/// <summary> /// Perform tasks at application exit. /// </summary> private void Application_Exit(object sender, ExitEventArgs e) { // Ignore exit process on elevated request... if (mElevatedRestart) { return; } // All application windows are already closed here. #region Dispose Here // Dispose Application. IoC.Application.Dispose(); // Dispose tray icon. WindowViewModel.DisposeTrayIcon(); // Clean log files. IoC.Logger.CleanLogFiles(); // Dispose IoC modules IoC.Web.Dispose(); IoC.Get <IMouseKeyHook>().Dispose(); // "Prepare data to die." IoC.DataContent.Unset(); #endregion }
/// <summary> /// Close MainWindow to Windows tray. /// </summary> public void CloseMainWindowToTray() { // Create notification tray icon. System.Windows.Forms.NotifyIcon trayIcon = new System.Windows.Forms.NotifyIcon(); trayIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon("Resources/Images/Logo/icon_white.ico"); trayIcon.DoubleClick += (s, args) => ShowMainWindow(); trayIcon.Visible = true; // Create context menu for the notification icon. trayIcon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(); trayIcon.ContextMenuStrip.Items.Add("Open Application").Click += (s, e) => ShowMainWindow(); trayIcon.ContextMenuStrip.Items.Add("Donate").Click += (s, e) => System.Diagnostics.Process.Start(IoC.Application.DonationURL); trayIcon.ContextMenuStrip.Items.Add("-"); trayIcon.ContextMenuStrip.Items.Add("Quit").Click += (s, e) => IoC.Application.Exit(); // Try to dispose previous ion if exists. WindowViewModel.DisposeTrayIcon(); // Assign tray icon. WindowViewModel.TrayIcon = trayIcon; // Hide MainWindow. Application.Current.MainWindow.Hide(); // A hidden window can be shown again, a closed one not. }
/// <summary> /// Show MainWindow. /// </summary> public void ShowMainWindow() { // Activate window if it is visible in background. if (Application.Current.MainWindow.IsVisible) { if (Application.Current.MainWindow.WindowState == WindowState.Minimized) { Application.Current.MainWindow.WindowState = WindowState.Normal; } } // Open window if it is closed in tray. else { Application.Current.MainWindow.Show(); WindowViewModel.DisposeTrayIcon(); } // Activate window. Application.Current.MainWindow.Activate(); // Try to bring focus to the window. Application.Current.MainWindow.Focus(); }