Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Runtime.Versioning;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Platform;
using Avalonia.Styling;
using Avalonia.Threading;
using Microsoft.Win32;
using UniGetUI.Avalonia.Views;
using UniGetUI.Core.Data;
using UniGetUI.Core.Logging;
Expand All @@ -14,13 +13,12 @@

namespace UniGetUI.Avalonia.Infrastructure;

[SupportedOSPlatform("windows")]
internal sealed class WindowsTrayService : IDisposable
internal sealed class TrayService : IDisposable
{
private readonly TrayIcon _trayIcon;
private string _lastIconUri = "";

public WindowsTrayService(MainWindow owner)
public TrayService(MainWindow owner)
{
_trayIcon = new TrayIcon
{
Expand Down Expand Up @@ -96,19 +94,25 @@ public void UpdateStatus()
}
}

// Windows reads SystemUsesLightTheme to pick dark vs light taskbar icons.
private static bool IsTaskbarLight()
{
#if WINDOWS
// On Windows, read the registry to match the taskbar background colour.
try
{
using var key = Registry.CurrentUser.OpenSubKey(
using var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
return key?.GetValue("SystemUsesLightTheme") is int v && v > 0;
}
catch
{
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;
#endif
}

private static NativeMenu BuildMenu(MainWindow owner)
Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI.Avalonia/UniGetUI.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
<Compile Include="Infrastructure\AvaloniaOperationRegistry.cs" />
<Compile Include="Infrastructure\AppRestartHelper.cs" />
<Compile Include="Infrastructure\WindowsAppNotificationBridge.cs" />
<Compile Include="Infrastructure\WindowsTrayService.cs" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<Compile Include="Infrastructure\TrayService.cs" />
<Compile Include="Infrastructure\MacOsNotificationBridge.cs" />
<Compile Include="Infrastructure\Secrets.cs" />
<Compile Include="Infrastructure\AsyncCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public partial class NotificationsViewModel : ViewModelBase
[ObservableProperty] private bool _isSystemTrayEnabled;
[ObservableProperty] private bool _isNotificationsEnabled;

/// <summary>True when the system-tray-disabled warning should be shown (Windows only).</summary>
public bool IsSystemTrayWarningVisible => OperatingSystem.IsWindows() && !IsSystemTrayEnabled;
/// <summary>True when the system-tray-disabled warning should be shown.</summary>
public bool IsSystemTrayWarningVisible => !IsSystemTrayEnabled;

public NotificationsViewModel()
{
Expand Down
24 changes: 7 additions & 17 deletions src/UniGetUI.Avalonia/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public partial class MainWindow : Window
private const uint SWP_FRAMECHANGED = 0x0020;

private bool _focusSidebarSelectionOnNextPageChange;
private WindowsTrayService? _trayService;
private TrayService? _trayService;
private bool _allowClose;
private NativeMethods.RECT? _windowsRestoreBoundsBeforeManualMaximize;

Expand All @@ -73,28 +73,22 @@ public MainWindow()
KeyDown += Window_KeyDown;
ViewModel.CurrentPageChanged += OnCurrentPageChanged;

if (OperatingSystem.IsWindows())
{
_trayService = new WindowsTrayService(this);
_trayService.UpdateStatus();
}
_trayService = new TrayService(this);
_trayService.UpdateStatus();
}

protected override void OnClosing(WindowClosingEventArgs e)
{
if (!_allowClose && OperatingSystem.IsWindows() && !Settings.Get(Settings.K.DisableSystemTray))
if (!_allowClose && !Settings.Get(Settings.K.DisableSystemTray))
{
e.Cancel = true;
Hide();
return;
}

AvaloniaAutoUpdater.ReleaseLockForAutoupdate_Window = true;
if (OperatingSystem.IsWindows())
{
_trayService?.Dispose();
_trayService = null;
}
_trayService?.Dispose();
_trayService = null;
base.OnClosing(e);
}

Expand Down Expand Up @@ -532,11 +526,7 @@ public void ShowBanner(string title, string message, RuntimeNotificationLevel le
ViewModel.ErrorBanner.IsOpen = true;
}

public void UpdateSystemTrayStatus()
{
if (OperatingSystem.IsWindows())
_trayService?.UpdateStatus();
}
public void UpdateSystemTrayStatus() => _trayService?.UpdateStatus();

public void ShowRuntimeNotification(string title, string message, RuntimeNotificationLevel level) =>
ShowBanner(title, message, level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
StateChangedCommand="{Binding ShowRestartRequiredCommand}"
CornerRadius="8"/>

<StackPanel x:Name="SystemTraySection" Orientation="Vertical" IsVisible="{Binding IsWindows}">
<StackPanel x:Name="SystemTraySection" Orientation="Vertical">
<settings:TranslatedTextBlock Text="UniGetUI on the background and system tray"
FontWeight="SemiBold"
Margin="44,32,4,8"
Expand All @@ -46,6 +46,7 @@
<settings:ButtonCard x:Name="EditAutostartSettings"
CornerRadius="0,0,8,8"
BorderThickness="1,0,1,1"
IsVisible="{Binding IsWindows}"
Text="{t:Translate Manage UniGetUI autostart behaviour}"
ButtonText="{t:Translate Open}"
Command="{Binding EditAutostartSettingsCommand}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public Interface_P()
DataContext = new Interface_PViewModel();
InitializeComponent();

if (OperatingSystem.IsMacOS())
SystemTraySection.IsVisible = false;

VM.RestartRequired += (s, e) => RestartRequired?.Invoke(s, e);
_ = VM.LoadIconCacheSize();

Expand Down
Loading