mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 18:47:55 +08:00
fix: 尝试修复更新重启后热键失效
This commit is contained in:
@@ -221,6 +221,7 @@ namespace MaaWpfGui.Main
|
||||
// MessageBox.Show("O(∩_∩)O 拜拜");
|
||||
ETagCache.Save();
|
||||
Instances.SettingsViewModel.Sober();
|
||||
Instances.MaaHotKeyManager.Release();
|
||||
|
||||
// 关闭程序时清理操作中心中的通知
|
||||
// 使用 handyorg 的 ShowBalloonTip,不需要清理
|
||||
|
||||
@@ -20,5 +20,7 @@ namespace MaaWpfGui.Services.HotKeys
|
||||
void UnRegister(MaaHotKeyAction action);
|
||||
|
||||
MaaHotKey GetOrNull(MaaHotKeyAction action);
|
||||
|
||||
void Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ namespace MaaWpfGui.Services.HotKeys
|
||||
{
|
||||
public class MaaHotKeyManager : IMaaHotKeyManager
|
||||
{
|
||||
private readonly Dictionary<MaaHotKeyAction, MaaHotKey> _actionHotKeyMapping =
|
||||
new Dictionary<MaaHotKeyAction, MaaHotKey>();
|
||||
private readonly Dictionary<MaaHotKeyAction, MaaHotKey> _actionHotKeyMapping = new();
|
||||
|
||||
private const string HotKeyConfigName = "HotKeys";
|
||||
|
||||
@@ -84,20 +83,28 @@ namespace MaaWpfGui.Services.HotKeys
|
||||
}
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
foreach (var kvPair in _actionHotKeyMapping)
|
||||
{
|
||||
InternalUnRegister(kvPair.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private void InternalUnRegister(MaaHotKeyAction action)
|
||||
{
|
||||
if (!_actionHotKeyMapping.ContainsKey(action) || _actionHotKeyMapping[action] == null)
|
||||
if (!_actionHotKeyMapping.TryGetValue(action, out var value) || value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Instances.HotKeyManager.Unregister(_actionHotKeyMapping[action]);
|
||||
Instances.HotKeyManager.Unregister(value);
|
||||
_actionHotKeyMapping[action] = null;
|
||||
}
|
||||
|
||||
public MaaHotKey GetOrNull(MaaHotKeyAction action)
|
||||
{
|
||||
return _actionHotKeyMapping.TryGetValue(action, out var value) ? value : null;
|
||||
return _actionHotKeyMapping.GetValueOrDefault(action);
|
||||
}
|
||||
|
||||
private void HotKeyManagerPressed(object sender, KeyPressedEventArgs e)
|
||||
@@ -120,12 +127,10 @@ namespace MaaWpfGui.Services.HotKeys
|
||||
var hotKeys = new Dictionary<MaaHotKeyAction, MaaHotKey>
|
||||
{
|
||||
{
|
||||
MaaHotKeyAction.ShowGui,
|
||||
new MaaHotKey(Key.M, ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)
|
||||
MaaHotKeyAction.ShowGui, new MaaHotKey(Key.M, ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)
|
||||
},
|
||||
{
|
||||
MaaHotKeyAction.LinkStart,
|
||||
new MaaHotKey(Key.L, ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)
|
||||
MaaHotKeyAction.LinkStart, new MaaHotKey(Key.L, ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt)
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,11 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
/// <inheritdoc/>
|
||||
protected override void OnViewLoaded()
|
||||
{
|
||||
CheckAndUpdateNow();
|
||||
if (CheckAndUpdateNow())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
InitViewModels();
|
||||
InitProxy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user