diff --git a/tools/Dashboard/DevHome.Dashboard/Services/IWidgetHostingService.cs b/tools/Dashboard/DevHome.Dashboard/Services/IWidgetHostingService.cs index 4abcd16923..db2cd091b3 100644 --- a/tools/Dashboard/DevHome.Dashboard/Services/IWidgetHostingService.cs +++ b/tools/Dashboard/DevHome.Dashboard/Services/IWidgetHostingService.cs @@ -9,17 +9,34 @@ namespace DevHome.Dashboard.Services; public interface IWidgetHostingService { + /// Get the list of current widgets from the WidgetService. + /// A list of widgets, or empty list if there were no widgets or the list could not be retrieved. public Task GetWidgetsAsync(); + /// Gets the widget with the given ID. + /// The widget, or null if one could not be retrieved. public Task GetWidgetAsync(string widgetId); + /// Create and return a new widget. + /// The new widget, or null if one could not be created. public Task CreateWidgetAsync(string widgetDefinitionId, WidgetSize widgetSize); + /// Get the catalog of widgets from the WidgetService. + /// The catalog of widgets, or null if one could not be created. public Task GetWidgetCatalogAsync(); + /// Get the list of WidgetProviderDefinitions from the WidgetService. + /// A list of WidgetProviderDefinitions, or an empty list if there were no widgets + /// or the list could not be retrieved. public Task GetProviderDefinitionsAsync(); + /// Get the list of WidgetDefinitions from the WidgetService. + /// A list of WidgetDefinitions, or an empty list if there were no widgets + /// or the list could not be retrieved. public Task GetWidgetDefinitionsAsync(); + /// Get the WidgetDefinition for the given WidgetDefinitionId from the WidgetService. + /// The WidgetDefinition, or null if the widget definition could not be found + /// or there was an error retrieving it. public Task GetWidgetDefinitionAsync(string widgetDefinitionId); } diff --git a/tools/Dashboard/DevHome.Dashboard/Services/WidgetHostingService.cs b/tools/Dashboard/DevHome.Dashboard/Services/WidgetHostingService.cs index b8dfef6826..16de637050 100644 --- a/tools/Dashboard/DevHome.Dashboard/Services/WidgetHostingService.cs +++ b/tools/Dashboard/DevHome.Dashboard/Services/WidgetHostingService.cs @@ -23,10 +23,7 @@ public class WidgetHostingService : IWidgetHostingService private const int MaxAttempts = 3; - /// - /// Get the list of current widgets from the WidgetService. - /// - /// A list of widgets, or null if there were no widgets or the list could not be retrieved. + /// public async Task GetWidgetsAsync() { var attempt = 0; @@ -35,7 +32,7 @@ public async Task GetWidgetsAsync() try { _widgetHost ??= await Task.Run(() => WidgetHost.Register(new WidgetHostContext("BAA93438-9B07-4554-AD09-7ACCD7D4F031"))); - return await Task.Run(() => _widgetHost.GetWidgets()); + return await Task.Run(() => _widgetHost.GetWidgets()) ?? []; } catch (COMException ex) when (ex.HResult == RpcServerUnavailable || ex.HResult == RpcCallFailed) { @@ -52,11 +49,10 @@ public async Task GetWidgetsAsync() } } - return null; + return []; } - /// Gets the widget with the given ID. - /// The widget, or null if one could not be retrieved. + /// public async Task GetWidgetAsync(string widgetId) { var attempt = 0; @@ -83,10 +79,7 @@ public async Task GetWidgetAsync(string widgetId) return null; } - /// - /// Create and return a new widget. - /// - /// The new widget, or null if one could not be created. + /// public async Task CreateWidgetAsync(string widgetDefinitionId, WidgetSize widgetSize) { var attempt = 0; @@ -113,10 +106,7 @@ public async Task CreateWidgetAsync(string widgetDefinitionId, WidgetSiz return null; } - /// - /// Get the catalog of widgets from the WidgetService. - /// - /// The catalog of widgets, or null if one could not be created. + /// public async Task GetWidgetCatalogAsync() { var attempt = 0; @@ -149,11 +139,7 @@ public async Task GetWidgetCatalogAsync() return _widgetCatalog; } - /// - /// Get the list of WidgetProviderDefinitions from the WidgetService. - /// - /// A list of WidgetProviderDefinitions, or an empty list if there were no widgets - /// or the list could not be retrieved. + /// public async Task GetProviderDefinitionsAsync() { var attempt = 0; @@ -182,11 +168,7 @@ public async Task GetProviderDefinitionsAsync() return []; } - /// - /// Get the list of WidgetDefinitions from the WidgetService. - /// - /// A list of WidgetDefinitions, or an empty list if there were no widgets - /// or the list could not be retrieved. + /// public async Task GetWidgetDefinitionsAsync() { var attempt = 0; @@ -215,11 +197,7 @@ public async Task GetWidgetDefinitionsAsync() return []; } - /// - /// Get the WidgetDefinition for the given WidgetDefinitionId from the WidgetService. - /// - /// The WidgetDefinition, or null if the widget definition could not be found - /// or there was an error retrieving it. + /// public async Task GetWidgetDefinitionAsync(string widgetDefinitionId) { var attempt = 0; diff --git a/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs b/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs index 817b63fed7..b5cd2f647a 100644 --- a/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs +++ b/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs @@ -217,15 +217,14 @@ private async Task InitializeDashboard() private async Task InitializePinnedWidgetListAsync(bool isFirstDashboardRun) { var hostWidgets = await GetPreviouslyPinnedWidgets(); - - if ((hostWidgets == null || hostWidgets.Length == 0) && isFirstDashboardRun) + if ((hostWidgets.Length == 0) && isFirstDashboardRun) { // If it's the first time the Dashboard has been displayed and we have no other widgets pinned to a // different version of Dev Home, pin some default widgets. _log.Information($"Pin default widgets"); await PinDefaultWidgetsAsync(); } - else if (hostWidgets != null) + else { await RestorePinnedWidgetsAsync(hostWidgets); } @@ -235,11 +234,10 @@ private async Task GetPreviouslyPinnedWidgets() { _log.Information("Get widgets for current host"); var unsafeHostWidgets = await ViewModel.WidgetHostingService.GetWidgetsAsync(); - - if (unsafeHostWidgets == null) + if (unsafeHostWidgets.Length == 0) { _log.Information($"Found 0 widgets for this host"); - return null; + return []; } var comSafeHostWidgets = new List(); @@ -380,7 +378,7 @@ private async Task DeleteAbandonedWidgetAsync(ComSafeWidget widget) await widget.DeleteAsync(); var newWidgetList = await ViewModel.WidgetHostingService.GetWidgetsAsync(); - length = (newWidgetList == null) ? 0 : newWidgetList.Length; + length = newWidgetList.Length; _log.Information($"After delete, {length} widgets for this host"); }