Skip to content

Commit

Permalink
improvements on error handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
marticliment committed Nov 23, 2023
1 parent f9bb332 commit 0150b10
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 122 deletions.
35 changes: 11 additions & 24 deletions src/WidgetProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public WidgetProvider()
{
WingetUI = new WingetUIConnector();
WingetUI.UpdateCheckFinished += WingetUI_UpdateCheckFinished;
WingetUI.Connected += WingetUI_Connected;

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

Expand Down Expand Up @@ -58,26 +57,7 @@ private void StartLoadingRoutine(GenericWidget widget)
updateOptions.Data = "{ \"IsLoading\": true }";
Console.WriteLine("Starting load routine...");
updateOptions.Template = Templates.BaseTemplate;
WingetUI.Connect(widget);
WidgetManager.GetDefault().UpdateWidget(updateOptions);
}

private void WingetUI_Connected(object? sender, ConnectionEventArgs e)
{
WidgetUpdateRequestOptions updateOptions = new WidgetUpdateRequestOptions(e.widget.Id);
if (!e.Succeeded)
{
updateOptions.Data = Templates.GetData_NoWingetUI();
Console.WriteLine("Could not connect to WingetUI");
}
else
{
updateOptions.Data = Templates.GetData_IsLoading();
Console.WriteLine("Connected to WingetUI");
WingetUI.GetAvailableUpdates(e.widget);
}

updateOptions.Template = Templates.BaseTemplate;
WingetUI.GetAvailableUpdates(widget);
WidgetManager.GetDefault().UpdateWidget(updateOptions);
}

Expand All @@ -88,9 +68,16 @@ private void WingetUI_UpdateCheckFinished(object? sender, UpdatesCheckFinishedEv
updateOptions.Template = Templates.BaseTemplate;
if (!e.Succeeded)
{
updateOptions.Data = Templates.GetData_ErrorOccurred("UPDATE_CHECK_FAILED");
Console.WriteLine("Could not check for updates");
WidgetManager.GetDefault().UpdateWidget(updateOptions);
if (e.ErrorReason == "NO_WINGETUI")
{
updateOptions.Data = Templates.GetData_NoWingetUI();
}
else
{
updateOptions.Data = Templates.GetData_ErrorOccurred(e.ErrorReason);
WidgetManager.GetDefault().UpdateWidget(updateOptions);
}

}
else if (e.Count == 0)
{
Expand Down
Loading

0 comments on commit 0150b10

Please sign in to comment.