Exemplo n.º 1
0
        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();
                }
            }
        }
Exemplo n.º 2
0
        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);
                }
            }
        }
Exemplo n.º 3
0
 private void DeleteProfile(string name)
 {
     ExecuteUiAction(() =>
     {
         SettingsFiles.ApplicationSettings.SetHotkey(name, Keys.None);
         SettingsFiles.SaveApplicationSettings();
         ProfileFiles.DeleteProfile(name);
     }, "Could not delete display profile " + name);
 }
Exemplo n.º 4
0
 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));
 }