Skip to content

Commit

Permalink
Revert "Pin default widgets on first run (#2118)" (#2179)
Browse files Browse the repository at this point in the history
This reverts commit b97bb34.
  • Loading branch information
krschau authored and EricJohnson327 committed Jan 25, 2024
1 parent 26a12eb commit 1587b5b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 80 deletions.
9 changes: 6 additions & 3 deletions common/Helpers/WellKnownSettingsKeys.cs
Original file line number Diff line number Diff line change
@@ -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";
}
78 changes: 1 addition & 77 deletions tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

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

private static Microsoft.UI.Dispatching.DispatcherQueue _dispatcher;

private readonly ILocalSettingsService _localSettingsService;

private const string DraggedWidget = "DraggedWidget";
private const string DraggedIndex = "DraggedIndex";

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

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

ActualThemeChanged += OnActualThemeChanged;

Expand Down Expand Up @@ -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<bool>(WellKnownSettingsKeys.IsNotFirstDashboardRun))
{
await RestorePinnedWidgetsAsync();
}
else
{
await Application.Current.GetService<ILocalSettingsService>().SaveSettingAsync(WellKnownSettingsKeys.IsNotFirstDashboardRun, true);
await PinDefaultWidgets();
}
await RestorePinnedWidgetsAsync();
}
else
{
Expand All @@ -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");
Expand Down

0 comments on commit 1587b5b

Please sign in to comment.