Skip to content

Commit

Permalink
优化命名
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuLing-zhang committed Sep 24, 2024
1 parent b1a5eb2 commit 723c4fb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/Components/ShortcutKeySetting.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<MudDialog DefaultFocus="DefaultFocus.FirstChild">
<DialogContent>
<MudButton Variant="Variant.Text" @onkeydown="OnKeyDown">@(_shortcutKeyText)</MudButton>
<MudButton Variant="Variant.Text" @onkeydown="OnKeyDown">@(_text)</MudButton>
</DialogContent>
<DialogActions>
<MudButton Color="Color.Primary"
Disabled="@(_shortcutKey.IsEmpty())"
Disabled="@(_key.IsEmpty())"
OnClick="Submit">
@(Lang["Save"])
</MudButton>
Expand Down
32 changes: 16 additions & 16 deletions src/Components/ShortcutKeySetting.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@ 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> Lang { get; set; } = default!;

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;
}

var ascii = buffer[0];

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)
Expand All @@ -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();
}
8 changes: 4 additions & 4 deletions src/Configuration/AppBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ internal class AppBase
/// <summary>
/// App路径(包含文件名)
/// </summary>
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;

/// <summary>
/// App Data文件夹路径
Expand All @@ -18,7 +18,7 @@ internal class AppBase
/// <summary>
/// 配置文件路径
/// </summary>
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();
}
8 changes: 4 additions & 4 deletions src/Models/ShortcutKeyModel.cs
Original file line number Diff line number Diff line change
@@ -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;
}
public string Key { get; set; } = key;
public string DisplayText { get; set; } = displayText;
}
6 changes: 3 additions & 3 deletions src/Pages/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private async Task SetShortcutKey()
return;
}

if (result.Data is not ShortcutKeyModel shortcutKeyModel)
if (result.Data is not ShortcutKey shortcutKey)
{
return;
}
Expand All @@ -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();
}
Expand Down

0 comments on commit 723c4fb

Please sign in to comment.