Fixing system tray icon.
This commit is contained in:
@@ -1,36 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Wino.Core.Domain.Interfaces;
|
|
||||||
|
|
||||||
public interface ISystemTrayService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the system tray icon.
|
|
||||||
/// </summary>
|
|
||||||
void Initialize();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Shows the system tray icon.
|
|
||||||
/// </summary>
|
|
||||||
void Show();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Hides the system tray icon.
|
|
||||||
/// </summary>
|
|
||||||
void Hide();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Event fired when the tray icon is double-clicked.
|
|
||||||
/// </summary>
|
|
||||||
event EventHandler? TrayIconDoubleClicked;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets whether the tray icon is currently minimized.
|
|
||||||
/// </summary>
|
|
||||||
bool IsMinimizedToTray { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Disposes of the system tray resources.
|
|
||||||
/// </summary>
|
|
||||||
void Dispose();
|
|
||||||
}
|
|
||||||
@@ -686,6 +686,8 @@
|
|||||||
"SystemFolderConfigDialogValidation_InboxSelected": "You can't assign Inbox folder to any other system folder.",
|
"SystemFolderConfigDialogValidation_InboxSelected": "You can't assign Inbox folder to any other system folder.",
|
||||||
"SystemFolderConfigSetupSuccess_Message": "System folders are successfully configured.",
|
"SystemFolderConfigSetupSuccess_Message": "System folders are successfully configured.",
|
||||||
"SystemFolderConfigSetupSuccess_Title": "System Folders Setup",
|
"SystemFolderConfigSetupSuccess_Title": "System Folders Setup",
|
||||||
|
"SystemTrayMenu_ShowWino": "Open Wino Mail",
|
||||||
|
"SystemTrayMenu_ExitWino": "Exit",
|
||||||
"TestingImapConnectionMessage": "Testing server connection...",
|
"TestingImapConnectionMessage": "Testing server connection...",
|
||||||
"TitleBarServerDisconnectedButton_Description": "Wino is disconnected from the network. Click reconnect to restore connection.",
|
"TitleBarServerDisconnectedButton_Description": "Wino is disconnected from the network. Click reconnect to restore connection.",
|
||||||
"TitleBarServerDisconnectedButton_Title": "no connection",
|
"TitleBarServerDisconnectedButton_Title": "no connection",
|
||||||
|
|||||||
+10
-12
@@ -2,13 +2,13 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using CommunityToolkit.Mvvm.Messaging;
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Windows.AppLifecycle;
|
||||||
using Wino.Core.Domain.Enums;
|
using Wino.Core.Domain.Enums;
|
||||||
using Wino.Core.Domain.Interfaces;
|
using Wino.Core.Domain.Interfaces;
|
||||||
using Wino.Core.WinUI;
|
using Wino.Core.WinUI;
|
||||||
using Wino.Core.WinUI.Interfaces;
|
using Wino.Core.WinUI.Interfaces;
|
||||||
using Wino.Mail.Services;
|
using Wino.Mail.Services;
|
||||||
using Wino.Mail.ViewModels;
|
using Wino.Mail.ViewModels;
|
||||||
using Wino.Mail.WinUI.Services;
|
|
||||||
using Wino.Messaging.Server;
|
using Wino.Messaging.Server;
|
||||||
using Wino.Services;
|
using Wino.Services;
|
||||||
namespace Wino.Mail.WinUI;
|
namespace Wino.Mail.WinUI;
|
||||||
@@ -36,7 +36,6 @@ public partial class App : WinoApplication, IRecipient<NewMailSynchronizationReq
|
|||||||
services.AddTransient<ISettingsBuilderService, SettingsBuilderService>();
|
services.AddTransient<ISettingsBuilderService, SettingsBuilderService>();
|
||||||
services.AddTransient<IProviderService, ProviderService>();
|
services.AddTransient<IProviderService, ProviderService>();
|
||||||
services.AddSingleton<IAuthenticatorConfig, MailAuthenticatorConfiguration>();
|
services.AddSingleton<IAuthenticatorConfig, MailAuthenticatorConfiguration>();
|
||||||
services.AddSingleton<ISystemTrayService, SystemTrayService>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegisterViewModels(IServiceCollection services)
|
private void RegisterViewModels(IServiceCollection services)
|
||||||
@@ -79,6 +78,8 @@ public partial class App : WinoApplication, IRecipient<NewMailSynchronizationReq
|
|||||||
return services.BuildServiceProvider();
|
return services.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsStartupTaskLaunch() => AppInstance.GetCurrent().GetActivatedEventArgs()?.Kind == ExtendedActivationKind.StartupTask;
|
||||||
|
|
||||||
protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
||||||
{
|
{
|
||||||
// TODO: Check app relaunch mutex before loading anything.
|
// TODO: Check app relaunch mutex before loading anything.
|
||||||
@@ -99,19 +100,16 @@ public partial class App : WinoApplication, IRecipient<NewMailSynchronizationReq
|
|||||||
|
|
||||||
await InitializeServicesAsync();
|
await InitializeServicesAsync();
|
||||||
|
|
||||||
// Initialize system tray
|
|
||||||
var systemTrayService = Services.GetRequiredService<ISystemTrayService>();
|
|
||||||
if (systemTrayService != null)
|
|
||||||
{
|
|
||||||
systemTrayService.Initialize();
|
|
||||||
systemTrayService.Show(); // Explicitly show the tray icon
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MainWindow is not IWinoShellWindow shellWindow) throw new ArgumentException("MainWindow must implement IWinoShellWindow");
|
if (MainWindow is not IWinoShellWindow shellWindow) throw new ArgumentException("MainWindow must implement IWinoShellWindow");
|
||||||
|
|
||||||
shellWindow.HandleAppActivation(args);
|
bool isStartupTaskLaunch = IsStartupTaskLaunch();
|
||||||
|
|
||||||
MainWindow.Activate();
|
// Do not actiavate window if launched from startup task. Keep running in the system tray.
|
||||||
|
if (!isStartupTaskLaunch)
|
||||||
|
{
|
||||||
|
shellWindow.HandleAppActivation(args);
|
||||||
|
MainWindow.Activate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegisterRecipients()
|
private void RegisterRecipients()
|
||||||
|
|||||||
@@ -1,196 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using H.NotifyIcon;
|
|
||||||
using Microsoft.UI.Xaml;
|
|
||||||
using Microsoft.UI.Xaml.Controls;
|
|
||||||
using Microsoft.UI.Xaml.Media.Imaging;
|
|
||||||
using Wino.Core.Domain.Interfaces;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Wino.Core.WinUI;
|
|
||||||
|
|
||||||
namespace Wino.Mail.WinUI.Services;
|
|
||||||
|
|
||||||
public class SystemTrayService : ISystemTrayService
|
|
||||||
{
|
|
||||||
private TaskbarIcon? _taskbarIcon;
|
|
||||||
private bool _isDisposed;
|
|
||||||
private bool _isMinimizedToTray;
|
|
||||||
|
|
||||||
public bool IsMinimizedToTray => _isMinimizedToTray;
|
|
||||||
|
|
||||||
public event EventHandler? TrayIconDoubleClicked;
|
|
||||||
|
|
||||||
public void Initialize()
|
|
||||||
{
|
|
||||||
if (_taskbarIcon != null) return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debug.WriteLine("Starting system tray initialization...");
|
|
||||||
|
|
||||||
// Create TaskbarIcon first
|
|
||||||
_taskbarIcon = new TaskbarIcon();
|
|
||||||
|
|
||||||
// Set basic properties first
|
|
||||||
_taskbarIcon.ToolTipText = "Wino Mail";
|
|
||||||
|
|
||||||
// Configure the taskbar icon with icon loading
|
|
||||||
var iconUri = new Uri("ms-appx:///Assets/Wino_Icon.ico");
|
|
||||||
var bitmapImage = new BitmapImage(iconUri);
|
|
||||||
_taskbarIcon.IconSource = bitmapImage;
|
|
||||||
System.Diagnostics.Debug.WriteLine("Icon source set");
|
|
||||||
|
|
||||||
// Create context menu
|
|
||||||
var contextMenu = new MenuFlyout();
|
|
||||||
|
|
||||||
// Show Window menu item
|
|
||||||
var showMenuItem = new MenuFlyoutItem
|
|
||||||
{
|
|
||||||
Text = "Show Wino Mail",
|
|
||||||
Icon = new SymbolIcon(Symbol.Home)
|
|
||||||
};
|
|
||||||
showMenuItem.Click += ShowMenuItem_Click;
|
|
||||||
contextMenu.Items.Add(showMenuItem);
|
|
||||||
System.Diagnostics.Debug.WriteLine("Show menu item added");
|
|
||||||
|
|
||||||
// Separator
|
|
||||||
contextMenu.Items.Add(new MenuFlyoutSeparator());
|
|
||||||
|
|
||||||
// Exit menu item
|
|
||||||
var exitMenuItem = new MenuFlyoutItem
|
|
||||||
{
|
|
||||||
Text = "Exit",
|
|
||||||
Icon = new SymbolIcon(Symbol.Cancel)
|
|
||||||
};
|
|
||||||
exitMenuItem.Click += ExitMenuItem_Click;
|
|
||||||
contextMenu.Items.Add(exitMenuItem);
|
|
||||||
System.Diagnostics.Debug.WriteLine("Exit menu item added");
|
|
||||||
|
|
||||||
// Set context menu
|
|
||||||
_taskbarIcon.ContextFlyout = contextMenu;
|
|
||||||
|
|
||||||
// Handle double-click using the proper event
|
|
||||||
_taskbarIcon.LeftClickCommand = new RelayCommand(OnTrayIconLeftClick);
|
|
||||||
|
|
||||||
// Set visibility and create explicitly
|
|
||||||
_taskbarIcon.Visibility = Visibility.Visible;
|
|
||||||
|
|
||||||
// Try ForceCreate to ensure the icon is properly created in the system tray
|
|
||||||
_taskbarIcon.ForceCreate();
|
|
||||||
System.Diagnostics.Debug.WriteLine("System tray icon created and visible");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debug.WriteLine($"Failed to initialize system tray: {ex.Message}");
|
|
||||||
System.Diagnostics.Debug.WriteLine($"Stack trace: {ex.StackTrace}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ShowMenuItem_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debug.WriteLine("Show menu item clicked");
|
|
||||||
TrayIconDoubleClicked?.Invoke(this, EventArgs.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ExitMenuItem_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debug.WriteLine("Exit menu item clicked");
|
|
||||||
ExitApplication();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTrayIconLeftClick()
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debug.WriteLine("Tray icon left clicked");
|
|
||||||
TrayIconDoubleClicked?.Invoke(this, EventArgs.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Show()
|
|
||||||
{
|
|
||||||
if (_taskbarIcon != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_taskbarIcon.Visibility = Visibility.Visible;
|
|
||||||
_taskbarIcon.ForceCreate(); // Ensure the icon is properly created and visible
|
|
||||||
_isMinimizedToTray = true;
|
|
||||||
System.Diagnostics.Debug.WriteLine("System tray icon set to visible and force created");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debug.WriteLine($"Failed to show system tray icon: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debug.WriteLine("TaskbarIcon is null when trying to show");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Hide()
|
|
||||||
{
|
|
||||||
if (_taskbarIcon != null)
|
|
||||||
{
|
|
||||||
_taskbarIcon.Visibility = Visibility.Collapsed;
|
|
||||||
_isMinimizedToTray = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ExitApplication()
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debug.WriteLine("Attempting to exit application...");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Clean up the tray icon first
|
|
||||||
Dispose();
|
|
||||||
|
|
||||||
// Get the main window and close it properly
|
|
||||||
if (WinoApplication.MainWindow is ShellWindow shellWindow)
|
|
||||||
{
|
|
||||||
// Force close the window without minimizing to tray
|
|
||||||
shellWindow.ForceClose();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Fallback to application exit
|
|
||||||
Application.Current.Exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
System.Diagnostics.Debug.WriteLine($"Error during application exit: {ex.Message}");
|
|
||||||
// Force exit if normal exit fails
|
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (_isDisposed) return;
|
|
||||||
|
|
||||||
_taskbarIcon?.Dispose();
|
|
||||||
_taskbarIcon = null;
|
|
||||||
_isDisposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simple RelayCommand implementation for the tray icon
|
|
||||||
public class RelayCommand : ICommand
|
|
||||||
{
|
|
||||||
private readonly Action _execute;
|
|
||||||
private readonly Func<bool>? _canExecute;
|
|
||||||
|
|
||||||
public RelayCommand(Action execute, Func<bool>? canExecute = null)
|
|
||||||
{
|
|
||||||
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
|
||||||
_canExecute = canExecute;
|
|
||||||
}
|
|
||||||
|
|
||||||
public event EventHandler? CanExecuteChanged;
|
|
||||||
|
|
||||||
public bool CanExecute(object? parameter) => _canExecute?.Invoke() ?? true;
|
|
||||||
|
|
||||||
public void Execute(object? parameter) => _execute();
|
|
||||||
|
|
||||||
public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
|
||||||
}
|
|
||||||
@@ -4,8 +4,10 @@
|
|||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:domain="using:Wino.Core.Domain"
|
||||||
xmlns:local="using:Wino.Mail.WinUI"
|
xmlns:local="using:Wino.Mail.WinUI"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:notifyicon="using:H.NotifyIcon"
|
||||||
xmlns:winuiex="using:WinUIEx"
|
xmlns:winuiex="using:WinUIEx"
|
||||||
Title="ShellWindow"
|
Title="ShellWindow"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
@@ -30,9 +32,25 @@
|
|||||||
IsBackButtonVisible="{x:Bind StatePersistanceService.IsBackButtonVisible, Mode=OneWay}"
|
IsBackButtonVisible="{x:Bind StatePersistanceService.IsBackButtonVisible, Mode=OneWay}"
|
||||||
IsPaneToggleButtonVisible="True"
|
IsPaneToggleButtonVisible="True"
|
||||||
PaneToggleRequested="PaneButtonClicked" />
|
PaneToggleRequested="PaneButtonClicked" />
|
||||||
|
|
||||||
<Frame
|
<Frame
|
||||||
x:Name="MainShellFrame"
|
x:Name="MainShellFrame"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Navigated="MainFrameNavigated" />
|
Navigated="MainFrameNavigated" />
|
||||||
|
|
||||||
|
<notifyicon:TaskbarIcon
|
||||||
|
x:Name="SystemTrayIcon"
|
||||||
|
ContextMenuMode="PopupMenu"
|
||||||
|
DoubleClickCommand="{x:Bind ShowWinoCommand}"
|
||||||
|
IconSource="/Assets/Wino_Icon.ico"
|
||||||
|
NoLeftClickDelay="True">
|
||||||
|
<notifyicon:TaskbarIcon.ContextFlyout>
|
||||||
|
<MenuFlyout AreOpenCloseAnimationsEnabled="False">
|
||||||
|
<MenuFlyoutItem Command="{x:Bind ShowWinoCommand}" Text="{x:Bind domain:Translator.SystemTrayMenu_ShowWino}" />
|
||||||
|
<MenuFlyoutSeparator />
|
||||||
|
<MenuFlyoutItem Command="{x:Bind ExitWinoCommand}" Text="{x:Bind domain:Translator.SystemTrayMenu_ExitWino}" />
|
||||||
|
</MenuFlyout>
|
||||||
|
</notifyicon:TaskbarIcon.ContextFlyout>
|
||||||
|
</notifyicon:TaskbarIcon>
|
||||||
</Grid>
|
</Grid>
|
||||||
</winuiex:WindowEx>
|
</winuiex:WindowEx>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using CommunityToolkit.Mvvm.Messaging;
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
@@ -19,7 +21,9 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow, IRecipient
|
|||||||
{
|
{
|
||||||
public IStatePersistanceService StatePersistanceService { get; } = WinoApplication.Current.Services.GetService<IStatePersistanceService>() ?? throw new Exception("StatePersistanceService not registered in DI container.");
|
public IStatePersistanceService StatePersistanceService { get; } = WinoApplication.Current.Services.GetService<IStatePersistanceService>() ?? throw new Exception("StatePersistanceService not registered in DI container.");
|
||||||
public IPreferencesService PreferencesService { get; } = WinoApplication.Current.Services.GetService<IPreferencesService>() ?? throw new Exception("PreferencesService not registered in DI container.");
|
public IPreferencesService PreferencesService { get; } = WinoApplication.Current.Services.GetService<IPreferencesService>() ?? throw new Exception("PreferencesService not registered in DI container.");
|
||||||
private readonly ISystemTrayService _systemTrayService;
|
|
||||||
|
public ICommand ShowWinoCommand { get; set; }
|
||||||
|
public ICommand ExitWinoCommand { get; set; }
|
||||||
|
|
||||||
public ShellWindow()
|
public ShellWindow()
|
||||||
{
|
{
|
||||||
@@ -31,22 +35,22 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow, IRecipient
|
|||||||
MinHeight = 420;
|
MinHeight = 420;
|
||||||
ConfigureTitleBar();
|
ConfigureTitleBar();
|
||||||
|
|
||||||
// Initialize system tray service
|
|
||||||
_systemTrayService = WinoApplication.Current.Services.GetService<ISystemTrayService>() ?? throw new Exception("SystemTrayService not registered in DI container.");
|
|
||||||
_systemTrayService.Initialize();
|
|
||||||
_systemTrayService.TrayIconDoubleClicked += OnTrayIconDoubleClicked;
|
|
||||||
|
|
||||||
// Handle window closing event to minimize to tray instead of closing
|
// Handle window closing event to minimize to tray instead of closing
|
||||||
Closed += OnWindowClosed;
|
Closed += OnWindowClosed;
|
||||||
|
|
||||||
// Use the AppWindow.Closing event to handle the close request
|
// Use the AppWindow.Closing event to handle the close request
|
||||||
AppWindow.Closing += OnAppWindowClosing;
|
AppWindow.Closing += OnAppWindowClosing;
|
||||||
|
|
||||||
|
ShowWinoCommand = new RelayCommand(RestoreFromTray);
|
||||||
|
ExitWinoCommand = new RelayCommand(ForceClose);
|
||||||
|
|
||||||
|
SystemTrayIcon.ForceCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ConfigureTitleBar()
|
private void ConfigureTitleBar()
|
||||||
{
|
{
|
||||||
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
|
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
|
||||||
|
|
||||||
// Apply initial theme colors
|
// Apply initial theme colors
|
||||||
var themeService = WinoApplication.Current.Services.GetService<INewThemeService>();
|
var themeService = WinoApplication.Current.Services.GetService<INewThemeService>();
|
||||||
if (themeService != null)
|
if (themeService != null)
|
||||||
@@ -133,54 +137,40 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow, IRecipient
|
|||||||
|
|
||||||
private void OnAppWindowClosing(object sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs e)
|
private void OnAppWindowClosing(object sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs e)
|
||||||
{
|
{
|
||||||
// Cancel the close and minimize to tray instead
|
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
MinimizeToTray();
|
MinimizeToTray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnWindowClosed(object sender, WindowEventArgs e)
|
private void OnWindowClosed(object sender, WindowEventArgs e)
|
||||||
{
|
{
|
||||||
// Clean up tray icon when window is actually closed
|
SystemTrayIcon?.Dispose();
|
||||||
_systemTrayService?.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MinimizeToTray()
|
private void MinimizeToTray()
|
||||||
{
|
{
|
||||||
// Hide the window and show tray icon
|
|
||||||
this.Hide();
|
this.Hide();
|
||||||
_systemTrayService.Show();
|
SystemTrayIcon.ForceCreate();
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTrayIconDoubleClicked(object? sender, EventArgs e)
|
|
||||||
{
|
|
||||||
// Restore the window from tray
|
|
||||||
RestoreFromTray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RestoreFromTray()
|
private void RestoreFromTray()
|
||||||
{
|
{
|
||||||
if (_systemTrayService.IsMinimizedToTray)
|
this.Show();
|
||||||
{
|
BringToFront();
|
||||||
// Show the window and hide tray icon
|
|
||||||
this.Show();
|
|
||||||
this.Activate();
|
|
||||||
_systemTrayService.Hide();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ForceClose()
|
public void ForceClose()
|
||||||
{
|
{
|
||||||
// Unsubscribe from the closing event to avoid infinite loop
|
// Unsubscribe from the closing event to avoid infinite loop
|
||||||
AppWindow.Closing -= OnAppWindowClosing;
|
AppWindow.Closing -= OnAppWindowClosing;
|
||||||
|
|
||||||
// Clean up system tray
|
// Clean up system tray
|
||||||
_systemTrayService?.Dispose();
|
SystemTrayIcon?.Dispose();
|
||||||
|
|
||||||
UnregisterRecipients();
|
UnregisterRecipients();
|
||||||
|
|
||||||
// Close the window
|
// Close the window
|
||||||
this.Close();
|
Close();
|
||||||
|
|
||||||
// Exit the application
|
// Exit the application
|
||||||
Application.Current.Exit();
|
Application.Current.Exit();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user