code cleanup

pull/3492/head^2
2dust 2 years ago
parent a883ba8808
commit 4ff1dc2982

@ -26,7 +26,7 @@ namespace v2rayN.Handler
public event Action<EGlobalHotkey>? HotkeyTriggerEvent;
public HotkeyHandler()
{
_hotkeyTriggerDic = new();
_hotkeyTriggerDic = new();
ComponentDispatcher.ThreadPreprocessMessage += OnThreadPreProcessMessage;
Init();
}
@ -35,7 +35,7 @@ namespace v2rayN.Handler
{
_hotkeyTriggerDic.Clear();
if (_config.globalHotkeys == null) return;
foreach(var item in _config.globalHotkeys)
foreach (var item in _config.globalHotkeys)
{
if (item.KeyCode != null && item.KeyCode != Key.None)
{
@ -47,7 +47,7 @@ namespace v2rayN.Handler
key = (key << 16) | (int)modifiers;
if (!_hotkeyTriggerDic.ContainsKey(key))
{
_hotkeyTriggerDic.Add(key, new() { item.eGlobalHotkey });
_hotkeyTriggerDic.Add(key, new() { item.eGlobalHotkey });
}
else
{
@ -59,7 +59,7 @@ namespace v2rayN.Handler
}
public void Load()
{
foreach(var _hotkeyCode in _hotkeyTriggerDic.Keys)
foreach (var _hotkeyCode in _hotkeyTriggerDic.Keys)
{
var hotkeyInfo = GetHotkeyInfo(_hotkeyCode);
bool isSuccess = false;
@ -67,7 +67,7 @@ namespace v2rayN.Handler
Application.Current.Dispatcher.Invoke(() =>
{
isSuccess = RegisterHotKey(IntPtr.Zero, _hotkeyCode, hotkeyInfo.fsModifiers, hotkeyInfo.vKey);
isSuccess = RegisterHotKey(IntPtr.Zero, _hotkeyCode, hotkeyInfo.fsModifiers, hotkeyInfo.vKey);
});
foreach (var name in hotkeyInfo.Names)
{
@ -82,13 +82,13 @@ namespace v2rayN.Handler
}
UpdateViewEvent?.Invoke(false, msg);
}
}
}
public void ReLoad()
{
foreach(var hotkey in _hotkeyTriggerDic.Keys)
foreach (var hotkey in _hotkeyTriggerDic.Keys)
{
Application.Current.Dispatcher.Invoke(() =>
{
@ -122,8 +122,8 @@ namespace v2rayN.Handler
}
private void OnThreadPreProcessMessage(ref MSG msg, ref bool handled)
{
if (msg.message != WmHotkey|| !_hotkeyTriggerDic.ContainsKey((int)msg.lParam))
{
if (msg.message != WmHotkey || !_hotkeyTriggerDic.ContainsKey((int)msg.lParam))
{
return;
}
handled = true;

@ -2,7 +2,6 @@
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using v2rayN.Mode;
using v2rayN.Resx;

@ -1,6 +1,4 @@
using Microsoft.Win32.TaskScheduler;
using System.Diagnostics;
using System.Text;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@ -21,7 +19,7 @@ namespace v2rayN.Views
this.Owner = Application.Current.MainWindow;
_config = LazyConfig.Instance.GetConfig();
_config.globalHotkeys ??= new List<KeyEventItem>();
txtGlobalHotkey0.KeyDown += TxtGlobalHotkey_KeyDown;
txtGlobalHotkey1.KeyDown += TxtGlobalHotkey_KeyDown;
txtGlobalHotkey2.KeyDown += TxtGlobalHotkey_KeyDown;
@ -29,7 +27,7 @@ namespace v2rayN.Views
txtGlobalHotkey4.KeyDown += TxtGlobalHotkey_KeyDown;
HotkeyHandler.Instance.IsPause = true;
this.Closing += (s, e) => HotkeyHandler.Instance.IsPause = false;
this.Closing += (s, e) => HotkeyHandler.Instance.IsPause = false;
Utils.SetDarkBorder(this, _config.uiItem.colorModeDark);
InitData();
}
@ -60,7 +58,7 @@ namespace v2rayN.Views
(sender as TextBox)!.Text = KeyEventItemToString(_TextBoxKeyEventItem[sender]);
}
private KeyEventItem GetKeyEventItemByEGlobalHotkey(List<KeyEventItem> KELsit,EGlobalHotkey eg)
private KeyEventItem GetKeyEventItemByEGlobalHotkey(List<KeyEventItem> KELsit, EGlobalHotkey eg)
{
return Utils.DeepCopy(KELsit.Find((it) => it.eGlobalHotkey == eg) ?? new()
{
@ -79,14 +77,14 @@ namespace v2rayN.Views
if (item.Control) res.Append($"{ModifierKeys.Control}+");
if (item.Shift) res.Append($"{ModifierKeys.Shift}+");
if (item.Alt) res.Append($"{ModifierKeys.Alt}+");
if(item.KeyCode != null && item.KeyCode != Key.None)
if (item.KeyCode != null && item.KeyCode != Key.None)
res.Append($"{item.KeyCode}");
return res.ToString();
}
private void BindingData()
{
foreach(var item in _TextBoxKeyEventItem)
foreach (var item in _TextBoxKeyEventItem)
{
if (item.Value.KeyCode != null && item.Value.KeyCode != Key.None)
{
@ -121,10 +119,10 @@ namespace v2rayN.Views
private void btnReset_Click(object sender, RoutedEventArgs e)
{
foreach(var k in _TextBoxKeyEventItem.Keys)
foreach (var k in _TextBoxKeyEventItem.Keys)
{
_TextBoxKeyEventItem[k].Alt = false;
_TextBoxKeyEventItem[k].Control= false;
_TextBoxKeyEventItem[k].Control = false;
_TextBoxKeyEventItem[k].Shift = false;
_TextBoxKeyEventItem[k].KeyCode = Key.None;
}

@ -150,7 +150,7 @@ namespace v2rayN.Views
this.OneWayBind(ViewModel, vm => vm.Servers, v => v.cmbServers.ItemsSource).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedServer, v => v.cmbServers.SelectedItem).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.BlServers, v => v.cmbServers.Visibility).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.BlServers, v => v.cmbServers.Visibility).DisposeWith(disposables);
//tray menu
this.BindCommand(ViewModel, vm => vm.AddServerViaClipboardCmd, v => v.menuAddServerViaClipboard2).DisposeWith(disposables);
@ -192,7 +192,7 @@ namespace v2rayN.Views
this.Title = $"{Utils.GetVersion()} - {(IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
spEnableTun.Visibility = IsAdministrator ? Visibility.Visible : Visibility.Collapsed;
if (_config.uiItem.autoHideStartup)
{
WindowState = WindowState.Minimized;

@ -48,6 +48,7 @@
FontSize="{DynamicResource StdFontSizeMsg}"
HorizontalScrollBarVisibility="Auto"
IsReadOnly="True"
IsReadOnlyCaretVisible="True"
TextAlignment="Left"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Visible">

Loading…
Cancel
Save