Exemple #1
0
        /// <summary>
        /// Loads keybindings from the configuration file and registers them with Windows.
        /// </summary>
        private void AssignHotkeys(HotkeyManager hotkeyManager)
        {
            try
            {
                foreach (var hotkey in ConfigManager.Config.Hotkeys ?? new HotkeyConfig[] {})
                {
                    var          keys = KeyCombination.Parse(hotkey.Hotkey);
                    HotkeyAction action;
                    try
                    {
                        // Reading the Action variable will cause it to be parsed from hotkey.ActionString.
                        // If this fails, an ArgumentException is thrown.
                        action = hotkey.Action;
                    }
                    catch (ArgumentException)
                    {
                        RaiseNotification($"Invalid hotkey configuration in config.yaml.\nThe action \"{hotkey.ActionString}\" is not known.", ToolTipIcon.Error);
                        continue;
                    }
                    switch (action)
                    {
                    case HotkeyAction.DecryptPassword:
                        hotkeyManager.AddHotKey(keys, () => DecryptPassword(hotkey.Options.CopyToClipboard, hotkey.Options.TypeUsername, hotkey.Options.TypePassword));
                        break;

                    case HotkeyAction.AddPassword:
                        hotkeyManager.AddHotKey(keys, AddPassword);
                        break;

                    case HotkeyAction.EditPassword:
                        hotkeyManager.AddHotKey(keys, EditPassword);
                        break;

                    case HotkeyAction.GitPull:
                        hotkeyManager.AddHotKey(keys, UpdatePasswordStore);
                        break;

                    case HotkeyAction.GitPush:
                        hotkeyManager.AddHotKey(keys, CommitChanges);
                        break;

                    case HotkeyAction.OpenShell:
                        hotkeyManager.AddHotKey(keys, OpenPasswordShell);
                        break;

                    case HotkeyAction.ShowDebugInfo:
                        hotkeyManager.AddHotKey(keys, ShowDebugInfo);
                        break;
                    }
                }
            }
            catch (Exception e) when(e is ArgumentException || e is HotkeyException)
            {
                RaiseNotification(e.Message, ToolTipIcon.Error);
                Exit();
            }
        }