From fa3e3305b55171c023394b6b5ec987c626927672 Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Wed, 9 Oct 2024 15:13:23 -0700 Subject: [PATCH 01/13] Remove RestoreState.cs --- .../Models/RestoreState.cs | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 tools/DevDiagnostics/DevHome.DevDiagnostics/Models/RestoreState.cs diff --git a/tools/DevDiagnostics/DevHome.DevDiagnostics/Models/RestoreState.cs b/tools/DevDiagnostics/DevHome.DevDiagnostics/Models/RestoreState.cs deleted file mode 100644 index 1e1206a6eb..0000000000 --- a/tools/DevDiagnostics/DevHome.DevDiagnostics/Models/RestoreState.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using Microsoft.UI.Xaml.Controls; - -namespace DevHome.DevDiagnostics.Models; - -internal sealed class RestoreState -{ - internal double Left { get; set; } - - internal double Top { get; set; } - - internal double Width { get; set; } - - internal double Height { get; set; } - - internal Orientation BarOrientation { get; set; } - - internal bool IsLargePanelVisible { get; set; } -} From 20af2d7106baf79b3a2cf3186a44eabe003f998f Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Wed, 9 Oct 2024 15:21:01 -0700 Subject: [PATCH 02/13] Remove WinGetPackageRestoreDataSource and WinGetPackageRestoreDataSourceTest --- .../BaseSetupFlowTest.cs | 2 - .../WinGetPackageRestoreDataSourceTest.cs | 231 ------------------ .../Extensions/ServiceExtensions.cs | 2 - .../WinGetPackageRestoreDataSource.cs | 175 ------------- 4 files changed, 410 deletions(-) delete mode 100644 tools/SetupFlow/DevHome.SetupFlow.UnitTest/ViewModels/WinGetPackageRestoreDataSourceTest.cs delete mode 100644 tools/SetupFlow/DevHome.SetupFlow/Services/WinGetPackageRestoreDataSource.cs diff --git a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs index b88b11e919..5cb2ff204b 100644 --- a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs +++ b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs @@ -76,11 +76,9 @@ private IHost CreateTestHost() // App-management services services.AddSingleton(WindowsPackageManager.Object); services.AddTransient(); - services.AddTransient(); services.AddSingleton(RestoreInfo.Object); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(new Mock().Object); services.AddSingleton(new Mock().Object); diff --git a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/ViewModels/WinGetPackageRestoreDataSourceTest.cs b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/ViewModels/WinGetPackageRestoreDataSourceTest.cs deleted file mode 100644 index d690627ba0..0000000000 --- a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/ViewModels/WinGetPackageRestoreDataSourceTest.cs +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using DevHome.Common.Extensions; -using DevHome.Services.WindowsPackageManager.Contracts; -using DevHome.Services.WindowsPackageManager.Exceptions; -using DevHome.Services.WindowsPackageManager.Models; -using DevHome.SetupFlow.Services; -using DevHome.SetupFlow.UnitTest.Helpers; -using Microsoft.Internal.Windows.DevHome.Helpers.Restore; -using Microsoft.Management.Deployment; -using Moq; -using Windows.Storage.Streams; - -namespace DevHome.SetupFlow.UnitTest.ViewModels; - -[TestClass] -public class WinGetPackageRestoreDataSourceTest : BaseSetupFlowTest -{ - // Icon stream size - private const ulong EmptyIconStreamSize = 0; - private const ulong NonEmptyIconStreamSize = 1; - - [TestMethod] - public void LoadCatalogs_EmptyPackages_ReturnsNoCatalogs() - { - // Arrange - var expectedPackages = new List(); - var restoreApplicationInfoList = expectedPackages.Select(p => CreateRestoreApplicationInfo(p.Id).Object).ToList(); - WindowsPackageManager.Setup(wpm => wpm.GetPackagesAsync(It.IsAny>())).ReturnsAsync(expectedPackages); - ConfigureRestoreDeviceInfo(RestoreDeviceInfoStatus.Ok, restoreApplicationInfoList); - - // Act - var loadedPackages = LoadCatalogsFromRestoreDataSource(); - - // Assert - Assert.AreEqual(0, loadedPackages.Count); - WindowsPackageManager.Verify(wpm => wpm.GetPackagesAsync(It.IsAny>()), Times.Never()); - } - - [TestMethod] - public void LoadCatalogs_ExceptionThrownWhenGettingPackages_ReturnsNoCatalogs() - { - // Arrange - WindowsPackageManager!.Setup(wpm => wpm.GetPackagesAsync(It.IsAny>())).ThrowsAsync(new FindPackagesException(FindPackagesResultStatus.CatalogError)); - ConfigureRestoreDeviceInfo(RestoreDeviceInfoStatus.Ok, new List()); - - // Act - var loadedPackages = LoadCatalogsFromRestoreDataSource(); - - // Assert - Assert.AreEqual(0, loadedPackages.Count); - } - - [TestMethod] - [DataRow(RestoreDeviceInfoStatus.NotAvailable)] - [DataRow(RestoreDeviceInfoStatus.Error)] - public void LoadCatalogs_NonSuccessStatus_ReturnsNoCatalogs(RestoreDeviceInfoStatus status) - { - // Arrange - ConfigureRestoreDeviceInfo(status, new List()); - - // Act - var loadedPackages = LoadCatalogsFromRestoreDataSource(); - - // Assert - Assert.AreEqual(0, loadedPackages.Count); - } - - [TestMethod] - [DataRow("mock1", "mock2")] - [DataRow("mock2", "mock1")] - public void LoadCatalogs_OrderedPackages_ReturnsWinGetCatalogWithMatchingInputOrder(string packageId1, string packageId2) - { - // Arrange - var expectedPackages = new List - { - PackageHelper.CreatePackage(packageId1).Object, - PackageHelper.CreatePackage(packageId2).Object, - }; - var restoreApplicationInfoList = expectedPackages.Select(p => CreateRestoreApplicationInfo(p.Id).Object).ToList(); - WindowsPackageManager.Setup(wpm => wpm.GetPackagesAsync(It.IsAny>())).ReturnsAsync(expectedPackages); - ConfigureRestoreDeviceInfo(RestoreDeviceInfoStatus.Ok, restoreApplicationInfoList); - - // Act - var loadedPackages = LoadCatalogsFromRestoreDataSource(); - - // Assert - Assert.AreEqual(1, loadedPackages.Count); - Assert.AreEqual(expectedPackages.Count, loadedPackages[0].Packages.Count); - Assert.AreEqual(expectedPackages[0].Id, loadedPackages[0].Packages.ElementAt(0).Id); - Assert.IsNotNull(expectedPackages[0].LightThemeIcon); - Assert.IsNotNull(expectedPackages[0].DarkThemeIcon); - Assert.AreEqual(expectedPackages[1].Id, loadedPackages[0].Packages.ElementAt(1).Id); - Assert.IsNotNull(expectedPackages[1].LightThemeIcon); - Assert.IsNotNull(expectedPackages[1].DarkThemeIcon); - } - - [TestMethod] - public void LoadCatalogs_Success_ReturnsWinGetCatalogs() - { - // Arrange - var expectedPackages = new List - { - PackageHelper.CreatePackage("mock1").Object, - PackageHelper.CreatePackage("mock2").Object, - }; - var restoreApplicationInfoList = expectedPackages.Select(p => CreateRestoreApplicationInfo(p.Id).Object).ToList(); - WindowsPackageManager.Setup(wpm => wpm.GetPackagesAsync(It.IsAny>())).ReturnsAsync(expectedPackages); - ConfigureRestoreDeviceInfo(RestoreDeviceInfoStatus.Ok, restoreApplicationInfoList); - - // Act - var loadedPackages = LoadCatalogsFromRestoreDataSource(); - - // Assert - Assert.AreEqual(1, loadedPackages.Count); - Assert.AreEqual(expectedPackages.Count, loadedPackages[0].Packages.Count); - Assert.AreEqual(expectedPackages[0].Id, loadedPackages[0].Packages.ElementAt(0).Id); - Assert.IsNotNull(expectedPackages[0].LightThemeIcon); - Assert.IsNotNull(expectedPackages[0].DarkThemeIcon); - Assert.AreEqual(expectedPackages[1].Id, loadedPackages[0].Packages.ElementAt(1).Id); - Assert.IsNotNull(expectedPackages[1].LightThemeIcon); - Assert.IsNotNull(expectedPackages[1].DarkThemeIcon); - } - - [TestMethod] - public void LoadCatalogs_ExceptionThrownWhenGettingRestoreApplicationIcon_ReturnsNullForIcon() - { - var expectedPackages = new List - { - PackageHelper.CreatePackage("mock").Object, - }; - var restoreApplicationInfoList = expectedPackages.Select(p => - { - var restoreAppInfo = CreateRestoreApplicationInfo(p.Id); - - // Mock restore application icon not found by throwing an exception - restoreAppInfo - .Setup(appInfo => appInfo.GetIconAsync(It.IsAny())) - .Throws(new ArgumentOutOfRangeException()); - - return restoreAppInfo.Object; - }).ToList(); - WindowsPackageManager.Setup(wpm => wpm.GetPackagesAsync(It.IsAny>())).ReturnsAsync(expectedPackages); - ConfigureRestoreDeviceInfo(RestoreDeviceInfoStatus.Ok, restoreApplicationInfoList); - - // Act - var loadedPackages = LoadCatalogsFromRestoreDataSource(); - - // Assert - Assert.AreEqual(1, loadedPackages.Count); - Assert.AreEqual(expectedPackages.Count, loadedPackages[0].Packages.Count); - Assert.AreEqual(expectedPackages[0].Id, loadedPackages[0].Packages.ElementAt(0).Id); - Assert.IsNull(expectedPackages[0].LightThemeIcon); - Assert.IsNull(expectedPackages[0].DarkThemeIcon); - } - - [TestMethod] - public void LoadCatalogs_GettingRestoreApplicationIconWithEmptyStream_ReturnsNullForIcon() - { - var expectedPackages = new List - { - PackageHelper.CreatePackage("mock").Object, - }; - var restoreApplicationInfoList = expectedPackages.Select(p => CreateRestoreApplicationInfo(p.Id, EmptyIconStreamSize).Object).ToList(); - WindowsPackageManager.Setup(wpm => wpm.GetPackagesAsync(It.IsAny>())).ReturnsAsync(expectedPackages); - WindowsPackageManager.Setup(wpm => wpm.CreateWinGetCatalogPackageUri(It.IsAny())).Returns(new WinGetPackageUri("x-ms-winget://mock/mock")); - ConfigureRestoreDeviceInfo(RestoreDeviceInfoStatus.Ok, restoreApplicationInfoList); - - // Act - var loadedPackages = LoadCatalogsFromRestoreDataSource(); - - // Assert - Assert.AreEqual(1, loadedPackages.Count); - Assert.AreEqual(expectedPackages.Count, loadedPackages[0].Packages.Count); - Assert.AreEqual(expectedPackages[0].Id, loadedPackages[0].Packages.ElementAt(0).Id); - Assert.IsNull(expectedPackages[0].LightThemeIcon); - Assert.IsNull(expectedPackages[0].DarkThemeIcon); - } - - /// - /// Load catalogs from restore data source - /// - /// List of package catalogs - private IList LoadCatalogsFromRestoreDataSource() - { - var restoreDataSource = TestHost!.GetService(); - restoreDataSource.InitializeAsync().GetAwaiter().GetResult(); - return restoreDataSource.LoadCatalogsAsync().GetAwaiter().GetResult(); - } - - /// - /// Configure a restore device info including WinGet packages to restore - /// - /// Result status - /// Mock a list of application info to restore - private void ConfigureRestoreDeviceInfo(RestoreDeviceInfoStatus status, IList restoreApplicationInfoList) - { - // Mock restore device info - var deviceInfo = new Mock(); - deviceInfo.Setup(di => di.WinGetApplicationsInfo).Returns(restoreApplicationInfoList); - - // Mock restore device info result - var restoreDeviceInfoResult = new Mock(); - restoreDeviceInfoResult.Setup(result => result.Status).Returns(status); - restoreDeviceInfoResult.Setup(result => result.RestoreDeviceInfo).Returns(deviceInfo.Object); - RestoreInfo.Setup(restore => restore.GetRestoreDeviceInfoAsync()).Returns(Task.FromResult(restoreDeviceInfoResult.Object).AsAsyncOperation()); - } - - /// - /// Create an application info to restore - /// - /// Id of the package corresponding to the application to restore - /// Restore application info - private Mock CreateRestoreApplicationInfo(string packageId, ulong iconStreamSize = NonEmptyIconStreamSize) - { - var appInfo = new Mock(); - - // Mock id - appInfo.Setup(app => app.Id).Returns(packageId); - - // Mock icon - var mockIconStream = new Mock(); - mockIconStream.SetupGet(stream => stream.Size).Returns(iconStreamSize); - appInfo - .Setup(app => app.GetIconAsync(It.IsAny())) - .Returns(Task.FromResult(mockIconStream.Object).AsAsyncOperation()); - - return appInfo; - } -} diff --git a/tools/SetupFlow/DevHome.SetupFlow/Extensions/ServiceExtensions.cs b/tools/SetupFlow/DevHome.SetupFlow/Extensions/ServiceExtensions.cs index 85caef575b..a9dfc51460 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Extensions/ServiceExtensions.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/Extensions/ServiceExtensions.cs @@ -58,13 +58,11 @@ private static IServiceCollection AddAppManagement(this IServiceCollection servi services.AddTransient(); // Services - services.AddSingleton(); services.AddSingleton(); services.AddTransient(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(sp => { var dataSourcePath = sp.GetService>().Value.WinGetPackageJsonDataSourcePath; diff --git a/tools/SetupFlow/DevHome.SetupFlow/Services/WinGetPackageRestoreDataSource.cs b/tools/SetupFlow/DevHome.SetupFlow/Services/WinGetPackageRestoreDataSource.cs deleted file mode 100644 index 530e9bfe3d..0000000000 --- a/tools/SetupFlow/DevHome.SetupFlow/Services/WinGetPackageRestoreDataSource.cs +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading.Tasks; -using DevHome.Common.Extensions; -using DevHome.Services.WindowsPackageManager.Contracts; -using DevHome.Services.WindowsPackageManager.Models; -using DevHome.SetupFlow.Models; -using DevHome.Telemetry; -using Microsoft.Diagnostics.Telemetry.Internal; -using Microsoft.Internal.Windows.DevHome.Helpers.Restore; -using Serilog; -using Windows.Storage.Streams; - -namespace DevHome.SetupFlow.Services; - -public class WinGetPackageRestoreDataSource : WinGetPackageDataSource -{ - private readonly ILogger _log = Log.ForContext("SourceContext", nameof(WinGetPackageRestoreDataSource)); - private readonly IRestoreInfo _restoreInfo; - private readonly ISetupFlowStringResource _stringResource; - private IRestoreDeviceInfo _restoreDeviceInfo; - - public WinGetPackageRestoreDataSource( - ISetupFlowStringResource stringResource, - IWinGet winget, - IRestoreInfo restoreInfo) - : base(winget) - { - _stringResource = stringResource; - _restoreInfo = restoreInfo; - } - - /// - /// Gets the total number of package catalogs available in this data source - /// - /// - /// Each collection of packages from a restore device is compiled into a - /// catalog. At most show one catalog. - /// - public override int CatalogCount => _restoreDeviceInfo == null ? 0 : 1; - - /// - /// Gets the restore device information - /// - public async override Task InitializeAsync() - { - var restoreDeviceInfoResult = await _restoreInfo.GetRestoreDeviceInfoAsync(); - if (restoreDeviceInfoResult.Status == RestoreDeviceInfoStatus.Ok) - { - _restoreDeviceInfo = restoreDeviceInfoResult.RestoreDeviceInfo; - TelemetryFactory.Get().Log("AppInstall_RestoreApps_Found", LogLevel.Critical, new EmptyEvent(PartA_PrivTags.ProductAndServicePerformance)); - } - else - { - _log.Warning($"Restore data source skipped with status: {restoreDeviceInfoResult.Status}"); - } - } - - public async override Task> LoadCatalogsAsync() - { - var result = new List(); - if (_restoreDeviceInfo == null) - { - _log.Warning($"Load catalogs skipped because no restore device information was found"); - return result; - } - - try - { - _log.Information("Finding packages from restore data"); - var packages = await GetPackagesAsync(_restoreDeviceInfo.WinGetApplicationsInfo.Select(p => GetPackageUri(p)).ToList()); - foreach (var package in packages) - { - var packageUri = WinGet.CreatePackageUri(package); - _log.Information($"Obtaining icon information for restore package {package.Id}"); - var appInfo = _restoreDeviceInfo.WinGetApplicationsInfo.FirstOrDefault(p => packageUri == GetPackageUri(p)); - if (appInfo != null) - { - package.LightThemeIcon = await GetRestoreApplicationIconAsync(appInfo, RestoreApplicationIconTheme.Light); - package.DarkThemeIcon = await GetRestoreApplicationIconAsync(appInfo, RestoreApplicationIconTheme.Dark); - } - } - - if (packages.Any()) - { - result.Add(new PackageCatalog() - { - Name = _stringResource.GetLocalized(StringResourceKey.RestorePackagesTitle, _restoreDeviceInfo.DisplayName), - Description = GetDescription(), - Packages = packages.ToReadOnlyCollection(), - }); - } - else - { - _log.Information("No packages found from restore"); - } - } - catch (Exception e) - { - _log.Error(e, $"Error loading packages from winget restore catalog."); - } - - if (result.Count > 0) - { - TelemetryFactory.Get().Log("AppInstall_RestoreApps_Loaded", LogLevel.Critical, new EmptyEvent(PartA_PrivTags.ProductAndServicePerformance)); - } - - return result; - } - - /// - /// Get the icon for a restore application based on the provided theme - /// - /// Restore application - /// Target theme - /// Restore application icon stream, or null if no corresponding icon was found - private async Task GetRestoreApplicationIconAsync(IRestoreApplicationInfo appInfo, RestoreApplicationIconTheme theme) - { - try - { - // Load icon from restore app data - var iconTask = appInfo.GetIconAsync(theme); - - // Check if no icon is available - if (iconTask != null) - { - var icon = await iconTask; - - // Ensure stream is not empty to prevent rendering an empty image - if (icon.Size > 0) - { - return icon; - } - } - } - catch (Exception e) - { - _log.Error(e, $"Failed to get icon for restore package {appInfo.Id}"); - } - - _log.Warning($"No {theme} icon found for restore package {appInfo.Id}. A default one will be provided."); - return null; - } - - /// - /// Gets the restore catalog description - /// - /// Localized restore catalog description - private string GetDescription() - { - // Check if last modified time is not available - if (_restoreDeviceInfo.LastModifiedTime == DateTime.MinValue) - { - return _stringResource.GetLocalized(StringResourceKey.RestorePackagesDescription, _restoreDeviceInfo.DisplayName); - } - - return _stringResource.GetLocalized(StringResourceKey.RestorePackagesDescriptionWithDate, _restoreDeviceInfo.DisplayName, _restoreDeviceInfo.LastModifiedTime.ToString("d", CultureInfo.CurrentCulture)); - } - - /// - /// Gets the package URI for a restore application - /// - /// Application information - /// Package URI - /// All restored applications are from winget catalog - private WinGetPackageUri GetPackageUri(IRestoreApplicationInfo appInfo) - { - return WinGet.CreateWinGetCatalogPackageUri(appInfo.Id); - } -} From 2e6f32693e542dd59845f8e1834ee17775afd718 Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Wed, 9 Oct 2024 15:23:22 -0700 Subject: [PATCH 03/13] Remove using from BaseSetupFlowTest.cs --- .../DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs index 5cb2ff204b..5c68dfd5ac 100644 --- a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs +++ b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs @@ -11,7 +11,6 @@ using DevHome.SetupFlow.ViewModels; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Internal.Windows.DevHome.Helpers.Restore; using Moq; namespace DevHome.SetupFlow.UnitTest; @@ -26,8 +25,6 @@ public class BaseSetupFlowTest protected Mock ThemeSelectorService { get; private set; } - protected Mock RestoreInfo { get; private set; } - protected Mock StringResource { get; private set; } protected Mock LocalSettingsService { get; private set; } @@ -40,7 +37,6 @@ public void TestInitialize() { WindowsPackageManager = new Mock(); ThemeSelectorService = new Mock(); - RestoreInfo = new Mock(); StringResource = new Mock(); LocalSettingsService = new Mock(); TestHost = CreateTestHost(); @@ -76,7 +72,6 @@ private IHost CreateTestHost() // App-management services services.AddSingleton(WindowsPackageManager.Object); services.AddTransient(); - services.AddSingleton(RestoreInfo.Object); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); From 1e2ff886b0df34432f5ebcc7192e9fe9a5f4ccbf Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Wed, 9 Oct 2024 15:45:03 -0700 Subject: [PATCH 04/13] Remove using from ServiceExtension --- .../SetupFlow/DevHome.SetupFlow/Extensions/ServiceExtensions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/Extensions/ServiceExtensions.cs b/tools/SetupFlow/DevHome.SetupFlow/Extensions/ServiceExtensions.cs index a9dfc51460..cbfbce2781 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Extensions/ServiceExtensions.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/Extensions/ServiceExtensions.cs @@ -12,7 +12,6 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Microsoft.Internal.Windows.DevHome.Helpers; -using Microsoft.Internal.Windows.DevHome.Helpers.Restore; namespace DevHome.SetupFlow.Extensions; From a84277e3f7f7a143daf18f0d78f94d124864814a Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Wed, 9 Oct 2024 16:06:55 -0700 Subject: [PATCH 05/13] Remove using from PackageViewModel : --- .../ViewModels/PackageViewModel.cs | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs index 89af8dfb97..1b41a3a2b4 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs @@ -11,7 +11,6 @@ using DevHome.Services.WindowsPackageManager.Contracts; using DevHome.SetupFlow.Models; using DevHome.SetupFlow.Services; -using Microsoft.Internal.Windows.DevHome.Helpers.Restore; using Microsoft.UI.Xaml.Media.Imaging; using Windows.Storage.Streams; using Windows.System; @@ -86,8 +85,8 @@ public PackageViewModel( _orchestrator = orchestrator; // Lazy-initialize optional or expensive view model members - _packageDarkThemeIcon = new Lazy(() => GetIconByTheme(RestoreApplicationIconTheme.Dark)); - _packageLightThemeIcon = new Lazy(() => GetIconByTheme(RestoreApplicationIconTheme.Light)); + _packageDarkThemeIcon = new Lazy(() => IconByTheme); + _packageLightThemeIcon = new Lazy(() => IconByTheme); SelectedVersion = GetDefaultSelectedVersion(); InstallPackageTask = CreateInstallTask(); @@ -203,22 +202,19 @@ private void ToggleSelection() _screenReaderService.Announce(announcementText); } - /// - /// Gets the package icon based on the provided theme - /// - /// Package icon theme - /// Package icon - private BitmapImage GetIconByTheme(RestoreApplicationIconTheme theme) + public BitmapImage IconByTheme { - return theme switch + get { - // Get default dark theme icon if corresponding package icon was not found - RestoreApplicationIconTheme.Dark => - _package.DarkThemeIcon == null ? DefaultDarkPackageIconSource : CreateBitmapImage(_package.DarkThemeIcon), - - // Get default light theme icon if corresponding package icon was not found - _ => _package.LightThemeIcon == null ? DefaultLightPackageIconSource : CreateBitmapImage(_package.LightThemeIcon), - }; + if (_themeSelector.IsDarkTheme()) + { + return CreateBitmapImage(_package.DarkThemeIcon); + } + else + { + return CreateBitmapImage(_package.LightThemeIcon); + } + } } private BitmapImage CreateBitmapImage(IRandomAccessStream stream) From bbd33f35ed7353145ffe3034e467bd14b3d856c3 Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Wed, 9 Oct 2024 16:17:24 -0700 Subject: [PATCH 06/13] Remove strings --- .../Services/StringResourceKey.cs | 3 --- .../Strings/en-us/Resources.resw | 16 ---------------- 2 files changed, 19 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/Services/StringResourceKey.cs b/tools/SetupFlow/DevHome.SetupFlow/Services/StringResourceKey.cs index 3f546d665e..7a015f1a6f 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Services/StringResourceKey.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/Services/StringResourceKey.cs @@ -80,9 +80,6 @@ public static class StringResourceKey public static readonly string RemovedAllApplications = nameof(RemovedAllApplications); public static readonly string ResultCountPlural = nameof(ResultCountPlural); public static readonly string ResultCountSingular = nameof(ResultCountSingular); - public static readonly string RestorePackagesTitle = nameof(RestorePackagesTitle); - public static readonly string RestorePackagesDescription = nameof(RestorePackagesDescription); - public static readonly string RestorePackagesDescriptionWithDate = nameof(RestorePackagesDescriptionWithDate); public static readonly string Repository = nameof(Repository); public static readonly string ReviewNothingToSetUpToolTip = nameof(ReviewNothingToSetUpToolTip); public static readonly string SelectedPackagesCount = nameof(SelectedPackagesCount); diff --git a/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw b/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw index c841bfdcff..c915664c7e 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw +++ b/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw @@ -601,18 +601,6 @@ {0} Results found for "{1}" {Locked="{0}", "{1}"} Label for a search result counter. {0} is replaced by the number of result items. {1} is replaced with the search term. - - On {0} - {Locked="{0}"} Header text of a section for restoring packages from another device. {0} is replaced by a device name. - - - These applications are from {0}. Select the ones to install. - {Locked="{0}"} Description text of a section for restoring packages from another device. {0} is replaced by a device name. - - - These applications are from {0} (last synced on {1}). Select the ones to install. - {Locked="{0}","{1}"} Description text of a section for restoring packages from another device. {0} is replaced by a device name. {1} is replaced by a date. - {0} packages {Locked="{0}"} Display the number of packages. {0} is replaced by the number of packages. @@ -661,10 +649,6 @@ Previous Label for a "go to previous page" button - - Restore - Label for restore button - Generate Configuration file Text for a generating configuration file button From 949ca5172bfc31543d6b5bbadbc85c2225fbeee4 Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Mon, 21 Oct 2024 10:08:30 -0700 Subject: [PATCH 07/13] Updates (in progress) --- .../ViewModels/PackageViewModel.cs | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs index 1b41a3a2b4..8be3e37c75 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs @@ -11,9 +11,8 @@ using DevHome.Services.WindowsPackageManager.Contracts; using DevHome.SetupFlow.Models; using DevHome.SetupFlow.Services; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Media.Imaging; -using Windows.Storage.Streams; -using Windows.System; namespace DevHome.SetupFlow.ViewModels; @@ -85,8 +84,8 @@ public PackageViewModel( _orchestrator = orchestrator; // Lazy-initialize optional or expensive view model members - _packageDarkThemeIcon = new Lazy(() => IconByTheme); - _packageLightThemeIcon = new Lazy(() => IconByTheme); + _packageDarkThemeIcon = new Lazy(GetIconByTheme()); + _packageLightThemeIcon = new Lazy(GetIconByTheme()); SelectedVersion = GetDefaultSelectedVersion(); InstallPackageTask = CreateInstallTask(); @@ -202,19 +201,17 @@ private void ToggleSelection() _screenReaderService.Announce(announcementText); } - public BitmapImage IconByTheme + public BitmapImage GetIconByTheme() { - get + return _themeSelector.Theme switch { - if (_themeSelector.IsDarkTheme()) - { - return CreateBitmapImage(_package.DarkThemeIcon); - } - else - { - return CreateBitmapImage(_package.LightThemeIcon); - } - } + // Get default dark theme icon if corresponding package icon was not found + ElementTheme.Dark => + _package.DarkThemeIcon == null ? DefaultDarkPackageIconSource : CreateBitmapImage(_package.DarkThemeIcon), + + // Get default light theme icon if corresponding package icon was not found + _ => _package.LightThemeIcon == null ? DefaultLightPackageIconSource : CreateBitmapImage(_package.LightThemeIcon), + }; } private BitmapImage CreateBitmapImage(IRandomAccessStream stream) From c753337a6963ead123931d394ef74ac1d2d27b43 Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Mon, 21 Oct 2024 10:20:19 -0700 Subject: [PATCH 08/13] Update GetIconByTheme --- .../SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs index 8be3e37c75..17faeb40de 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs @@ -13,6 +13,8 @@ using DevHome.SetupFlow.Services; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Media.Imaging; +using Windows.Storage.Streams; +using Windows.System; namespace DevHome.SetupFlow.ViewModels; From 058e7ffa757798d3b31ba770d1b114df1d7bc520 Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Mon, 21 Oct 2024 13:03:12 -0700 Subject: [PATCH 09/13] Split IconByTheme into GetLight/DarkThemeIcon() --- .../ViewModels/PackageViewModel.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs index 17faeb40de..12493534be 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs @@ -86,8 +86,8 @@ public PackageViewModel( _orchestrator = orchestrator; // Lazy-initialize optional or expensive view model members - _packageDarkThemeIcon = new Lazy(GetIconByTheme()); - _packageLightThemeIcon = new Lazy(GetIconByTheme()); + _packageDarkThemeIcon = new Lazy(() => GetDarkThemeIcon()); + _packageLightThemeIcon = new Lazy(() => GetLightThemeIcon()); SelectedVersion = GetDefaultSelectedVersion(); InstallPackageTask = CreateInstallTask(); @@ -203,17 +203,24 @@ private void ToggleSelection() _screenReaderService.Announce(announcementText); } - public BitmapImage GetIconByTheme() + public BitmapImage GetLightThemeIcon() { - return _themeSelector.Theme switch + if (_package.LightThemeIcon != null) { - // Get default dark theme icon if corresponding package icon was not found - ElementTheme.Dark => - _package.DarkThemeIcon == null ? DefaultDarkPackageIconSource : CreateBitmapImage(_package.DarkThemeIcon), + return CreateBitmapImage(_package.LightThemeIcon); + } + + return DefaultDarkPackageIconSource; + } + + public BitmapImage GetDarkThemeIcon() + { + if (_package.DarkThemeIcon != null) + { + return CreateBitmapImage(_package.DarkThemeIcon); + } - // Get default light theme icon if corresponding package icon was not found - _ => _package.LightThemeIcon == null ? DefaultLightPackageIconSource : CreateBitmapImage(_package.LightThemeIcon), - }; + return DefaultDarkPackageIconSource; } private BitmapImage CreateBitmapImage(IRandomAccessStream stream) From 0a9357da78a8f9fec76568653ef27d7bdec28b98 Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Mon, 21 Oct 2024 13:15:08 -0700 Subject: [PATCH 10/13] Refactor GetLight/DarkThemeIcon() --- .../ViewModels/PackageViewModel.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs index 12493534be..a43ac9193a 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Reflection.Metadata.Ecma335; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -205,22 +206,12 @@ private void ToggleSelection() public BitmapImage GetLightThemeIcon() { - if (_package.LightThemeIcon != null) - { - return CreateBitmapImage(_package.LightThemeIcon); - } - - return DefaultDarkPackageIconSource; + return _packageLightThemeIcon == null ? DefaultLightPackageIconSource : CreateBitmapImage(_package.LightThemeIcon); } public BitmapImage GetDarkThemeIcon() { - if (_package.DarkThemeIcon != null) - { - return CreateBitmapImage(_package.DarkThemeIcon); - } - - return DefaultDarkPackageIconSource; + return _packageDarkThemeIcon == null ? DefaultDarkPackageIconSource : CreateBitmapImage(_package.DarkThemeIcon); } private BitmapImage CreateBitmapImage(IRandomAccessStream stream) From 5acf585945be56b0f2fadff64cd8315ff2baf866 Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Tue, 22 Oct 2024 15:42:47 -0700 Subject: [PATCH 11/13] Check _package.Icon, not packageIcon --- .../DevHome.SetupFlow/ViewModels/PackageViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs index a43ac9193a..abaff777b4 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs @@ -206,12 +206,12 @@ private void ToggleSelection() public BitmapImage GetLightThemeIcon() { - return _packageLightThemeIcon == null ? DefaultLightPackageIconSource : CreateBitmapImage(_package.LightThemeIcon); + return _package.LightThemeIcon == null ? DefaultLightPackageIconSource : CreateBitmapImage(_package.LightThemeIcon); } public BitmapImage GetDarkThemeIcon() { - return _packageDarkThemeIcon == null ? DefaultDarkPackageIconSource : CreateBitmapImage(_package.DarkThemeIcon); + return _package.DarkThemeIcon == null ? DefaultDarkPackageIconSource : CreateBitmapImage(_package.DarkThemeIcon); } private BitmapImage CreateBitmapImage(IRandomAccessStream stream) From 7225b3a9bdfdb3978f508d7a73c9bcc2a13179bc Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Tue, 22 Oct 2024 17:33:57 -0700 Subject: [PATCH 12/13] Remove unnecessary usings from PackageViewModel.cs --- .../SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs index abaff777b4..870cd06082 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Reflection.Metadata.Ecma335; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -12,7 +11,6 @@ using DevHome.Services.WindowsPackageManager.Contracts; using DevHome.SetupFlow.Models; using DevHome.SetupFlow.Services; -using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Media.Imaging; using Windows.Storage.Streams; using Windows.System; From 59b1cdc4815a80cfac34f00d21a6c221a6cc0a75 Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Tue, 22 Oct 2024 17:40:48 -0700 Subject: [PATCH 13/13] Refactor GetIconByTheme() --- .../ViewModels/PackageViewModel.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs index 870cd06082..e8435c0efe 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs @@ -11,6 +11,7 @@ using DevHome.Services.WindowsPackageManager.Contracts; using DevHome.SetupFlow.Models; using DevHome.SetupFlow.Services; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Media.Imaging; using Windows.Storage.Streams; using Windows.System; @@ -85,8 +86,8 @@ public PackageViewModel( _orchestrator = orchestrator; // Lazy-initialize optional or expensive view model members - _packageDarkThemeIcon = new Lazy(() => GetDarkThemeIcon()); - _packageLightThemeIcon = new Lazy(() => GetLightThemeIcon()); + _packageDarkThemeIcon = new Lazy(() => GetIconByTheme()); + _packageLightThemeIcon = new Lazy(() => GetIconByTheme()); SelectedVersion = GetDefaultSelectedVersion(); InstallPackageTask = CreateInstallTask(); @@ -202,14 +203,13 @@ private void ToggleSelection() _screenReaderService.Announce(announcementText); } - public BitmapImage GetLightThemeIcon() + private BitmapImage GetIconByTheme() { - return _package.LightThemeIcon == null ? DefaultLightPackageIconSource : CreateBitmapImage(_package.LightThemeIcon); - } - - public BitmapImage GetDarkThemeIcon() - { - return _package.DarkThemeIcon == null ? DefaultDarkPackageIconSource : CreateBitmapImage(_package.DarkThemeIcon); + return _themeSelector.GetActualTheme() switch + { + ElementTheme.Dark => _package.DarkThemeIcon == null ? DefaultDarkPackageIconSource : CreateBitmapImage(_package.DarkThemeIcon), + _ => _package.LightThemeIcon == null ? DefaultLightPackageIconSource : CreateBitmapImage(_package.LightThemeIcon), + }; } private BitmapImage CreateBitmapImage(IRandomAccessStream stream)