From 723c4fb85e4b3708912414c3ccb9bd18c4b407a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=9D=E9=9B=B6?= <78294929+JiuLing-zhang@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:41:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Components/ShortcutKeySetting.razor | 4 +-- src/Components/ShortcutKeySetting.razor.cs | 32 +++++++++++----------- src/Configuration/AppBase.cs | 8 +++--- src/Models/ShortcutKeyModel.cs | 8 +++--- src/Pages/Index.razor.cs | 6 ++-- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Components/ShortcutKeySetting.razor b/src/Components/ShortcutKeySetting.razor index fb19579..6ee5c77 100644 --- a/src/Components/ShortcutKeySetting.razor +++ b/src/Components/ShortcutKeySetting.razor @@ -1,10 +1,10 @@  - @(_shortcutKeyText) + @(_text) @(Lang["Save"]) diff --git a/src/Components/ShortcutKeySetting.razor.cs b/src/Components/ShortcutKeySetting.razor.cs index 36429be..04cb391 100644 --- a/src/Components/ShortcutKeySetting.razor.cs +++ b/src/Components/ShortcutKeySetting.razor.cs @@ -8,9 +8,9 @@ public partial class ShortcutKeySetting [CascadingParameter] private MudDialogInstance MudDialog { get; set; } = default!; - private string _shortcutKeyText = default!; - private string _shortcutKey = ""; - private string _shortcutKeyDisplay = ""; + private string _text = default!; + private string _key = ""; + private string _displayText = ""; [Inject] private IStringLocalizer Lang { get; set; } = default!; @@ -18,18 +18,18 @@ public partial class ShortcutKeySetting protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - _shortcutKeyText = Lang["EnterShortcutKey"]; + _text = Lang["EnterShortcutKey"]; } private Task OnKeyDown(KeyboardEventArgs value) { - _shortcutKey = ""; + _key = ""; byte[] buffer = Encoding.ASCII.GetBytes(value.Key); if (buffer.Length != 1) { - _shortcutKeyText = Lang["EnterShortcutKey"]; - _shortcutKey = ""; + _text = Lang["EnterShortcutKey"]; + _key = ""; return Task.CompletedTask; } @@ -37,15 +37,15 @@ private Task OnKeyDown(KeyboardEventArgs value) if (value.CtrlKey) { - _shortcutKey = "Ctrl + "; + _key = "Ctrl + "; } if (value.ShiftKey) { - _shortcutKey += "Shift + "; + _key += "Shift + "; } if (value.AltKey) { - _shortcutKey += "Alt + "; + _key += "Alt + "; } if (ascii >= 97 && ascii <= 122) @@ -55,21 +55,21 @@ private Task OnKeyDown(KeyboardEventArgs value) if ((ascii >= 48 && ascii <= 57) || (ascii >= 65 && ascii <= 90)) { - _shortcutKeyDisplay = _shortcutKey + $"{value.Key}"; - _shortcutKeyText = _shortcutKeyDisplay; - _shortcutKey += $"{ascii}"; + _displayText = _key + $"{value.Key}"; + _text = _displayText; + _key += $"{ascii}"; } else { - _shortcutKeyText = Lang["EnterShortcutKey"]; - _shortcutKey = ""; + _text = Lang["EnterShortcutKey"]; + _key = ""; } return Task.CompletedTask; } private void Submit() { - MudDialog.Close(DialogResult.Ok(new ShortcutKeyModel(_shortcutKey, _shortcutKeyDisplay))); + MudDialog.Close(DialogResult.Ok(new ShortcutKey(_key, _displayText))); } private void Cancel() => MudDialog.Cancel(); } \ No newline at end of file diff --git a/src/Configuration/AppBase.cs b/src/Configuration/AppBase.cs index 8b876c7..67d6711 100644 --- a/src/Configuration/AppBase.cs +++ b/src/Configuration/AppBase.cs @@ -7,9 +7,9 @@ internal class AppBase /// /// App路径(包含文件名) /// - public static string ExecutablePath { get; set; } = Process.GetCurrentProcess().MainModule.FileName; + public static string ExecutablePath { get; } = Process.GetCurrentProcess().MainModule.FileName; - public static string FriendlyName { get; set; } = AppDomain.CurrentDomain.FriendlyName; + public static string FriendlyName { get; } = AppDomain.CurrentDomain.FriendlyName; /// /// App Data文件夹路径 @@ -18,7 +18,7 @@ internal class AppBase /// /// 配置文件路径 /// - public static string ConfigPath { get; set; } = Path.Combine(DataPath, FriendlyName, "config.json"); + public static string ConfigPath { get; } = Path.Combine(DataPath, FriendlyName, "config.json"); - public static string Version { get; set; } = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString(); + public static string Version { get; } = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString(); } \ No newline at end of file diff --git a/src/Models/ShortcutKeyModel.cs b/src/Models/ShortcutKeyModel.cs index 91649f7..3957dd3 100644 --- a/src/Models/ShortcutKeyModel.cs +++ b/src/Models/ShortcutKeyModel.cs @@ -1,6 +1,6 @@ namespace ComputerLock.Models; -internal class ShortcutKeyModel(string shortcutKey, string shortcutKeyDisplay) +internal class ShortcutKey(string key, string displayText) { - public string ShortcutKey { get; set; } = shortcutKey; - public string ShortcutKeyDisplay { get; set; } = shortcutKeyDisplay; -} \ No newline at end of file + public string Key { get; set; } = key; + public string DisplayText { get; set; } = displayText; +} diff --git a/src/Pages/Index.razor.cs b/src/Pages/Index.razor.cs index dfbd3e8..8f0e617 100644 --- a/src/Pages/Index.razor.cs +++ b/src/Pages/Index.razor.cs @@ -156,7 +156,7 @@ private async Task SetShortcutKey() return; } - if (result.Data is not ShortcutKeyModel shortcutKeyModel) + if (result.Data is not ShortcutKey shortcutKey) { return; } @@ -166,8 +166,8 @@ private async Task SetShortcutKey() { UnregisterHotKey(); } - AppSettings.ShortcutKeyForLock = shortcutKeyModel.ShortcutKey; - AppSettings.ShortcutKeyDisplayForLock = shortcutKeyModel.ShortcutKeyDisplay; + AppSettings.ShortcutKeyForLock = shortcutKey.Key; + AppSettings.ShortcutKeyDisplayForLock = shortcutKey.DisplayText; SaveSettings(); RegisterHotKey(); }