Skip to content

Commit

Permalink
优化设置解锁密码的流程
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuLing-zhang committed Feb 12, 2025
1 parent 13486b1 commit 9786fd4
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 215 deletions.
2 changes: 2 additions & 0 deletions src/ComputerLock/Components/ResetPassword.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
</DialogContent>
<DialogActions>
<MudButton Color="Color.Primary"
FullWidth="true"
Variant="Variant.Filled"
OnClick="Submit">
@(Lang["Save"])
</MudButton>
Expand Down
34 changes: 18 additions & 16 deletions src/ComputerLock/Components/SetPassword.razor
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<MudPasswordField @bind-Value="@_password"
Class="mt-6"
Variant="Variant.Text"
Label="@(Lang["SetPasswordInput"])"
IconSize="Size.Small" />
<MudDialog>
<DialogContent>
<MudPaper Width="350px" Elevation="0">
<MudPasswordField @bind-Value="@_password"
Variant="Variant.Text"
Label="@(Lang["SetPasswordInput"])"
IconSize="Size.Small" />
</MudPaper>
</DialogContent>
<DialogActions>
<MudButton Color="Color.Primary"
FullWidth="true"
Variant="Variant.Filled"
OnClick="Submit">
@(Lang["SetPasswordFinished"])
</MudButton>
</DialogActions>
</MudDialog>

<MudButton Class="mt-4"
FullWidth="true"
Variant="Variant.Filled"
Color="Color.Primary"
OnClick="SavePasswordAsync">@(Lang["SetPasswordFinished"])</MudButton>

<MudAlert Class="mt-6"
Severity="Severity.Normal"
Style="opacity:0.5"
Icon="@Icons.Material.Filled.Face5"
Dense="true">@(Lang["DefaultPasswordTip"])</MudAlert>
15 changes: 9 additions & 6 deletions src/ComputerLock/Components/SetPassword.razor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
namespace ComputerLock.Components;
using DialogResult = MudBlazor.DialogResult;

namespace ComputerLock.Components;
public partial class SetPassword
{
[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = default!;

[Inject]
private IStringLocalizer<Lang> Lang { get; set; } = default!;

Expand All @@ -9,15 +14,12 @@ public partial class SetPassword

private string _password = "";

[Parameter]
public EventCallback<string> PasswordSetFinished { get; set; }

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}

private async Task SavePasswordAsync()
private void Submit()
{
if (_password.IsEmpty())
{
Expand All @@ -26,6 +28,7 @@ private async Task SavePasswordAsync()
}

var password = JiuLing.CommonLibs.Security.MD5Utils.GetStringValueToLower(_password);
await PasswordSetFinished.InvokeAsync(password);
MudDialog.Close(DialogResult.Ok(password));
Snackbar.Add(Lang["SaveOk"], Severity.Success);
}
}
9 changes: 2 additions & 7 deletions src/ComputerLock/Configuration/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,9 @@ public void Initialize(HotkeyTools hotkeyTools)
public LangEnum Lang { get; set; } = LangEnum.zh;

/// <summary>
/// 默认密码 1
/// 解锁密码
/// </summary>
public string Password { get; set; } = "c4ca4238a0b923820dcc509a6f75849b";

/// <summary>
/// 初始密码已修改
/// </summary>
public bool IsPasswordChanged { get; set; } = false;
public string Password { get; set; } = "";

/// <summary>
/// 锁屏快捷键
Expand Down
259 changes: 125 additions & 134 deletions src/ComputerLock/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,151 +1,142 @@
@page "/"

Check warning on line 1 in src/ComputerLock/Pages/Index.razor

View workflow job for this annotation

GitHub Actions / build

Illegal Attribute 'DisableRipple' on 'MudChip' using pattern 'LowerCase' source location '(593,16)-(593,77)' (https://mudblazor.com/features/analyzers)

Check warning on line 1 in src/ComputerLock/Pages/Index.razor

View workflow job for this annotation

GitHub Actions / build

Illegal Attribute 'DisableRipple' on 'MudChip' using pattern 'LowerCase' source location '(593,16)-(593,77)' (https://mudblazor.com/features/analyzers)
@using ComputerLock.Enums
@using JiuLing.CommonLibs.ExtensionMethods

<style>
.dialog-blurry {
backdrop-filter: blur(10px);
}
</style>

@if (!AppSettings.IsPasswordChanged)
{
<SetPassword PasswordSetFinished="OnPasswordSetFinishedAsync"></SetPassword>
}
else
{
<MudSwitch @bind-Value="@(AppSettings.LockOnStartup)"
@bind-Value:after="SaveSettings"
Label="@(Lang["LockOnStartup"])"
Color="Color.Primary" />

<MudTooltip Text="@(Lang["DisableWindowsRemark"])" Placement="Placement.Bottom">
<MudSwitch @bind-Value="@(AppSettings.IsDisableWindowsLock)"
@bind-Value:after="SaveSettings"
Label="@(Lang["DisableWindowsLock"])"
Color="Color.Primary" />
</MudTooltip>
<MudSwitch @bind-Value="@(AppSettings.LockOnStartup)"
@bind-Value:after="SaveSettings"
Label="@(Lang["LockOnStartup"])"
Color="Color.Primary" />

<MudSwitch @bind-Value="@(AppSettings.IsHideMouseCursor)"
<MudTooltip Text="@(Lang["DisableWindowsRemark"])" Placement="Placement.Bottom">
<MudSwitch @bind-Value="@(AppSettings.IsDisableWindowsLock)"
@bind-Value:after="SaveSettings"
Label="@(Lang["HideMouseCursor"])"
Label="@(Lang["DisableWindowsLock"])"
Color="Color.Primary" />

<MudSwitch @bind-Value="@(AppSettings.LockAnimation)"
@bind-Value:after="SaveSettings"
Label="@(Lang["LockAnimation"])"
Color="Color.Primary" />

<MudNumericField T="int"
Label="@(Lang["AutoLock"])"
Value="@(AppSettings.AutoLockMinute)"
Margin="Margin.Dense"
Min="0"
Variant="Variant.Outlined"
ValueChanged="AutoLockChanged">
</MudNumericField>

<HotkeyInput Title="@(Lang["LockHotkey"])"
Hotkey="@(AppSettings.LockHotkeyString)"
OnHotkeySet="SetLockHotkey"
OnHotkeyClear="ClearLockHotkey" />

<MudToggleGroup @bind-Value="@(AppSettings.ScreenUnlockMethod)"
@bind-Value:after="SaveSettings"
T="ScreenUnlockMethods"
SelectionMode="SelectionMode.SingleSelection"
Class="mt-2"
Color="Color.Primary"
Size="Size.Small"
CheckMark
FixedContent>
<MudToggleItem Value="@(ScreenUnlockMethods.Password)" Text="@(Lang["PasswordUnlock"])" />
<MudToggleItem Value="@(ScreenUnlockMethods.Hotkey)" Text="@(Lang["HotkeyUnlock"])" />
</MudToggleGroup>

<MudPaper Elevation="0" Height="210px">

@if (AppSettings.ScreenUnlockMethod == ScreenUnlockMethods.Password)
{
<div class="d-flex align-center">
<MudSwitch @bind-Value="@(AppSettings.EnablePasswordBox)"
@bind-Value:after="SaveSettings"
Label="@(Lang["EnablePasswordBox"])"
Color="Color.Primary" />
@if (!AppSettings.EnablePasswordBox)
{
<MudChip T="string"
Label="true"
Icon="@Icons.Material.Filled.WarningAmber"
IconColor="Color.Primary"
DisableRipple="true"
Size="Size.Small">
@(Lang["EnablePasswordBoxTips"])
</MudChip>
}
</div>

<MudSwitch @bind-Value="@(AppSettings.IsHidePasswordWindow)"
</MudTooltip>

<MudSwitch @bind-Value="@(AppSettings.IsHideMouseCursor)"
@bind-Value:after="SaveSettings"
Label="@(Lang["HideMouseCursor"])"
Color="Color.Primary" />

<MudSwitch @bind-Value="@(AppSettings.LockAnimation)"
@bind-Value:after="SaveSettings"
Label="@(Lang["LockAnimation"])"
Color="Color.Primary" />

<MudNumericField T="int"
Label="@(Lang["AutoLock"])"
Value="@(AppSettings.AutoLockMinute)"
Margin="Margin.Dense"
Min="0"
Variant="Variant.Outlined"
ValueChanged="AutoLockChanged">
</MudNumericField>

<HotkeyInput Title="@(Lang["LockHotkey"])"
Hotkey="@(AppSettings.LockHotkeyString)"
OnHotkeySet="SetLockHotkey"
OnHotkeyClear="ClearLockHotkey" />

<MudToggleGroup @bind-Value="@(AppSettings.ScreenUnlockMethod)"
@bind-Value:after="SaveSettings"
T="ScreenUnlockMethods"
SelectionMode="SelectionMode.SingleSelection"
Class="mt-2"
Color="Color.Primary"
Size="Size.Small"
CheckMark
FixedContent>
<MudToggleItem Value="@(ScreenUnlockMethods.Password)" Text="@(Lang["PasswordUnlock"])" />
<MudToggleItem Value="@(ScreenUnlockMethods.Hotkey)" Text="@(Lang["HotkeyUnlock"])" />
</MudToggleGroup>

<MudPaper Elevation="0" Height="210px">

@if (AppSettings.ScreenUnlockMethod == ScreenUnlockMethods.Password)
{
<MudButton Color="Color.Primary"
IconSize="Size.Small"
OnClick="ResetPassword">
@(Lang["ResetPassword"])
</MudButton>

<div class="d-flex align-center">
<MudSwitch @bind-Value="@(AppSettings.EnablePasswordBox)"
@bind-Value:after="SaveSettings"
Class="ml-6"
Disabled="@(!AppSettings.EnablePasswordBox)"
Label="@(Lang["HidePasswordWindow"])"
Label="@(Lang["EnablePasswordBox"])"
Color="Color.Primary" />
@if (!AppSettings.EnablePasswordBox)
{
<MudChip T="string"
Label="true"
Icon="@Icons.Material.Filled.WarningAmber"
IconColor="Color.Primary"
DisableRipple="true"
Size="Size.Small">
@(Lang["EnablePasswordBoxTips"])
</MudChip>
}
</div>

<MudSwitch @bind-Value="@(AppSettings.IsHidePasswordWindow)"
@bind-Value:after="SaveSettings"
Class="ml-6"
Disabled="@(!AppSettings.EnablePasswordBox)"
Label="@(Lang["HidePasswordWindow"])"
Color="Color.Primary" />

<MudSwitch @bind-Value="@(_keyboardDownChecked)"
@bind-Value:after="KeyboardDownChecked"
Class="ml-6"
Disabled="@(!AppSettings.EnablePasswordBox)"
Label="@(Lang["KeyboardDownActivePwd"])"
Color="Color.Primary" />
<MudSwitch @bind-Value="@(_keyboardDownChecked)"
@bind-Value:after="KeyboardDownChecked"
Class="ml-6"
Disabled="@(!AppSettings.EnablePasswordBox)"
Label="@(Lang["KeyboardDownActivePwd"])"
Color="Color.Primary" />

<MudSwitch @bind-Value="@(_mouseDownChecked)"
@bind-Value:after="MouseDownChecked"
Class="ml-6"
Disabled="@(!AppSettings.EnablePasswordBox)"
Label="@(Lang["MouseDownActivePwd"])"
Color="Color.Primary" />
<MudSwitch @bind-Value="@(_mouseDownChecked)"
@bind-Value:after="MouseDownChecked"
Class="ml-6"
Disabled="@(!AppSettings.EnablePasswordBox)"
Label="@(Lang["MouseDownActivePwd"])"
Color="Color.Primary" />

<MudSelect T="ScreenLocationEnum"
Label="@(Lang["PwdLocation"])"
Variant="Variant.Outlined"
Value="@(AppSettings.PasswordInputLocation)"
Disabled="@(!AppSettings.EnablePasswordBox)"
Class="ml-6"
ValueChanged="PwdBoxLocationChanged"
Margin="Margin.Dense"
Dense="true">
<MudSelectItem Value="@(ScreenLocationEnum.Center)">@(Lang["Center"])</MudSelectItem>
<MudSelectItem Value="@(ScreenLocationEnum.TopLeft)">@(Lang["TopLeft"])</MudSelectItem>
<MudSelectItem Value="@(ScreenLocationEnum.TopRight)">@(Lang["TopRight"])</MudSelectItem>
<MudSelectItem Value="@(ScreenLocationEnum.BottomLeft)">@(Lang["BottomLeft"])</MudSelectItem>
<MudSelectItem Value="@(ScreenLocationEnum.BottomRight)">@(Lang["BottomRight"])</MudSelectItem>
</MudSelect>

<MudButton Color="Color.Primary"
StartIcon="@Icons.Material.Filled.VpnKey"
IconSize="Size.Small"
OnClick="ResetPassword">
@(Lang["ResetPassword"])
</MudButton>
}
else if (AppSettings.ScreenUnlockMethod == ScreenUnlockMethods.Hotkey)
{
<MudPaper Class="mt-1 d-flex align-center" Elevation="0">
<HotkeyInput Title="@(Lang["UnlockHotkey"])"
Hotkey="@(AppSettings.UnlockHotkeyString)"
Disabled="@AppSettings.IsUnlockUseLockHotkey"
OnHotkeySet="SetUnlockHotkey"
OnHotkeyClear="ClearUnlockHotkey" />

<MudCheckBox @bind-Value="@(AppSettings.IsUnlockUseLockHotkey)"
@bind-Value:after="SaveSettings"
class="ml-3"
Label="@(Lang["UseLockHotkey"])"
Size="Size.Small"
Dense="true"
Color="Color.Primary"></MudCheckBox>
</MudPaper>
}
</MudPaper>
}
<MudSelect T="ScreenLocationEnum"
Label="@(Lang["PwdLocation"])"
Variant="Variant.Outlined"
Value="@(AppSettings.PasswordInputLocation)"
Disabled="@(!AppSettings.EnablePasswordBox)"
Class="ml-6"
ValueChanged="PwdBoxLocationChanged"
Margin="Margin.Dense"
Dense="true">
<MudSelectItem Value="@(ScreenLocationEnum.Center)">@(Lang["Center"])</MudSelectItem>
<MudSelectItem Value="@(ScreenLocationEnum.TopLeft)">@(Lang["TopLeft"])</MudSelectItem>
<MudSelectItem Value="@(ScreenLocationEnum.TopRight)">@(Lang["TopRight"])</MudSelectItem>
<MudSelectItem Value="@(ScreenLocationEnum.BottomLeft)">@(Lang["BottomLeft"])</MudSelectItem>
<MudSelectItem Value="@(ScreenLocationEnum.BottomRight)">@(Lang["BottomRight"])</MudSelectItem>
</MudSelect>
}
else if (AppSettings.ScreenUnlockMethod == ScreenUnlockMethods.Hotkey)
{
<MudPaper Class="mt-1 d-flex align-center" Elevation="0">
<HotkeyInput Title="@(Lang["UnlockHotkey"])"
Hotkey="@(AppSettings.UnlockHotkeyString)"
Disabled="@AppSettings.IsUnlockUseLockHotkey"
OnHotkeySet="SetUnlockHotkey"
OnHotkeyClear="ClearUnlockHotkey" />

<MudCheckBox @bind-Value="@(AppSettings.IsUnlockUseLockHotkey)"
@bind-Value:after="SaveSettings"
class="ml-3"
Label="@(Lang["UseLockHotkey"])"
Size="Size.Small"
Dense="true"
Color="Color.Primary"></MudCheckBox>
</MudPaper>
}
</MudPaper>
Loading

0 comments on commit 9786fd4

Please sign in to comment.