mirror of
https://github.com/2dust/v2rayN.git
synced 2026-09-22 22:38:10 +03:00
* Interaction * Remove view action * ViewModel-first * MainGirdOrientation Hot Reload * Fix avalonia preview * Remove CloseWindowInteraction * Fix * Avoid threading issues * Fix * ProfilesSelect * Try fix previewer * Remove AppEvents.ProfilesRefreshRequested * Remove AppEvents.SubscriptionsRefreshRequested * Remove AppEvents.ProxiesReloadRequested * Remove AppEvents.AdjustMainLvColWidthRequested * Remove AppEvents.SetDefaultServerRequested * Remove AppEvents.RoutingsMenuRefreshRequested * Remove AppEvents.TestServerRequested * Remove AppEvents.InboundDisplayRequested * Remove AppEvents.SubscriptionsUpdateRequested * Remove AppEvents.ShowHideWindowRequested * Remove AppEvents.ReloadRequested * Remove AppEvents.AddServerRequested * Fix
63 lines
1.4 KiB
C#
63 lines
1.4 KiB
C#
namespace ServiceLib.ViewModels;
|
|
|
|
public class GlobalHotkeySettingViewModel : MyReactiveObject, ICloseable
|
|
{
|
|
public event EventHandler? RequestClose;
|
|
|
|
private readonly List<KeyEventItem> _globalHotkeys;
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
|
|
|
|
public GlobalHotkeySettingViewModel()
|
|
{
|
|
_config = AppManager.Instance.Config;
|
|
|
|
_globalHotkeys = JsonUtils.DeepCopy(_config.GlobalHotkeys);
|
|
|
|
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
|
|
{
|
|
await SaveSettingAsync();
|
|
});
|
|
}
|
|
|
|
public KeyEventItem GetKeyEventItem(EGlobalHotkey eg)
|
|
{
|
|
var item = _globalHotkeys.FirstOrDefault((it) => it.EGlobalHotkey == eg);
|
|
if (item != null)
|
|
{
|
|
return item;
|
|
}
|
|
|
|
item = new()
|
|
{
|
|
EGlobalHotkey = eg,
|
|
Control = false,
|
|
Alt = false,
|
|
Shift = false,
|
|
KeyCode = null
|
|
};
|
|
_globalHotkeys.Add(item);
|
|
|
|
return item;
|
|
}
|
|
|
|
public void ResetKeyEventItem()
|
|
{
|
|
_globalHotkeys.Clear();
|
|
}
|
|
|
|
private async Task SaveSettingAsync()
|
|
{
|
|
_config.GlobalHotkeys = _globalHotkeys;
|
|
|
|
if (await ConfigHandler.SaveConfig(_config) == 0)
|
|
{
|
|
RequestClose?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
else
|
|
{
|
|
NoticeManager.Instance.Enqueue(ResUI.OperationFailed);
|
|
}
|
|
}
|
|
}
|