From bd0858ceb85879817db99f22982b19bdf47bd7c0 Mon Sep 17 00:00:00 2001 From: Kristen Schau <47155823+krschau@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:13:31 -0700 Subject: [PATCH] Fix Dashboard crash when widgets runtime isn't present (#3819) --- .../Helpers/WidgetHelpers.cs | 4 +-- .../Services/WidgetServiceService.cs | 34 +++++++++++-------- .../Views/DashboardView.xaml.cs | 2 +- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/tools/Dashboard/DevHome.Dashboard/Helpers/WidgetHelpers.cs b/tools/Dashboard/DevHome.Dashboard/Helpers/WidgetHelpers.cs index f8a1686da9..74155fb86c 100644 --- a/tools/Dashboard/DevHome.Dashboard/Helpers/WidgetHelpers.cs +++ b/tools/Dashboard/DevHome.Dashboard/Helpers/WidgetHelpers.cs @@ -19,8 +19,8 @@ internal sealed class WidgetHelpers { public const string WebExperiencePackPackageId = "9MSSGKG348SP"; public const string WebExperiencePackageFamilyName = "MicrosoftWindows.Client.WebExperience_cw5n1h2txyewy"; - public const string WidgetPlatformRuntimePackageId = "9N3RK8ZV2ZR8"; - public const string WidgetPlatformRuntimePackageFamilyName = "Microsoft.WidgetsPlatformRuntime_8wekyb3d8bbwe"; + public const string WidgetsPlatformRuntimePackageId = "9N3RK8ZV2ZR8"; + public const string WidgetsPlatformRuntimePackageFamilyName = "Microsoft.WidgetsPlatformRuntime_8wekyb3d8bbwe"; public static readonly string[] DefaultWidgetDefinitionIds = { diff --git a/tools/Dashboard/DevHome.Dashboard/Services/WidgetServiceService.cs b/tools/Dashboard/DevHome.Dashboard/Services/WidgetServiceService.cs index 2419399d47..3929477015 100644 --- a/tools/Dashboard/DevHome.Dashboard/Services/WidgetServiceService.cs +++ b/tools/Dashboard/DevHome.Dashboard/Services/WidgetServiceService.cs @@ -38,8 +38,12 @@ public WidgetServiceService(IPackageDeploymentService packageDeploymentService, public WidgetServiceStates GetWidgetServiceState() { - // First check for the WidgetPlatformRuntime package. If it's installed and has a valid state, we return that state. - var package = GetWidgetPlatformRuntimePackage(); + var isWindows11String = RuntimeHelper.IsOnWindows11 ? "Windows 11" : "Windows 10"; + _log.Information($"Checking for WidgetService on {isWindows11String}"); + + // First check for the WidgetsPlatformRuntime package. If it's installed and has a valid state, we return that state. + _log.Information("Checking for WidgetsPlatformRuntime..."); + var package = GetWidgetsPlatformRuntimePackage(); _widgetServiceState = ValidatePackage(package); if (_widgetServiceState == WidgetServiceStates.MeetsMinVersion || _widgetServiceState == WidgetServiceStates.Updating) @@ -47,7 +51,8 @@ public WidgetServiceStates GetWidgetServiceState() return _widgetServiceState; } - // If the WidgetPlatformRuntime package is not installed or not high enough version, check for the WebExperience package. + // If the WidgetsPlatformRuntime package is not installed or not high enough version, check for the WebExperience package. + _log.Information("Checking for WebExperiencePack..."); package = GetWebExperiencePackPackage(); _widgetServiceState = ValidatePackage(package); @@ -57,8 +62,8 @@ public WidgetServiceStates GetWidgetServiceState() public async Task TryInstallingWidgetService() { _log.Information("Try installing widget service..."); - var installedSuccessfully = await _msStoreService.TryInstallPackageAsync(WidgetHelpers.WidgetPlatformRuntimePackageId); - _widgetServiceState = ValidatePackage(GetWidgetPlatformRuntimePackage()); + var installedSuccessfully = await _msStoreService.TryInstallPackageAsync(WidgetHelpers.WidgetsPlatformRuntimePackageId); + _widgetServiceState = ValidatePackage(GetWidgetsPlatformRuntimePackage()); _log.Information($"InstalledSuccessfully == {installedSuccessfully}, {_widgetServiceState}"); return installedSuccessfully; } @@ -77,34 +82,35 @@ private Package GetWebExperiencePackPackage() return packages.First(); } - private Package GetWidgetPlatformRuntimePackage() + private Package GetWidgetsPlatformRuntimePackage() { var minSupportedVersion = new Version(1, 0, 0, 0); - var packages = _packageDeploymentService.FindPackagesForCurrentUser(WidgetHelpers.WidgetPlatformRuntimePackageFamilyName, (minSupportedVersion, null)); + var packages = _packageDeploymentService.FindPackagesForCurrentUser(WidgetHelpers.WidgetsPlatformRuntimePackageFamilyName, (minSupportedVersion, null)); return packages.First(); } private WidgetServiceStates ValidatePackage(Package package) { - var isWindows11String = RuntimeHelper.IsOnWindows11 ? "Windows 11" : "Windows 10"; - _log.Information($"Validating package {package.DisplayName} on {isWindows11String}"); - + WidgetServiceStates packageStatus; if (package == null) { - return WidgetServiceStates.NotAtMinVersion; + packageStatus = WidgetServiceStates.NotAtMinVersion; } else if (package.Status.VerifyIsOK()) { - return WidgetServiceStates.MeetsMinVersion; + packageStatus = WidgetServiceStates.MeetsMinVersion; } else if (package.Status.Servicing == true) { - return WidgetServiceStates.Updating; + packageStatus = WidgetServiceStates.Updating; } else { - return WidgetServiceStates.NotOK; + packageStatus = WidgetServiceStates.NotOK; } + + _log.Information($"ValidatePackage found {packageStatus}"); + return packageStatus; } } diff --git a/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs b/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs index 8ee62bea6b..f30eeb6c4a 100644 --- a/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs +++ b/tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs @@ -560,7 +560,7 @@ public async Task GoToWidgetsInStoreAsync() } else { - await Windows.System.Launcher.LaunchUriAsync(new($"ms-windows-store://pdp/?productid={WidgetHelpers.WidgetPlatformRuntimePackageId}")); + await Windows.System.Launcher.LaunchUriAsync(new($"ms-windows-store://pdp/?productid={WidgetHelpers.WidgetsPlatformRuntimePackageId}")); } }