Skip to content

Commit 1ad19d8

Browse files
committed
请先解锁的提示语支持自定义
1 parent dfc12e8 commit 1ad19d8

File tree

7 files changed

+94
-6
lines changed

7 files changed

+94
-6
lines changed

src/ComputerLock/Components/Settings/LockSettings.razor

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,34 @@
120120
Color="Color.Primary"
121121
Class="no-left-padding max-width-fix"
122122
Dense="true" />
123-
<MudText Typo="Typo.caption" Class="input-tip ml-7">
124-
@(Lang["LockTipsRemark"])
125-
</MudText>
123+
<MudCollapse Expanded="@(AppSettings.LockTips)">
124+
<MudStack Row="true" AlignItems="AlignItems.Start" Class="ml-7">
125+
<MudTextFieldExtended T="string"
126+
@ref="_textTipsMessageRef"
127+
@bind-Value="@(LockTipsMessage)"
128+
Disabled="@(!_lockTipsMessageEdit)"
129+
OnBlur="TipsMessageBlur"
130+
OnKeyDown="TipsMessageKeyDown"
131+
Immediate="true"
132+
Label=""
133+
Variant="Variant.Text"
134+
Margin="Margin.Dense"
135+
HelperText="@(Lang["LockTipsRemark"])">
136+
<AdornmentStart>
137+
<div style="opacity:0.5; font-size:13px;">
138+
@(Lang["LockHintText"])
139+
</div>
140+
</AdornmentStart>
141+
</MudTextFieldExtended>
142+
<MudIconButton Icon="@Icons.Material.Filled.Edit"
143+
Variant="Variant.Outlined"
144+
Color="Color.Primary"
145+
Size="Size.Small"
146+
OnClick="EnableTipsMessageEditing"
147+
Disabled="_lockTipsMessageEdit" />
148+
</MudStack>
149+
</MudCollapse>
126150
</div>
127-
128151
<div>
129152
<MudText Typo="Typo.subtitle2" Class="input-title">@(Lang["LockStatusDisplay"])</MudText>
130153
<MudSelect T="LockStatusDisplay"

src/ComputerLock/Components/Settings/LockSettings.razor.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using ComputerLock.Interfaces;
2+
using Microsoft.AspNetCore.Components.Web;
3+
using MudExtensions;
24

35
namespace ComputerLock.Components.Settings;
46

@@ -28,6 +30,44 @@ public partial class LockSettings
2830

2931
[Inject]
3032
private PowerManager PowerManager { get; set; } = null!;
33+
34+
private MudTextFieldExtended<string>? _textTipsMessageRef;
35+
private bool _lockTipsMessageEdit;
36+
public string LockTipsMessage
37+
{
38+
get => AppSettings.LockTipsMessage.IsEmpty()
39+
? Lang["LockTipsValue"] // 显示默认文案
40+
: AppSettings.LockTipsMessage;
41+
set => AppSettings.LockTipsMessage = value;
42+
}
43+
private async Task EnableTipsMessageEditing()
44+
{
45+
_lockTipsMessageEdit = true;
46+
// 等待渲染后再聚焦,否则焦点可能丢失
47+
await Task.Delay(1);
48+
_textTipsMessageRef?.FocusAsync();
49+
}
50+
51+
private void TipsMessageBlur(FocusEventArgs args)
52+
{
53+
TipsMessageFinishEditing();
54+
}
55+
private void TipsMessageKeyDown(KeyboardEventArgs args)
56+
{
57+
if (args.Key == "Enter")
58+
{
59+
TipsMessageFinishEditing();
60+
}
61+
}
62+
private void TipsMessageFinishEditing()
63+
{
64+
if (!_lockTipsMessageEdit)
65+
{
66+
return;
67+
}
68+
_lockTipsMessageEdit = false;
69+
}
70+
3171
private void SaveSettings()
3272
{
3373
AppSettingsProvider.SaveSettings(AppSettings);

src/ComputerLock/Configuration/AppSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public void Initialize(HotkeyTools hotkeyTools)
5252
/// </summary>
5353
public bool LockTips { get; set; } = false;
5454

55+
/// <summary>
56+
/// 自定义锁定提示文案
57+
/// </summary>
58+
public string? LockTipsMessage { get; set; }
59+
5560
/// <summary>
5661
/// 程序启动时锁定
5762
/// </summary>

src/ComputerLock/Resources/Lang.en.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,7 @@
441441
<data name="ExitProgram" xml:space="preserve">
442442
<value>Exit Program</value>
443443
</data>
444+
<data name="LockHintText" xml:space="preserve">
445+
<value>Hint Text</value>
446+
</data>
444447
</root>

src/ComputerLock/Resources/Lang.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,7 @@
441441
<data name="ExitProgram" xml:space="preserve">
442442
<value>退出程序</value>
443443
</data>
444+
<data name="LockHintText" xml:space="preserve">
445+
<value>提示文字</value>
446+
</data>
444447
</root>

src/ComputerLock/Resources/Lang.zh.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,7 @@
441441
<data name="ExitProgram" xml:space="preserve">
442442
<value>退出程序</value>
443443
</data>
444+
<data name="LockHintText" xml:space="preserve">
445+
<value>提示文字</value>
446+
</data>
444447
</root>

src/ComputerLock/Services/GlobalLockService.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void InitUserInputHandling()
7272
if (_appSettings.LockTips && IsLocked)
7373
{
7474
_logger.Info("用户输入 -> 检测到键盘输入");
75-
_popupService.ShowMessage(_lang["LockTipsValue"]);
75+
_popupService.ShowMessage(GetLockTipsMessage());
7676
}
7777
};
7878

@@ -81,11 +81,22 @@ private void InitUserInputHandling()
8181
if (_appSettings.LockTips && IsLocked)
8282
{
8383
_logger.Info("用户输入 -> 检测到鼠标输入");
84-
_popupService.ShowMessage(_lang["LockTipsValue"]);
84+
_popupService.ShowMessage(GetLockTipsMessage());
8585
}
8686
};
8787
}
8888

89+
/// <summary>
90+
/// 获取锁定提示文案
91+
/// </summary>
92+
/// <returns></returns>
93+
private string GetLockTipsMessage()
94+
{
95+
return _appSettings.LockTipsMessage.IsEmpty()
96+
? _lang["LockTipsValue"]
97+
: _appSettings.LockTipsMessage;
98+
}
99+
89100
/// <summary>
90101
/// Windows 事件监控
91102
/// </summary>

0 commit comments

Comments
 (0)