static void Main(string[] args) { bool firstApplicationInstance; using (var mre = new EventWaitHandle(false, EventResetMode.ManualReset, ApplicationId, out firstApplicationInstance)) { if (args.Length == 0 || args[0] == "installed") { if (!firstApplicationInstance) { return; } Task.Run(() => { mre.WaitOne(); Application.Exit(); }); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Profile.JsonSerializerSettings.TypeNameHandling = TypeNameHandling.Auto; SettingsFiles.EnsureCreated(); using (new MainForm(args.Length != 0 && args[0] == "installed")) Application.Run(); } else if (args[0] == "exit") { mre.Set(); } } }
private void RefreshHotkeys() { // Unregister all hotkeys. foreach (var hotkey in _hotkeys) { hotkey.Dispose(); } _hotkeys.Clear(); // Remove any hotkeys for profiles that no longer exist (but keep hotkeys for system commands). if (SettingsFiles.ApplicationSettings.Hotkeys.RemoveAll(x => !SystemCommands.IsSystemCommand(x.Id) && !_profiles.ContainsKey(x.Id)) != 0) { SettingsFiles.SaveApplicationSettings(); } // Register hotkeys. foreach (var hotkeySetting in SettingsFiles.ApplicationSettings.Hotkeys) { var id = hotkeySetting.Id; try { _hotkeys.Add(new WinFormsHotkey(hotkeySetting.Hotkey, true, () => ExecuteSystemCommandOrLoadProfile(hotkeySetting.Id))); } catch (Exception ex) { BalloonTip("Could not bind hotkey " + WinFormsHotkey.HotkeyString(hotkeySetting.Hotkey) + " to " + SystemCommands.GetTitle(id), ex.Message, ToolTipIcon.Warning); } } }
private void DeleteProfile(string name) { ExecuteUiAction(() => { SettingsFiles.ApplicationSettings.SetHotkey(name, Keys.None); SettingsFiles.SaveApplicationSettings(); ProfileFiles.DeleteProfile(name); }, "Could not delete display profile " + name); }
private void SetHotkey(string id) { ExecuteUiAction(() => { var result = SetHotkeyDialog.ExecuteDialog(SystemCommands.GetTitle(id), SettingsFiles.ApplicationSettings.FindHotkey(id)); if (result == null) { return; } SettingsFiles.ApplicationSettings.SetHotkey(id, result.Value); SettingsFiles.SaveApplicationSettings(); }, "Could not set hotkey for " + SystemCommands.GetTitle(id)); }