diff --git a/common/Helpers/WellKnownSettingsKeys.cs b/common/Helpers/WellKnownSettingsKeys.cs index 2777e70c3a..fdddd11d71 100644 --- a/common/Helpers/WellKnownSettingsKeys.cs +++ b/common/Helpers/WellKnownSettingsKeys.cs @@ -1,11 +1,14 @@ // Copyright (c) Microsoft Corporation and Contributors // Licensed under the MIT license. -namespace DevHome.Common.Helpers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace DevHome.Common.Helpers; public class WellKnownSettingsKeys { public const string IsNotFirstRun = "IsNotFirstRun"; - - public const string IsNotFirstDashboardRun = "IsNotFirstDashboardRun"; } diff --git a/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs b/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs index bb8b04617e..d669137165 100644 --- a/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs +++ b/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs @@ -8,9 +8,7 @@ using System.Threading.Tasks; using CommunityToolkit.Mvvm.Input; using DevHome.Common; -using DevHome.Common.Contracts; using DevHome.Common.Extensions; -using DevHome.Common.Helpers; using DevHome.Dashboard.Controls; using DevHome.Dashboard.Helpers; using DevHome.Dashboard.Services; @@ -23,7 +21,6 @@ using Microsoft.Windows.Widgets; using Microsoft.Windows.Widgets.Hosts; using Windows.System; -using Log = DevHome.Dashboard.Helpers.Log; namespace DevHome.Dashboard.Views; @@ -48,8 +45,6 @@ public static ObservableCollection PinnedWidgets private static Microsoft.UI.Dispatching.DispatcherQueue _dispatcher; - private readonly ILocalSettingsService _localSettingsService; - private const string DraggedWidget = "DraggedWidget"; private const string DraggedIndex = "DraggedIndex"; @@ -63,7 +58,6 @@ public DashboardView() PinnedWidgets = new ObservableCollection(); _dispatcher = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread(); - _localSettingsService = Application.Current.GetService(); ActualThemeChanged += OnActualThemeChanged; @@ -131,15 +125,7 @@ private async Task InitializeDashboard() // Cache the widget icons before we display the widgets, since we include the icons in the widgets. await ViewModel.WidgetIconService.CacheAllWidgetIconsAsync(); - if (await _localSettingsService.ReadSettingAsync(WellKnownSettingsKeys.IsNotFirstDashboardRun)) - { - await RestorePinnedWidgetsAsync(); - } - else - { - await Application.Current.GetService().SaveSettingAsync(WellKnownSettingsKeys.IsNotFirstDashboardRun, true); - await PinDefaultWidgets(); - } + await RestorePinnedWidgetsAsync(); } else { @@ -165,68 +151,6 @@ private async Task InitializeDashboard() ViewModel.IsLoading = false; } - private async Task PinDefaultWidgets() - { - string[] defaultWidgetDefinitionIds = - { -#if CANARY_BUILD - "Microsoft.Windows.DevHome.Canary_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_CPUUsage", - "Microsoft.Windows.DevHome.Canary_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_GPUUsage", - "Microsoft.Windows.DevHome.Canary_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_NetworkUsage", -#elif STABLE_BUILD - "Microsoft.Windows.DevHome_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_CPUUsage", - "Microsoft.Windows.DevHome_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_GPUUsage", - "Microsoft.Windows.DevHome_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_NetworkUsage", -#else - "Microsoft.Windows.DevHome.Dev_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_CPUUsage", - "Microsoft.Windows.DevHome.Dev_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_GPUUsage", - "Microsoft.Windows.DevHome.Dev_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_NetworkUsage", -#endif - }; - - var catalog = await ViewModel.WidgetHostingService.GetWidgetCatalogAsync(); - - if (catalog is null) - { - Log.Logger()?.ReportError("AddWidgetDialog", $"Trying to pin default widgets, but WidgetCatalog is null."); - return; - } - - var widgetDefinitions = await Task.Run(() => catalog!.GetWidgetDefinitions().OrderBy(x => x.DisplayTitle)); - foreach (var widgetDefinition in widgetDefinitions) - { - var id = widgetDefinition.Id; - if (defaultWidgetDefinitionIds.Contains(id)) - { - await PinDefaultWidget(widgetDefinition); - } - } - } - - private async Task PinDefaultWidget(WidgetDefinition defaultWidgetDefinition) - { - try - { - // Create widget - var widgetHost = await ViewModel.WidgetHostingService.GetWidgetHostAsync(); - var size = WidgetHelpers.GetDefaultWidgetSize(defaultWidgetDefinition.GetWidgetCapabilities()); - var newWidget = await Task.Run(async () => await widgetHost?.CreateWidgetAsync(defaultWidgetDefinition.Id, size)); - - // Set custom state on new widget. - var position = PinnedWidgets.Count; - var newCustomState = WidgetHelpers.CreateWidgetCustomState(position); - Log.Logger()?.ReportDebug("DashboardView", $"SetCustomState: {newCustomState}"); - await newWidget.SetCustomStateAsync(newCustomState); - - // Put new widget on the Dashboard. - await InsertWidgetInPinnedWidgetsAsync(newWidget, size, position); - } - catch (Exception ex) - { - Log.Logger()?.ReportError("AddWidgetDialog", $"PinDefaultWidget failed: ", ex); - } - } - private async Task RestorePinnedWidgetsAsync() { Log.Logger()?.ReportInfo("DashboardView", "Get widgets for current host");