public void OnHotkeyCaptured(object sender, GlobalHotkey.HotkeyCapturedEventArgs e) { if (e.Available) { _globalHotkey.RemoveHotkey(Hotkey); Hotkey = e.Hotkey; var message = _translater.GetTranslation("succeed"); App.API.ShowMsg(message, iconPath: Constant.AppIcon); } else { var message = _translater.GetTranslation("hotkeyUnavailable"); App.API.ShowMsg(message, iconPath: Constant.ErrorIcon); } }
private void SetHotkeys() { SetWoxHotkey(); SetCustomHotkeys(); _settingVM.HotkeyViewModel.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(HotkeyViewModel.Hotkey)) { _globalHotkey.SetHotkey(_settingVM.HotkeyViewModel.Hotkey, OnWoxHotkey); } }; foreach (var vm in _settingVM.CustomHotkeyViewModels) { vm.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(CustomHotkeyViewModel.CustomHotkey)) { var k = vm.CustomHotkey; _globalHotkey.SetHotkey(k.Hotkey, () => { OnCustomHotkey(k); }); } }; } _settingVM.CustomHotkeyViewModels.CollectionChanged += (_, ce) => { if (ce.Action == NotifyCollectionChangedAction.Add) { var vm = (CustomHotkeyViewModel)ce.NewItems[0]; vm.PropertyChanged += (__, pe) => { if (pe.PropertyName == nameof(CustomHotkeyViewModel.CustomHotkey)) { var k = vm.CustomHotkey; _globalHotkey.SetHotkey(k.Hotkey, () => { OnCustomHotkey(k); }); } }; } else if (ce.Action == NotifyCollectionChangedAction.Remove) { var vm = (CustomHotkeyViewModel)ce.OldItems[0]; var k = vm.CustomHotkey; _globalHotkey.RemoveHotkey(k.Hotkey); } }; }