private void ExitApplication() { _isExit = true; mainwindow.Close(); _notifyIcon.Dispose(); _notifyIcon = null; Settings_.Save(mainwindow.config, SettingsFolderPath); }
private void MainWindow_Closing(object sender, CancelEventArgs e) { if (!_isExit) { e.Cancel = true; mainwindow.Hide(); Settings_.Save(mainwindow.config, SettingsFolderPath); } }
protected override async void OnStartup(StartupEventArgs e) { base.OnStartup(e); if (!singleton.WaitOne(TimeSpan.Zero, true)) { Application.Current.Shutdown(); } mainwindow.Closing += MainWindow_Closing; try { if (Directory.Exists(SettingsFolderPath)) { mainwindow.config = Settings_.Load(SettingsFolderPath); } else { Directory.CreateDirectory(SettingsFolderPath); } } catch { } #if !DEBUG using (var mgr = new UpdateManager("https://mbinary.pl/public/squirrel/lockmicrophonelevel/")) { SquirrelAwareApp.HandleEvents( onInitialInstall: v => { mgr.CreateShortcutForThisExe(); mgr.CreateRunAtWindowsStartupRegistry(); }, onAppUninstall: v => { mgr.RemoveShortcutForThisExe(); mgr.RemoveRunAtWindowsStartupRegistry(); }); try { var updateInfo = await mgr.CheckForUpdate(); if (updateInfo.ReleasesToApply.Any()) { updatewindow.Show(); await mgr.UpdateApp(); await Task.Delay(1500); updatewindow.Close(); System.Diagnostics.Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"/LockMicrophoneLevel/LockMicrophoneLevel.exe"); await Task.Delay(100); Environment.Exit(0); } else { CreateApplicationNotifyIcon(); } } catch { var result = MessageBox.Show("There was an error while updating app, would you like to start it in offline mode?", "App Update", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { CreateApplicationNotifyIcon(); } else { Environment.Exit(0); } } } #else CreateApplicationNotifyIcon(); #endif }