2026-04-21 02:16:58 +08:00
|
|
|
using Ink_Canvas.Helpers;
|
2026-04-19 08:35:22 +08:00
|
|
|
using Ink_Canvas.Windows.SettingsViews.Helpers;
|
2026-03-29 17:39:52 +08:00
|
|
|
using System;
|
2026-04-18 22:32:08 +08:00
|
|
|
using System.Diagnostics;
|
2026-03-29 12:38:46 +08:00
|
|
|
using System.Windows;
|
2026-04-25 13:56:16 +08:00
|
|
|
using System.Windows.Controls;
|
2026-03-29 12:38:46 +08:00
|
|
|
|
2026-04-05 21:50:53 +08:00
|
|
|
namespace Ink_Canvas.Windows.SettingsViews.Pages
|
2026-03-29 12:38:46 +08:00
|
|
|
{
|
2026-04-18 22:32:08 +08:00
|
|
|
public partial class StartupPage : iNKORE.UI.WPF.Modern.Controls.Page
|
2026-03-29 12:38:46 +08:00
|
|
|
{
|
2026-04-04 11:33:47 +08:00
|
|
|
private bool _isLoaded = false;
|
|
|
|
|
|
2026-04-05 17:27:00 +08:00
|
|
|
public StartupPage()
|
2026-03-29 12:38:46 +08:00
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2026-04-05 17:27:00 +08:00
|
|
|
Loaded += StartupPage_Loaded;
|
2026-04-04 11:33:47 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-05 17:27:00 +08:00
|
|
|
private void StartupPage_Loaded(object sender, RoutedEventArgs e)
|
2026-04-04 11:33:47 +08:00
|
|
|
{
|
|
|
|
|
LoadSettings();
|
|
|
|
|
_isLoaded = true;
|
2026-04-01 00:46:40 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-18 22:32:08 +08:00
|
|
|
private void LoadSettings()
|
|
|
|
|
{
|
|
|
|
|
_isLoaded = false;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-04-19 08:35:22 +08:00
|
|
|
var settings = SettingsManager.Settings;
|
2026-04-04 11:33:47 +08:00
|
|
|
|
2026-04-19 08:35:22 +08:00
|
|
|
bool runAtStartup = AutoStartHelper.IsAutoStartEnabled("Ink Canvas Annotation");
|
2026-04-18 22:32:08 +08:00
|
|
|
CardRunAtStartup.IsOn = runAtStartup;
|
2026-04-04 11:33:47 +08:00
|
|
|
|
2026-04-19 08:35:22 +08:00
|
|
|
if (settings.Startup != null)
|
2026-04-04 19:43:06 +08:00
|
|
|
{
|
2026-04-19 08:35:22 +08:00
|
|
|
CardFoldAtStartup.IsOn = settings.Startup.IsFoldAtStartup;
|
2026-04-04 19:43:06 +08:00
|
|
|
}
|
2026-04-04 11:33:47 +08:00
|
|
|
|
2026-04-19 08:35:22 +08:00
|
|
|
if (settings.ModeSettings != null)
|
2026-04-04 19:43:06 +08:00
|
|
|
{
|
2026-04-19 14:42:11 +08:00
|
|
|
CardPPTOnlyMode.IsOn = settings.ModeSettings.IsPPTOnlyMode;
|
2026-04-04 19:43:06 +08:00
|
|
|
}
|
2026-04-24 19:16:48 +08:00
|
|
|
|
|
|
|
|
CardExternalProtocol.IsOn = settings.Advanced.IsEnableUriScheme;
|
2026-04-25 13:56:16 +08:00
|
|
|
|
|
|
|
|
if (settings.Startup != null)
|
|
|
|
|
{
|
|
|
|
|
CardEnableNibMode.IsOn = settings.Startup.IsEnableNibMode;
|
|
|
|
|
|
2026-04-25 17:00:02 +08:00
|
|
|
ComboBoxCrashAction.SelectedIndex = settings.Startup.CrashAction;
|
2026-04-25 13:56:16 +08:00
|
|
|
}
|
2026-04-01 00:46:40 +08:00
|
|
|
}
|
2026-04-04 11:33:47 +08:00
|
|
|
catch (Exception ex)
|
2026-04-01 00:46:40 +08:00
|
|
|
{
|
2026-04-18 22:32:08 +08:00
|
|
|
Debug.WriteLine($"加载启动设置时出错: {ex.Message}");
|
2026-04-01 00:46:40 +08:00
|
|
|
}
|
2026-04-04 11:33:47 +08:00
|
|
|
|
|
|
|
|
_isLoaded = true;
|
2026-04-01 00:46:40 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-04 11:33:47 +08:00
|
|
|
#region 启动设置事件处理
|
|
|
|
|
|
|
|
|
|
private void ToggleSwitchRunAtStartup_Toggled(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!_isLoaded) return;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-04-18 22:32:08 +08:00
|
|
|
bool newState = CardRunAtStartup.IsOn;
|
2026-04-05 17:31:15 +08:00
|
|
|
|
2026-04-18 22:32:08 +08:00
|
|
|
if (newState)
|
|
|
|
|
{
|
2026-04-19 08:35:22 +08:00
|
|
|
AutoStartHelper.StartAutomaticallyDel("InkCanvas");
|
|
|
|
|
AutoStartHelper.StartAutomaticallyCreate("Ink Canvas Annotation");
|
2026-04-18 22:32:08 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-04-19 08:35:22 +08:00
|
|
|
AutoStartHelper.StartAutomaticallyDel("InkCanvas");
|
|
|
|
|
AutoStartHelper.StartAutomaticallyDel("Ink Canvas Annotation");
|
2026-04-18 22:32:08 +08:00
|
|
|
}
|
2026-04-01 00:46:40 +08:00
|
|
|
}
|
2026-04-04 11:33:47 +08:00
|
|
|
catch (Exception ex)
|
2026-04-01 00:46:40 +08:00
|
|
|
{
|
2026-04-18 22:32:08 +08:00
|
|
|
Debug.WriteLine($"设置开机启动时出错: {ex.Message}");
|
2026-04-01 00:46:40 +08:00
|
|
|
}
|
2026-03-29 12:38:46 +08:00
|
|
|
}
|
2026-04-04 11:33:47 +08:00
|
|
|
|
|
|
|
|
private void ToggleSwitchFoldAtStartup_Toggled(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!_isLoaded) return;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-04-18 22:32:08 +08:00
|
|
|
bool newState = CardFoldAtStartup.IsOn;
|
2026-04-05 17:31:15 +08:00
|
|
|
|
2026-04-19 08:35:22 +08:00
|
|
|
SettingsManager.Settings.Startup.IsFoldAtStartup = newState;
|
|
|
|
|
SettingsManager.SaveSettingsToFile();
|
2026-04-04 11:33:47 +08:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-04-18 22:32:08 +08:00
|
|
|
Debug.WriteLine($"设置开机折叠时出错: {ex.Message}");
|
2026-04-04 11:33:47 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-24 19:16:48 +08:00
|
|
|
private void ToggleSwitchExternalProtocol_Toggled(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!_isLoaded) return;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
bool newState = CardExternalProtocol.IsOn;
|
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
|
|
if (newState)
|
|
|
|
|
{
|
|
|
|
|
if (!UriSchemeHelper.IsUriSchemeRegistered())
|
|
|
|
|
{
|
|
|
|
|
success = UriSchemeHelper.RegisterUriScheme();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
success = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (UriSchemeHelper.IsUriSchemeRegistered())
|
|
|
|
|
{
|
|
|
|
|
success = UriSchemeHelper.UnregisterUriScheme();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
success = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
SettingsManager.Settings.Advanced.IsEnableUriScheme = newState;
|
|
|
|
|
SettingsManager.SaveSettingsToFile();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_isLoaded = false;
|
|
|
|
|
CardExternalProtocol.IsOn = !newState;
|
|
|
|
|
_isLoaded = true;
|
|
|
|
|
|
|
|
|
|
LogHelper.WriteLogToFile("设置外部协议失败,请检查权限或日志", LogHelper.LogType.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine($"设置外部协议时出错: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-04 11:33:47 +08:00
|
|
|
#endregion
|
|
|
|
|
|
2026-04-25 13:56:16 +08:00
|
|
|
#region 笔尖模式事件处理
|
|
|
|
|
|
|
|
|
|
private void ToggleSwitchEnableNibMode_Toggled(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!_isLoaded) return;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
bool newState = CardEnableNibMode.IsOn;
|
|
|
|
|
SettingsManager.Settings.Startup.IsEnableNibMode = newState;
|
|
|
|
|
|
|
|
|
|
var window = Application.Current.MainWindow;
|
|
|
|
|
if (window is MainWindow mw)
|
|
|
|
|
{
|
|
|
|
|
if (mw.ToggleSwitchEnableNibMode != null)
|
|
|
|
|
mw.ToggleSwitchEnableNibMode.IsOn = newState;
|
|
|
|
|
if (mw.BoardToggleSwitchEnableNibMode != null)
|
|
|
|
|
mw.BoardToggleSwitchEnableNibMode.IsOn = newState;
|
|
|
|
|
|
|
|
|
|
if (newState)
|
|
|
|
|
mw.BoundsWidth = SettingsManager.Settings.Advanced.NibModeBoundsWidth;
|
|
|
|
|
else
|
|
|
|
|
mw.BoundsWidth = SettingsManager.Settings.Advanced.FingerModeBoundsWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SettingsManager.SaveSettingsToFile();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine($"设置笔尖模式时出错: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 崩溃后操作事件处理
|
|
|
|
|
|
2026-04-25 17:00:02 +08:00
|
|
|
private void ComboBoxCrashAction_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
2026-04-25 13:56:16 +08:00
|
|
|
{
|
|
|
|
|
if (!_isLoaded) return;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-04-25 17:00:02 +08:00
|
|
|
var item = ComboBoxCrashAction?.SelectedItem as ComboBoxItem;
|
|
|
|
|
if (item == null) return;
|
|
|
|
|
var tag = item.Tag?.ToString() ?? "0";
|
|
|
|
|
switch (tag)
|
2026-04-25 13:56:16 +08:00
|
|
|
{
|
2026-04-25 17:00:02 +08:00
|
|
|
case "0":
|
|
|
|
|
App.CrashAction = App.CrashActionType.SilentRestart;
|
|
|
|
|
SettingsManager.Settings.Startup.CrashAction = 0;
|
|
|
|
|
break;
|
|
|
|
|
case "1":
|
|
|
|
|
App.CrashAction = App.CrashActionType.NoAction;
|
|
|
|
|
SettingsManager.Settings.Startup.CrashAction = 1;
|
|
|
|
|
break;
|
2026-04-25 13:56:16 +08:00
|
|
|
}
|
|
|
|
|
SettingsManager.SaveSettingsToFile();
|
|
|
|
|
App.SyncCrashActionFromSettings();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine($"设置崩溃操作时出错: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2026-04-04 11:33:47 +08:00
|
|
|
#region 模式设置事件处理
|
|
|
|
|
|
|
|
|
|
private void ToggleSwitchPPTOnlyMode_Toggled(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!_isLoaded) return;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-04-19 14:42:11 +08:00
|
|
|
bool newState = CardPPTOnlyMode.IsOn;
|
2026-04-05 17:31:15 +08:00
|
|
|
|
2026-04-19 08:35:22 +08:00
|
|
|
var window = Application.Current.MainWindow;
|
|
|
|
|
if (window != null)
|
|
|
|
|
{
|
|
|
|
|
WindowSettingsHelper.ApplyPptOnlyMode(window, newState);
|
|
|
|
|
}
|
2026-04-04 11:33:47 +08:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-04-18 22:32:08 +08:00
|
|
|
Debug.WriteLine($"设置仅PPT模式时出错: {ex.Message}");
|
2026-04-04 11:33:47 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2026-03-29 12:38:46 +08:00
|
|
|
}
|
2026-04-04 11:33:47 +08:00
|
|
|
}
|