public bool SetHotkeyCombination(HotKeys hotkeys, AudioDeviceType deviceType) { using (AppLogger.Log.InfoCall()) { HotKeys confHotKeys = null; switch (deviceType) { case AudioDeviceType.Playback: confHotKeys = AppConfigs.Configuration.PlaybackHotKeys; break; case AudioDeviceType.Recording: confHotKeys = AppConfigs.Configuration.RecordingHotKeys; break; default: throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null); } using (AppLogger.Log.InfoCall()) { AppLogger.Log.Info("Unregister previous hotkeys", confHotKeys); WindowsAPIAdapter.UnRegisterHotKey(confHotKeys); AppLogger.Log.Info("Unregistered previous hotkeys", confHotKeys); if (hotkeys.Enabled && !WindowsAPIAdapter.RegisterHotKey(hotkeys)) { AppLogger.Log.Warn("Can't register new hotkeys", hotkeys); ErrorTriggered?.Invoke(this, new ExceptionEvent(new Exception("Impossible to register HotKey: " + hotkeys))); return(false); } AppLogger.Log.Info("New Hotkeys registered", hotkeys); } switch (deviceType) { case AudioDeviceType.Playback: AppConfigs.Configuration.PlaybackHotKeys = hotkeys; break; case AudioDeviceType.Recording: AppConfigs.Configuration.RecordingHotKeys = hotkeys; break; default: throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null); } AppConfigs.Configuration.Save(); return(true); } }
/// <summary> /// Initialize the profile manager. Return the list of Profile that it couldn't register hotkeys for. /// </summary> /// <returns></returns> public Result <ProfileSetting[], VoidSuccess> Init() { RegisterEvents(); var errors = AppConfigs.Configuration.ProfileSettings .Where(setting => setting.HotKey != null) .Where(profileSetting => !WindowsAPIAdapter.RegisterHotKey(profileSetting.HotKey)) .ToArray(); if (errors.Length > 0) { return(errors); } return(Result.Success()); }
private Result <string, VoidSuccess> ValidateAddProfile(ProfileSetting profile) { if (string.IsNullOrEmpty(profile.ProfileName)) { return(SettingsStrings.profile_error_no_name); } if (string.IsNullOrEmpty(profile.ApplicationPath) && profile.HotKey == null) { return(SettingsStrings.profile_error_needHKOrPath); } if (profile.Recording == null && profile.Playback == null) { return(SettingsStrings.profile_error_needPlaybackOrRecording); } if (profile.HotKey != null && _profileByHotkey.ContainsKey(profile.HotKey)) { return(string.Format(SettingsStrings.profile_error_hotkey, profile.HotKey)); } if (!string.IsNullOrEmpty(profile.ApplicationPath) && _profileByApplication.ContainsKey(profile.ApplicationPath.ToLower())) { return(string.Format(SettingsStrings.profile_error_application, profile.ApplicationPath)); } if (AppConfigs.Configuration.ProfileSettings.Contains(profile)) { return(string.Format(SettingsStrings.profile_error_name, profile.ProfileName)); } if (profile.HotKey != null && !WindowsAPIAdapter.RegisterHotKey(profile.HotKey)) { return(string.Format(SettingsStrings.profile_error_hotkey, profile.HotKey)); } return(Result.Success()); }