Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 1587b5b

Browse files
krschauEricJohnson327
authored andcommitted
Revert "Pin default widgets on first run (#2118)" (#2179)
This reverts commit b97bb34.
1 parent 26a12eb commit 1587b5b

File tree

2 files changed

+7
-80
lines changed

2 files changed

+7
-80
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// Copyright (c) Microsoft Corporation and Contributors
22
// Licensed under the MIT license.
33

4-
namespace DevHome.Common.Helpers;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
59

10+
namespace DevHome.Common.Helpers;
611
public class WellKnownSettingsKeys
712
{
813
public const string IsNotFirstRun = "IsNotFirstRun";
9-
10-
public const string IsNotFirstDashboardRun = "IsNotFirstDashboardRun";
1114
}

tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
using System.Threading.Tasks;
99
using CommunityToolkit.Mvvm.Input;
1010
using DevHome.Common;
11-
using DevHome.Common.Contracts;
1211
using DevHome.Common.Extensions;
13-
using DevHome.Common.Helpers;
1412
using DevHome.Dashboard.Controls;
1513
using DevHome.Dashboard.Helpers;
1614
using DevHome.Dashboard.Services;
@@ -23,7 +21,6 @@
2321
using Microsoft.Windows.Widgets;
2422
using Microsoft.Windows.Widgets.Hosts;
2523
using Windows.System;
26-
using Log = DevHome.Dashboard.Helpers.Log;
2724

2825
namespace DevHome.Dashboard.Views;
2926

@@ -48,8 +45,6 @@ public static ObservableCollection<WidgetViewModel> PinnedWidgets
4845

4946
private static Microsoft.UI.Dispatching.DispatcherQueue _dispatcher;
5047

51-
private readonly ILocalSettingsService _localSettingsService;
52-
5348
private const string DraggedWidget = "DraggedWidget";
5449
private const string DraggedIndex = "DraggedIndex";
5550

@@ -63,7 +58,6 @@ public DashboardView()
6358
PinnedWidgets = new ObservableCollection<WidgetViewModel>();
6459

6560
_dispatcher = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
66-
_localSettingsService = Application.Current.GetService<ILocalSettingsService>();
6761

6862
ActualThemeChanged += OnActualThemeChanged;
6963

@@ -131,15 +125,7 @@ private async Task InitializeDashboard()
131125
// Cache the widget icons before we display the widgets, since we include the icons in the widgets.
132126
await ViewModel.WidgetIconService.CacheAllWidgetIconsAsync();
133127

134-
if (await _localSettingsService.ReadSettingAsync<bool>(WellKnownSettingsKeys.IsNotFirstDashboardRun))
135-
{
136-
await RestorePinnedWidgetsAsync();
137-
}
138-
else
139-
{
140-
await Application.Current.GetService<ILocalSettingsService>().SaveSettingAsync(WellKnownSettingsKeys.IsNotFirstDashboardRun, true);
141-
await PinDefaultWidgets();
142-
}
128+
await RestorePinnedWidgetsAsync();
143129
}
144130
else
145131
{
@@ -165,68 +151,6 @@ private async Task InitializeDashboard()
165151
ViewModel.IsLoading = false;
166152
}
167153

168-
private async Task PinDefaultWidgets()
169-
{
170-
string[] defaultWidgetDefinitionIds =
171-
{
172-
#if CANARY_BUILD
173-
"Microsoft.Windows.DevHome.Canary_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_CPUUsage",
174-
"Microsoft.Windows.DevHome.Canary_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_GPUUsage",
175-
"Microsoft.Windows.DevHome.Canary_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_NetworkUsage",
176-
#elif STABLE_BUILD
177-
"Microsoft.Windows.DevHome_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_CPUUsage",
178-
"Microsoft.Windows.DevHome_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_GPUUsage",
179-
"Microsoft.Windows.DevHome_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_NetworkUsage",
180-
#else
181-
"Microsoft.Windows.DevHome.Dev_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_CPUUsage",
182-
"Microsoft.Windows.DevHome.Dev_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_GPUUsage",
183-
"Microsoft.Windows.DevHome.Dev_8wekyb3d8bbwe!App!!CoreWidgetProvider!!System_NetworkUsage",
184-
#endif
185-
};
186-
187-
var catalog = await ViewModel.WidgetHostingService.GetWidgetCatalogAsync();
188-
189-
if (catalog is null)
190-
{
191-
Log.Logger()?.ReportError("AddWidgetDialog", $"Trying to pin default widgets, but WidgetCatalog is null.");
192-
return;
193-
}
194-
195-
var widgetDefinitions = await Task.Run(() => catalog!.GetWidgetDefinitions().OrderBy(x => x.DisplayTitle));
196-
foreach (var widgetDefinition in widgetDefinitions)
197-
{
198-
var id = widgetDefinition.Id;
199-
if (defaultWidgetDefinitionIds.Contains(id))
200-
{
201-
await PinDefaultWidget(widgetDefinition);
202-
}
203-
}
204-
}
205-
206-
private async Task PinDefaultWidget(WidgetDefinition defaultWidgetDefinition)
207-
{
208-
try
209-
{
210-
// Create widget
211-
var widgetHost = await ViewModel.WidgetHostingService.GetWidgetHostAsync();
212-
var size = WidgetHelpers.GetDefaultWidgetSize(defaultWidgetDefinition.GetWidgetCapabilities());
213-
var newWidget = await Task.Run(async () => await widgetHost?.CreateWidgetAsync(defaultWidgetDefinition.Id, size));
214-
215-
// Set custom state on new widget.
216-
var position = PinnedWidgets.Count;
217-
var newCustomState = WidgetHelpers.CreateWidgetCustomState(position);
218-
Log.Logger()?.ReportDebug("DashboardView", $"SetCustomState: {newCustomState}");
219-
await newWidget.SetCustomStateAsync(newCustomState);
220-
221-
// Put new widget on the Dashboard.
222-
await InsertWidgetInPinnedWidgetsAsync(newWidget, size, position);
223-
}
224-
catch (Exception ex)
225-
{
226-
Log.Logger()?.ReportError("AddWidgetDialog", $"PinDefaultWidget failed: ", ex);
227-
}
228-
}
229-
230154
private async Task RestorePinnedWidgetsAsync()
231155
{
232156
Log.Logger()?.ReportInfo("DashboardView", "Get widgets for current host");

0 commit comments

Comments
 (0)