Skip to content

Commit 0150b10

Browse files
committed
improvements on error handling logic
1 parent f9bb332 commit 0150b10

2 files changed

Lines changed: 149 additions & 122 deletions

File tree

src/WidgetProvider.cs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public WidgetProvider()
2525
{
2626
WingetUI = new WingetUIConnector();
2727
WingetUI.UpdateCheckFinished += WingetUI_UpdateCheckFinished;
28-
WingetUI.Connected += WingetUI_Connected;
2928

3029
var runningWidgets = WidgetManager.GetDefault().GetWidgetInfos();
3130

@@ -58,26 +57,7 @@ private void StartLoadingRoutine(GenericWidget widget)
5857
updateOptions.Data = "{ \"IsLoading\": true }";
5958
Console.WriteLine("Starting load routine...");
6059
updateOptions.Template = Templates.BaseTemplate;
61-
WingetUI.Connect(widget);
62-
WidgetManager.GetDefault().UpdateWidget(updateOptions);
63-
}
64-
65-
private void WingetUI_Connected(object? sender, ConnectionEventArgs e)
66-
{
67-
WidgetUpdateRequestOptions updateOptions = new WidgetUpdateRequestOptions(e.widget.Id);
68-
if (!e.Succeeded)
69-
{
70-
updateOptions.Data = Templates.GetData_NoWingetUI();
71-
Console.WriteLine("Could not connect to WingetUI");
72-
}
73-
else
74-
{
75-
updateOptions.Data = Templates.GetData_IsLoading();
76-
Console.WriteLine("Connected to WingetUI");
77-
WingetUI.GetAvailableUpdates(e.widget);
78-
}
79-
80-
updateOptions.Template = Templates.BaseTemplate;
60+
WingetUI.GetAvailableUpdates(widget);
8161
WidgetManager.GetDefault().UpdateWidget(updateOptions);
8262
}
8363

@@ -88,9 +68,16 @@ private void WingetUI_UpdateCheckFinished(object? sender, UpdatesCheckFinishedEv
8868
updateOptions.Template = Templates.BaseTemplate;
8969
if (!e.Succeeded)
9070
{
91-
updateOptions.Data = Templates.GetData_ErrorOccurred("UPDATE_CHECK_FAILED");
92-
Console.WriteLine("Could not check for updates");
93-
WidgetManager.GetDefault().UpdateWidget(updateOptions);
71+
if (e.ErrorReason == "NO_WINGETUI")
72+
{
73+
updateOptions.Data = Templates.GetData_NoWingetUI();
74+
}
75+
else
76+
{
77+
updateOptions.Data = Templates.GetData_ErrorOccurred(e.ErrorReason);
78+
WidgetManager.GetDefault().UpdateWidget(updateOptions);
79+
}
80+
9481
}
9582
else if (e.Count == 0)
9683
{

0 commit comments

Comments
 (0)