Skip to content

Commit

Permalink
Split IconByTheme into GetLight/DarkThemeIcon()
Browse files Browse the repository at this point in the history
  • Loading branch information
lauren-ciha committed Oct 21, 2024
1 parent 2684cec commit 6aabbd9
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public PackageViewModel(
_orchestrator = orchestrator;

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

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

0 comments on commit 6aabbd9

Please sign in to comment.