Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions src/UniGetUI.Avalonia/Infrastructure/TrayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ public TrayService(MainWindow owner)
Menu = BuildMenu(owner, _restartComputerItem),
};

// macOS tints the menu bar from the wallpaper, not from the system appearance, so no theme
// check can pick the right glyph; a template icon is masked and tinted by macOS itself.
if (OperatingSystem.IsMacOS())
{
MacOSProperties.SetIsTemplateIcon(_trayIcon, true);
}

PendingRebootStore.Changed += OnPendingRebootStoreChanged;
if (Application.Current?.PlatformSettings is { } platformSettings)
{
platformSettings.ColorValuesChanged += OnPlatformColorValuesChanged;
}

_trayIcon.Clicked += (_, _) => Dispatcher.UIThread.Post(() => owner.ShowFromTray());

Expand Down Expand Up @@ -144,15 +155,30 @@ private static bool IsTaskbarLight()
return false;
}
#else
// On Linux (and other platforms), mirror the app's active theme variant so
// the icon remains legible regardless of the desktop colour scheme.
return Application.Current?.ActualThemeVariant == ThemeVariant.Light;
// macOS: the icon is a template (see the constructor), only its alpha is used.
if (OperatingSystem.IsMacOS())
{
return true;
}

// The Linux panel follows the desktop appearance, not UniGetUI's own theme.
var app = Application.Current;
PlatformThemeVariant? osVariant = app?.PlatformSettings?.GetColorValues().ThemeVariant;
if (osVariant is not null)
{
return osVariant == PlatformThemeVariant.Light;
}

return app?.ActualThemeVariant == ThemeVariant.Light;
#endif
}

private void OnPendingRebootStoreChanged(object? sender, EventArgs e)
=> Dispatcher.UIThread.Post(UpdateStatus);

private void OnPlatformColorValuesChanged(object? sender, PlatformColorValues e)
=> Dispatcher.UIThread.Post(UpdateStatus);

private static NativeMenu BuildMenu(MainWindow owner, NativeMenuItem restartComputerItem)
{
var menu = new NativeMenu();
Expand Down Expand Up @@ -194,6 +220,11 @@ public void Dispose()
{
PendingRebootStore.Changed -= OnPendingRebootStoreChanged;
var app = Application.Current;
if (app?.PlatformSettings is { } platformSettings)
{
platformSettings.ColorValuesChanged -= OnPlatformColorValuesChanged;
}

if (app is not null)
TrayIcon.GetIcons(app)?.Remove(_trayIcon);
_trayIcon.Dispose();
Expand Down
Loading