From cb6af3e21f412800d26419dccf2953cb185d3210 Mon Sep 17 00:00:00 2001
From: CJKmkp <2564608840@qq.com>
Date: Fri, 1 May 2026 01:22:35 +0800
Subject: [PATCH] =?UTF-8?q?add!:=E5=AE=89=E5=85=A8=E9=9D=A2=E6=9D=BF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Windows/SettingsViews/Pages/HomePage.xaml | 7 +
.../SettingsViews/Pages/SecurityPage.xaml | 112 +++++++++++
.../SettingsViews/Pages/SecurityPage.xaml.cs | 183 ++++++++++++++++++
.../Windows/SettingsViews/SettingsWindow.xaml | 9 +
.../SettingsViews/SettingsWindow.xaml.cs | 1 +
5 files changed, 312 insertions(+)
create mode 100644 Ink Canvas/Windows/SettingsViews/Pages/SecurityPage.xaml
create mode 100644 Ink Canvas/Windows/SettingsViews/Pages/SecurityPage.xaml.cs
diff --git a/Ink Canvas/Windows/SettingsViews/Pages/HomePage.xaml b/Ink Canvas/Windows/SettingsViews/Pages/HomePage.xaml
index d5a3d047..4db69267 100644
--- a/Ink Canvas/Windows/SettingsViews/Pages/HomePage.xaml
+++ b/Ink Canvas/Windows/SettingsViews/Pages/HomePage.xaml
@@ -76,6 +76,13 @@
+
+
+
+
+
+
diff --git a/Ink Canvas/Windows/SettingsViews/Pages/SecurityPage.xaml b/Ink Canvas/Windows/SettingsViews/Pages/SecurityPage.xaml
new file mode 100644
index 00000000..ca144548
--- /dev/null
+++ b/Ink Canvas/Windows/SettingsViews/Pages/SecurityPage.xaml
@@ -0,0 +1,112 @@
+
+
+
+
+
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ink Canvas/Windows/SettingsViews/Pages/SecurityPage.xaml.cs b/Ink Canvas/Windows/SettingsViews/Pages/SecurityPage.xaml.cs
new file mode 100644
index 00000000..43d296c5
--- /dev/null
+++ b/Ink Canvas/Windows/SettingsViews/Pages/SecurityPage.xaml.cs
@@ -0,0 +1,183 @@
+using Ink_Canvas.Helpers;
+using Ink_Canvas.Windows.SettingsViews.Helpers;
+using System;
+using System.Windows;
+using Page = iNKORE.UI.WPF.Modern.Controls.Page;
+
+namespace Ink_Canvas.Windows.SettingsViews.Pages
+{
+ public partial class SecurityPage : Page
+ {
+ private bool _isLoaded = false;
+
+ public SecurityPage()
+ {
+ InitializeComponent();
+ Loaded += Page_Loaded;
+ Unloaded += Page_Unloaded;
+ }
+
+ private void Page_Loaded(object sender, RoutedEventArgs e)
+ {
+ LoadSettings();
+ _isLoaded = true;
+ }
+
+ private void Page_Unloaded(object sender, RoutedEventArgs e)
+ {
+ _isLoaded = false;
+ }
+
+ private void LoadSettings()
+ {
+ _isLoaded = false;
+ try
+ {
+ var settings = SettingsManager.Settings;
+ if (settings == null) return;
+ if (settings.Security == null) settings.Security = new Security();
+
+ var sec = settings.Security;
+ CardPasswordEnabled.IsOn = sec.PasswordEnabled;
+ CardRequirePasswordOnExit.IsOn = sec.RequirePasswordOnExit;
+ CardRequirePasswordOnEnterSettings.IsOn = sec.RequirePasswordOnEnterSettings;
+ CardRequirePasswordOnResetConfig.IsOn = sec.RequirePasswordOnResetConfig;
+ CardRequirePasswordOnModifyOrClearNameList.IsOn = sec.RequirePasswordOnModifyOrClearNameList;
+ CardEnableProcessProtection.IsOn = sec.EnableProcessProtection;
+
+ UpdatePasswordUiState();
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"加载安全页面设置时出错: {ex.Message}");
+ }
+ _isLoaded = true;
+ }
+
+ private void UpdatePasswordUiState()
+ {
+ var sec = SettingsManager.Settings?.Security;
+ var enabled = sec != null && sec.PasswordEnabled;
+
+ if (BtnSetOrChangePassword != null) BtnSetOrChangePassword.IsEnabled = enabled;
+
+ CardRequirePasswordOnExit.IsEnabled = enabled;
+ CardRequirePasswordOnEnterSettings.IsEnabled = enabled;
+ CardRequirePasswordOnResetConfig.IsEnabled = enabled;
+ CardRequirePasswordOnModifyOrClearNameList.IsEnabled = enabled;
+ }
+
+ private void SetCardIsOnSilently(Ink_Canvas.Controls.LabeledSettingsCard card, bool value)
+ {
+ var prev = _isLoaded;
+ _isLoaded = false;
+ try { card.IsOn = value; }
+ finally { _isLoaded = prev; }
+ }
+
+ private async void ToggleSwitchPasswordEnabled_Toggled(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ var settings = SettingsManager.Settings;
+ if (settings == null) return;
+ if (settings.Security == null) settings.Security = new Security();
+ var sec = settings.Security;
+
+ bool newState = CardPasswordEnabled.IsOn;
+ var owner = Window.GetWindow(this);
+
+ if (newState)
+ {
+ var havePassword = SecurityManager.HasPasswordConfigured(settings);
+ if (!havePassword)
+ {
+ var pwd = await SecurityManager.PromptSetNewPasswordAsync(owner);
+ if (string.IsNullOrEmpty(pwd))
+ {
+ SetCardIsOnSilently(CardPasswordEnabled, false);
+ return;
+ }
+ SecurityManager.SetPassword(settings, pwd);
+ }
+
+ sec.PasswordEnabled = true;
+ SettingsManager.SaveSettingsToFile();
+ UpdatePasswordUiState();
+ }
+ else
+ {
+ if (SecurityManager.HasPasswordConfigured(settings))
+ {
+ bool ok = await SecurityManager.PromptAndVerifyAsync(settings, owner,
+ "关闭安全密码", "请输入当前密码以关闭安全密码功能。");
+ if (!ok)
+ {
+ SetCardIsOnSilently(CardPasswordEnabled, true);
+ return;
+ }
+ }
+
+ sec.PasswordEnabled = false;
+ SecurityManager.ClearPassword(settings);
+ SettingsManager.SaveSettingsToFile();
+ UpdatePasswordUiState();
+ }
+ }
+
+ private async void BtnSetOrChangePassword_Click(object sender, RoutedEventArgs e)
+ {
+ var settings = SettingsManager.Settings;
+ if (settings == null) return;
+ if (settings.Security == null) settings.Security = new Security();
+
+ var owner = Window.GetWindow(this);
+ var newPwd = await SecurityManager.PromptChangePasswordAsync(settings, owner);
+ if (!string.IsNullOrEmpty(newPwd))
+ {
+ SecurityManager.SetPassword(settings, newPwd);
+ settings.Security.PasswordEnabled = true;
+ SettingsManager.SaveSettingsToFile();
+
+ SetCardIsOnSilently(CardPasswordEnabled, true);
+ UpdatePasswordUiState();
+ }
+ }
+
+ private void ToggleSwitchRequirePasswordOnExit_Toggled(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ SettingsManager.Settings.Security.RequirePasswordOnExit = CardRequirePasswordOnExit.IsOn;
+ SettingsManager.SaveSettingsToFile();
+ }
+
+ private void ToggleSwitchRequirePasswordOnEnterSettings_Toggled(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ SettingsManager.Settings.Security.RequirePasswordOnEnterSettings = CardRequirePasswordOnEnterSettings.IsOn;
+ SettingsManager.SaveSettingsToFile();
+ }
+
+ private void ToggleSwitchRequirePasswordOnResetConfig_Toggled(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ SettingsManager.Settings.Security.RequirePasswordOnResetConfig = CardRequirePasswordOnResetConfig.IsOn;
+ SettingsManager.SaveSettingsToFile();
+ }
+
+ private void ToggleSwitchRequirePasswordOnModifyOrClearNameList_Toggled(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ SettingsManager.Settings.Security.RequirePasswordOnModifyOrClearNameList = CardRequirePasswordOnModifyOrClearNameList.IsOn;
+ SettingsManager.SaveSettingsToFile();
+ }
+
+ private void ToggleSwitchEnableProcessProtection_Toggled(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ bool newState = CardEnableProcessProtection.IsOn;
+ SettingsManager.Settings.Security.EnableProcessProtection = newState;
+ SettingsManager.SaveSettingsToFile();
+ ProcessProtectionManager.SetEnabled(newState);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml
index 97a8db66..8482e0af 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml
@@ -153,6 +153,15 @@
+
+
+
+
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs
index 7f4394b9..32862577 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs
@@ -40,6 +40,7 @@ namespace Ink_Canvas.Windows.SettingsViews
{ "HomePage", typeof(HomePage) },
{ "StartupPage", typeof(StartupPage) },
{ "PrivacyPage", typeof(PrivacyPage) },
+ { "SecurityPage", typeof(SecurityPage) },
{ "WindowPage", typeof(WindowPage) },
{ "AppearancePage", typeof(AppearancePage) },
{ "UpdatePage", typeof(UpdatePage) },