mirror of https://github.com/2dust/v2rayN
code cleanup
parent
a883ba8808
commit
4ff1dc2982
|
@ -26,7 +26,7 @@ namespace v2rayN.Handler
|
||||||
public event Action<EGlobalHotkey>? HotkeyTriggerEvent;
|
public event Action<EGlobalHotkey>? HotkeyTriggerEvent;
|
||||||
public HotkeyHandler()
|
public HotkeyHandler()
|
||||||
{
|
{
|
||||||
_hotkeyTriggerDic = new();
|
_hotkeyTriggerDic = new();
|
||||||
ComponentDispatcher.ThreadPreprocessMessage += OnThreadPreProcessMessage;
|
ComponentDispatcher.ThreadPreprocessMessage += OnThreadPreProcessMessage;
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
_hotkeyTriggerDic.Clear();
|
_hotkeyTriggerDic.Clear();
|
||||||
if (_config.globalHotkeys == null) return;
|
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)
|
if (item.KeyCode != null && item.KeyCode != Key.None)
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@ namespace v2rayN.Handler
|
||||||
key = (key << 16) | (int)modifiers;
|
key = (key << 16) | (int)modifiers;
|
||||||
if (!_hotkeyTriggerDic.ContainsKey(key))
|
if (!_hotkeyTriggerDic.ContainsKey(key))
|
||||||
{
|
{
|
||||||
_hotkeyTriggerDic.Add(key, new() { item.eGlobalHotkey });
|
_hotkeyTriggerDic.Add(key, new() { item.eGlobalHotkey });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -59,7 +59,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
public void Load()
|
public void Load()
|
||||||
{
|
{
|
||||||
foreach(var _hotkeyCode in _hotkeyTriggerDic.Keys)
|
foreach (var _hotkeyCode in _hotkeyTriggerDic.Keys)
|
||||||
{
|
{
|
||||||
var hotkeyInfo = GetHotkeyInfo(_hotkeyCode);
|
var hotkeyInfo = GetHotkeyInfo(_hotkeyCode);
|
||||||
bool isSuccess = false;
|
bool isSuccess = false;
|
||||||
|
@ -67,7 +67,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
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)
|
foreach (var name in hotkeyInfo.Names)
|
||||||
{
|
{
|
||||||
|
@ -82,13 +82,13 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
UpdateViewEvent?.Invoke(false, msg);
|
UpdateViewEvent?.Invoke(false, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReLoad()
|
public void ReLoad()
|
||||||
{
|
{
|
||||||
foreach(var hotkey in _hotkeyTriggerDic.Keys)
|
foreach (var hotkey in _hotkeyTriggerDic.Keys)
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
@ -122,8 +122,8 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
private void OnThreadPreProcessMessage(ref MSG msg, ref bool handled)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
handled = true;
|
handled = true;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using v2rayN.Mode;
|
using v2rayN.Mode;
|
||||||
using v2rayN.Resx;
|
using v2rayN.Resx;
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using Microsoft.Win32.TaskScheduler;
|
using System.Text;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
@ -21,7 +19,7 @@ namespace v2rayN.Views
|
||||||
this.Owner = Application.Current.MainWindow;
|
this.Owner = Application.Current.MainWindow;
|
||||||
_config = LazyConfig.Instance.GetConfig();
|
_config = LazyConfig.Instance.GetConfig();
|
||||||
_config.globalHotkeys ??= new List<KeyEventItem>();
|
_config.globalHotkeys ??= new List<KeyEventItem>();
|
||||||
|
|
||||||
txtGlobalHotkey0.KeyDown += TxtGlobalHotkey_KeyDown;
|
txtGlobalHotkey0.KeyDown += TxtGlobalHotkey_KeyDown;
|
||||||
txtGlobalHotkey1.KeyDown += TxtGlobalHotkey_KeyDown;
|
txtGlobalHotkey1.KeyDown += TxtGlobalHotkey_KeyDown;
|
||||||
txtGlobalHotkey2.KeyDown += TxtGlobalHotkey_KeyDown;
|
txtGlobalHotkey2.KeyDown += TxtGlobalHotkey_KeyDown;
|
||||||
|
@ -29,7 +27,7 @@ namespace v2rayN.Views
|
||||||
txtGlobalHotkey4.KeyDown += TxtGlobalHotkey_KeyDown;
|
txtGlobalHotkey4.KeyDown += TxtGlobalHotkey_KeyDown;
|
||||||
|
|
||||||
HotkeyHandler.Instance.IsPause = true;
|
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);
|
Utils.SetDarkBorder(this, _config.uiItem.colorModeDark);
|
||||||
InitData();
|
InitData();
|
||||||
}
|
}
|
||||||
|
@ -60,7 +58,7 @@ namespace v2rayN.Views
|
||||||
(sender as TextBox)!.Text = KeyEventItemToString(_TextBoxKeyEventItem[sender]);
|
(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()
|
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.Control) res.Append($"{ModifierKeys.Control}+");
|
||||||
if (item.Shift) res.Append($"{ModifierKeys.Shift}+");
|
if (item.Shift) res.Append($"{ModifierKeys.Shift}+");
|
||||||
if (item.Alt) res.Append($"{ModifierKeys.Alt}+");
|
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}");
|
res.Append($"{item.KeyCode}");
|
||||||
|
|
||||||
return res.ToString();
|
return res.ToString();
|
||||||
}
|
}
|
||||||
private void BindingData()
|
private void BindingData()
|
||||||
{
|
{
|
||||||
foreach(var item in _TextBoxKeyEventItem)
|
foreach (var item in _TextBoxKeyEventItem)
|
||||||
{
|
{
|
||||||
if (item.Value.KeyCode != null && item.Value.KeyCode != Key.None)
|
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)
|
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].Alt = false;
|
||||||
_TextBoxKeyEventItem[k].Control= false;
|
_TextBoxKeyEventItem[k].Control = false;
|
||||||
_TextBoxKeyEventItem[k].Shift = false;
|
_TextBoxKeyEventItem[k].Shift = false;
|
||||||
_TextBoxKeyEventItem[k].KeyCode = Key.None;
|
_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.OneWayBind(ViewModel, vm => vm.Servers, v => v.cmbServers.ItemsSource).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SelectedServer, v => v.cmbServers.SelectedItem).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
|
//tray menu
|
||||||
this.BindCommand(ViewModel, vm => vm.AddServerViaClipboardCmd, v => v.menuAddServerViaClipboard2).DisposeWith(disposables);
|
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)}";
|
this.Title = $"{Utils.GetVersion()} - {(IsAdministrator ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}";
|
||||||
|
|
||||||
spEnableTun.Visibility = IsAdministrator ? Visibility.Visible : Visibility.Collapsed;
|
spEnableTun.Visibility = IsAdministrator ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
|
||||||
if (_config.uiItem.autoHideStartup)
|
if (_config.uiItem.autoHideStartup)
|
||||||
{
|
{
|
||||||
WindowState = WindowState.Minimized;
|
WindowState = WindowState.Minimized;
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
FontSize="{DynamicResource StdFontSizeMsg}"
|
FontSize="{DynamicResource StdFontSizeMsg}"
|
||||||
HorizontalScrollBarVisibility="Auto"
|
HorizontalScrollBarVisibility="Auto"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
|
IsReadOnlyCaretVisible="True"
|
||||||
TextAlignment="Left"
|
TextAlignment="Left"
|
||||||
TextWrapping="Wrap"
|
TextWrapping="Wrap"
|
||||||
VerticalScrollBarVisibility="Visible">
|
VerticalScrollBarVisibility="Visible">
|
||||||
|
|
Loading…
Reference in New Issue