Skip to content

Commit

Permalink
Refactor GetIconByTheme()
Browse files Browse the repository at this point in the history
  • Loading branch information
lauren-ciha committed Oct 23, 2024
1 parent 7225b3a commit 59b1cdc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,8 +86,8 @@ public PackageViewModel(
_orchestrator = orchestrator;

// Lazy-initialize optional or expensive view model members
_packageDarkThemeIcon = new Lazy<BitmapImage>(() => GetDarkThemeIcon());
_packageLightThemeIcon = new Lazy<BitmapImage>(() => GetLightThemeIcon());
_packageDarkThemeIcon = new Lazy<BitmapImage>(() => GetIconByTheme());
_packageLightThemeIcon = new Lazy<BitmapImage>(() => GetIconByTheme());

SelectedVersion = GetDefaultSelectedVersion();
InstallPackageTask = CreateInstallTask();
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 59b1cdc

Please sign in to comment.