88using System . Threading . Tasks ;
99using CommunityToolkit . Mvvm . Input ;
1010using DevHome . Common ;
11- using DevHome . Common . Contracts ;
1211using DevHome . Common . Extensions ;
13- using DevHome . Common . Helpers ;
1412using DevHome . Dashboard . Controls ;
1513using DevHome . Dashboard . Helpers ;
1614using DevHome . Dashboard . Services ;
2321using Microsoft . Windows . Widgets ;
2422using Microsoft . Windows . Widgets . Hosts ;
2523using Windows . System ;
26- using Log = DevHome . Dashboard . Helpers . Log ;
2724
2825namespace 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