protected override void OnExit(ExitEventArgs e) { // Stop Registry Monitoring NightLightWatcher.Stop(); ThemeWatcher.Stop(); // Save Configuration File var settingService = Container.Resolve <SettingService>(); Task.WaitAll(settingService.SaveConfigFile()); // Disable Tray Tray.Visible = false; // Continue App Termination base.OnExit(e); }
protected override async void OnStartup(StartupEventArgs e) { // Preparation PrepIcon(); Tray = new NotifyIcon(); Tray.Visible = true; Tray.Text = "Windows 10 Night Light Theme Synchronization"; Tray.ContextMenuStrip = new ContextMenuStrip(); Tray.ContextMenuStrip.Items.Add("&Setting", null, TrayClickSetting); Tray.ContextMenuStrip.Items.Add("E&xit", null, TrayClickExit); // Load Configuration File _settingService = Container.Resolve <SettingService>(); await _settingService.OpenConfigFile(); // Background Services // -> Monitoring Service ThemeWatcher.Start(); NightLightWatcher.Start(); NightLightWatcher.WatchingStatusChanged += NightLightWatcher_WatchingStatusChanged; // -> Theme Service : Just constructs it as it will sync theme automatically var themeService = Container.Resolve <ThemeService>(); ThemeWatcher.SystemThemeChanged += ThemeWatcher_SystemThemeChanged; // Tray Event Tray.MouseClick += _tray_MouseClick; SetTrayIcon(ThemeWatcher.SystemTheme); // Activate Window If StartMinimized is not enabled if (!_settingService.CurrentSetting.StartMinimized) { StartMainWindow(); } else { Tray.ShowBalloonTip(5000, "The app is started.", "It has been minimized to system tray.", ToolTipIcon.Info); } // Prevent default startup behavior //base.OnStartup(e); }