Skip to content

Commit

Permalink
Fix Dashboard crash when widgets runtime isn't present (#3819)
Browse files Browse the repository at this point in the history
  • Loading branch information
krschau committed Sep 10, 2024
1 parent 2cab842 commit bd0858c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions tools/Dashboard/DevHome.Dashboard/Helpers/WidgetHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
{
Expand Down
34 changes: 20 additions & 14 deletions tools/Dashboard/DevHome.Dashboard/Services/WidgetServiceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ 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)
{
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);

Expand All @@ -57,8 +62,8 @@ public WidgetServiceStates GetWidgetServiceState()
public async Task<bool> 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;
}
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}"));
}
}

Expand Down

0 comments on commit bd0858c

Please sign in to comment.