代码清理

This commit is contained in:
PrefacedCorg
2025-10-06 18:29:12 +08:00
parent 98ec204bab
commit 4da78a04cb
11 changed files with 102 additions and 105 deletions
+2 -2
View File
@@ -865,7 +865,7 @@ namespace Ink_Canvas.Helpers
{
// 检查当前是否处于鼠标模式
bool isMouseMode = IsInSelectMode();
if (isMouseMode)
{
// 鼠标模式下,根据设置决定是否启用快捷键
@@ -874,7 +874,7 @@ namespace Ink_Canvas.Helpers
else
{
// 非鼠标模式下,需要检查焦点和屏幕位置
// 策略1:鼠标在窗口上时启用热键(最高优先级)
if (_isMouseOverWindow)
{
+5 -5
View File
@@ -839,7 +839,7 @@ namespace Ink_Canvas
// 检测到新版本,停止重试定时器
timerCheckAutoUpdateRetry.Stop();
updateCheckRetryCount = 0;
// 检测到新版本
LogHelper.WriteLogToFile($"AutoUpdate | New version available: {AvailableLatestVersion}");
@@ -1006,7 +1006,7 @@ namespace Ink_Canvas
else if (hasValidLineGroup)
{
LogHelper.WriteLogToFile("AutoUpdate | Current version is already the latest, no retry needed");
// 停止重试定时器
timerCheckAutoUpdateRetry.Stop();
updateCheckRetryCount = 0;
@@ -1015,13 +1015,13 @@ namespace Ink_Canvas
{
// 检查更新失败,启动重试定时器
LogHelper.WriteLogToFile("AutoUpdate | Update check failed, starting retry timer");
// 重置重试计数
updateCheckRetryCount = 0;
// 启动重试定时器,10分钟后重新检查
timerCheckAutoUpdateRetry.Start();
// 清理更新文件夹
AutoUpdateHelper.DeleteUpdatesFolder();
}
+14 -14
View File
@@ -74,7 +74,7 @@ namespace Ink_Canvas
// 强制刷新UI
window.InvalidateVisual();
// 通知其他窗口刷新主题
RefreshOtherWindowsTheme();
}
@@ -118,7 +118,7 @@ namespace Ink_Canvas
// 强制刷新UI
window.InvalidateVisual();
// 通知其他窗口刷新主题
RefreshOtherWindowsTheme();
}
@@ -184,18 +184,18 @@ namespace Ink_Canvas
// 根据主题设置高光颜色
Color highlightBackgroundColor;
Color highlightBarColor;
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
(Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
if (isDarkTheme)
{
highlightBackgroundColor = Color.FromArgb(21, 102, 204, 255);
highlightBarColor = Color.FromRgb(102, 204, 255);
highlightBackgroundColor = Color.FromArgb(21, 102, 204, 255);
highlightBarColor = Color.FromRgb(102, 204, 255);
}
else
{
highlightBackgroundColor = Color.FromArgb(21, 59, 130, 246);
highlightBarColor = Color.FromRgb(37, 99, 235);
highlightBackgroundColor = Color.FromArgb(21, 59, 130, 246);
highlightBarColor = Color.FromRgb(37, 99, 235);
}
// 设置高光背景颜色
@@ -224,16 +224,16 @@ namespace Ink_Canvas
{
// 根据主题选择高光颜色
Color selectedColor;
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
(Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
if (isDarkTheme)
{
selectedColor = Color.FromRgb(102, 204, 255);
selectedColor = Color.FromRgb(102, 204, 255);
}
else
{
selectedColor = Color.FromRgb(30, 58, 138);
selectedColor = Color.FromRgb(30, 58, 138);
}
// 根据当前模式设置按钮颜色
@@ -376,7 +376,7 @@ namespace Ink_Canvas
{
// 强制刷新墨迹选中栏的视觉状态
BorderStrokeSelectionControl.InvalidateVisual();
// 刷新墨迹选中栏内的所有图标
var viewbox = BorderStrokeSelectionControl.Child as Viewbox;
if (viewbox?.Child is ui.SimpleStackPanel stackPanel)
@@ -434,7 +434,7 @@ namespace Ink_Canvas
{
// 强制刷新图片选中栏的视觉状态
BorderImageSelectionControl.InvalidateVisual();
// 刷新图片选中栏内的所有图标
var viewbox = BorderImageSelectionControl.Child as Viewbox;
if (viewbox?.Child is ui.SimpleStackPanel stackPanel)
+1 -1
View File
@@ -418,7 +418,7 @@ namespace Ink_Canvas
// 获取主题颜色资源
var iconForegroundBrush = Application.Current.FindResource("IconForeground") as SolidColorBrush;
// 设置下一页按钮颜色
if (iconForegroundBrush != null)
{
@@ -476,9 +476,9 @@ namespace Ink_Canvas
// 根据主题选择高光颜色
Color highlightColor;
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
(Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
if (isDarkTheme)
{
highlightColor = Color.FromRgb(102, 204, 255); // #66ccff for dark theme
@@ -3716,18 +3716,18 @@ namespace Ink_Canvas
// 根据主题设置高光颜色
Color highlightBackgroundColor;
Color highlightBarColor;
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
(Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
if (isDarkTheme)
{
highlightBackgroundColor = Color.FromArgb(21, 102, 204, 255);
highlightBarColor = Color.FromRgb(102, 204, 255);
highlightBackgroundColor = Color.FromArgb(21, 102, 204, 255);
highlightBarColor = Color.FromRgb(102, 204, 255);
}
else
{
highlightBackgroundColor = Color.FromArgb(21, 59, 130, 246);
highlightBarColor = Color.FromRgb(37, 99, 235);
highlightBackgroundColor = Color.FromArgb(21, 59, 130, 246);
highlightBarColor = Color.FromRgb(37, 99, 235);
}
// 设置高光背景颜色
+10 -10
View File
@@ -61,10 +61,10 @@ namespace Ink_Canvas
private Timer timerCheckAutoFold = new Timer();
private string AvailableLatestVersion;
private Timer timerCheckAutoUpdateWithSilence = new Timer();
private Timer timerCheckAutoUpdateRetry = new Timer();
private Timer timerCheckAutoUpdateRetry = new Timer();
private bool isHidingSubPanelsWhenInking; // 避免书写时触发二次关闭二级菜单导致动画不连续
private int updateCheckRetryCount = 0;
private const int MAX_UPDATE_CHECK_RETRIES = 6;
private int updateCheckRetryCount = 0;
private const int MAX_UPDATE_CHECK_RETRIES = 6;
private Timer timerDisplayTime = new Timer();
private Timer timerDisplayDate = new Timer();
private Timer timerNtpSync = new Timer();
@@ -120,7 +120,7 @@ namespace Ink_Canvas
timerCheckAutoUpdateWithSilence.Elapsed += timerCheckAutoUpdateWithSilence_Elapsed;
timerCheckAutoUpdateWithSilence.Interval = 1000 * 60 * 10;
timerCheckAutoUpdateRetry.Elapsed += timerCheckAutoUpdateRetry_Elapsed;
timerCheckAutoUpdateRetry.Interval = 1000 * 60 * 10;
timerCheckAutoUpdateRetry.Interval = 1000 * 60 * 10;
WaterMarkTime.DataContext = nowTimeVM;
WaterMarkDate.DataContext = nowTimeVM;
timerDisplayTime.Elapsed += TimerDisplayTime_Elapsed;
@@ -863,7 +863,7 @@ namespace Ink_Canvas
// 执行更新检查
LogHelper.WriteLogToFile("AutoUpdate | Retrying update check after failure");
// 清除之前的更新状态
AvailableLatestVersion = null;
AvailableLatestLineGroup = null;
@@ -878,7 +878,7 @@ namespace Ink_Canvas
// 检查更新成功,重置重试计数
updateCheckRetryCount = 0;
LogHelper.WriteLogToFile($"AutoUpdate | Retry successful, found new version: {AvailableLatestVersion}");
// 停止重试定时器,因为已经找到了更新
return;
}
@@ -886,7 +886,7 @@ namespace Ink_Canvas
{
// 检查更新仍然失败,继续重试
LogHelper.WriteLogToFile($"AutoUpdate | Retry {updateCheckRetryCount} failed, will retry in 10 minutes");
// 重新启动定时器,10分钟后再次尝试
timerCheckAutoUpdateRetry.Start();
}
@@ -894,7 +894,7 @@ namespace Ink_Canvas
catch (Exception ex)
{
LogHelper.WriteLogToFile($"AutoUpdate | Error in retry check: {ex.Message}", LogHelper.LogType.Error);
// 出错时也重新启动定时器,稍后再检查
if (updateCheckRetryCount <= MAX_UPDATE_CHECK_RETRIES)
{
@@ -910,10 +910,10 @@ namespace Ink_Canvas
{
// 停止重试定时器
timerCheckAutoUpdateRetry.Stop();
// 重置重试计数
updateCheckRetryCount = 0;
LogHelper.WriteLogToFile("AutoUpdate | Update check retry state reset");
}
catch (Exception ex)
@@ -1,6 +1,4 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace Ink_Canvas.Windows.Controls
@@ -22,7 +22,7 @@ namespace Ink_Canvas
timer.Elapsed += Timer_Elapsed;
timer.Interval = 50;
InitializeUI();
// 应用主题
ApplyTheme();
}
@@ -111,9 +111,9 @@ namespace Ink_Canvas
private void Grid_MouseUp(object sender, MouseButtonEventArgs e)
{
if (isTimerRunning) return;
var textForeground = Application.Current.FindResource("TimerWindowTextForeground") as SolidColorBrush;
if (ProcessBarTime.Visibility == Visibility.Visible && isTimerRunning == false)
{
ProcessBarTime.Visibility = Visibility.Collapsed;
@@ -439,7 +439,7 @@ namespace Ink_Canvas
{
// 重新应用主题
ApplyTheme();
// 强制刷新UI
InvalidateVisual();
}
@@ -1,8 +1,8 @@
using Ink_Canvas.Helpers;
using System.Windows;
using System.Windows.Input;
using iNKORE.UI.WPF.Modern;
using System;
using System.Windows;
using System.Windows.Input;
namespace Ink_Canvas
{
@@ -54,9 +54,9 @@ namespace Ink_Canvas
try
{
// 根据当前主题设置窗口主题
bool isDarkTheme = MainWindow.Settings.Appearance.Theme == 1 ||
bool isDarkTheme = MainWindow.Settings.Appearance.Theme == 1 ||
(MainWindow.Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
if (isDarkTheme)
{
ThemeManager.SetRequestedTheme(this, ElementTheme.Dark);
+1 -1
View File
@@ -487,7 +487,7 @@ namespace Ink_Canvas
{
// 重新应用主题
ApplyTheme(MainWindow.Settings);
// 强制刷新UI
InvalidateVisual();
}
@@ -5,7 +5,6 @@ using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
namespace Ink_Canvas
@@ -23,7 +22,7 @@ namespace Ink_Canvas
timer.Elapsed += Timer_Elapsed;
timer.Interval = 50;
InitializeUI();
// 应用主题
ApplyTheme();
}
@@ -46,9 +45,9 @@ namespace Ink_Canvas
{
int totalHours = (int)leftTimeSpan.TotalHours;
int displayHours = totalHours;
if (displayHours > 99) displayHours = 99;
Digit1Display.Text = (displayHours / 10).ToString();
Digit2Display.Text = (displayHours % 10).ToString();
Digit3Display.Text = (leftTimeSpan.Minutes / 10).ToString();
@@ -86,7 +85,7 @@ namespace Ink_Canvas
bool isPaused = false;
Timer timer = new Timer();
// 最近计时记录
private string recentTimer1 = "--:--";
private string recentTimer2 = "--:--";
@@ -94,7 +93,7 @@ namespace Ink_Canvas
private string recentTimer4 = "--:--";
private string recentTimer5 = "--:--";
private string recentTimer6 = "--:--";
// 最近计时记录的注册表键名
private const string RecentTimer1Key = "SeewoTimer_RecentTimer1";
private const string RecentTimer2Key = "SeewoTimer_RecentTimer2";
@@ -201,10 +200,10 @@ namespace Ink_Canvas
int currentHour = hour;
int hourTens = currentHour / 10;
int hourOnes = currentHour % 10;
hourTens++;
if (hourTens >= 10) hourTens = 0;
hour = hourTens * 10 + hourOnes;
UpdateDigitDisplays();
}
@@ -215,10 +214,10 @@ namespace Ink_Canvas
int currentHour = hour;
int hourTens = currentHour / 10;
int hourOnes = currentHour % 10;
hourTens--;
if (hourTens < 0) hourTens = 9;
hour = hourTens * 10 + hourOnes;
UpdateDigitDisplays();
}
@@ -230,15 +229,15 @@ namespace Ink_Canvas
int currentHour = hour;
int hourTens = currentHour / 10;
int hourOnes = currentHour % 10;
hourOnes++;
if (hourOnes >= 10)
if (hourOnes >= 10)
{
hourOnes = 0;
hourTens++;
if (hourTens >= 10) hourTens = 0;
}
hour = hourTens * 10 + hourOnes;
UpdateDigitDisplays();
}
@@ -249,15 +248,15 @@ namespace Ink_Canvas
int currentHour = hour;
int hourTens = currentHour / 10;
int hourOnes = currentHour % 10;
hourOnes--;
if (hourOnes < 0)
if (hourOnes < 0)
{
hourOnes = 9;
hourTens--;
if (hourTens < 0) hourTens = 9;
}
hour = hourTens * 10 + hourOnes;
UpdateDigitDisplays();
}
@@ -269,10 +268,10 @@ namespace Ink_Canvas
int currentMinute = minute;
int minuteTens = currentMinute / 10;
int minuteOnes = currentMinute % 10;
minuteTens++;
if (minuteTens >= 6) minuteTens = 0;
minute = minuteTens * 10 + minuteOnes;
UpdateDigitDisplays();
}
@@ -283,10 +282,10 @@ namespace Ink_Canvas
int currentMinute = minute;
int minuteTens = currentMinute / 10;
int minuteOnes = currentMinute % 10;
minuteTens--;
if (minuteTens < 0) minuteTens = 5;
minute = minuteTens * 10 + minuteOnes;
UpdateDigitDisplays();
}
@@ -298,15 +297,15 @@ namespace Ink_Canvas
int currentMinute = minute;
int minuteTens = currentMinute / 10;
int minuteOnes = currentMinute % 10;
minuteOnes++;
if (minuteOnes >= 10)
if (minuteOnes >= 10)
{
minuteOnes = 0;
minuteTens++;
if (minuteTens >= 6) minuteTens = 0;
}
minute = minuteTens * 10 + minuteOnes;
UpdateDigitDisplays();
}
@@ -317,15 +316,15 @@ namespace Ink_Canvas
int currentMinute = minute;
int minuteTens = currentMinute / 10;
int minuteOnes = currentMinute % 10;
minuteOnes--;
if (minuteOnes < 0)
if (minuteOnes < 0)
{
minuteOnes = 9;
minuteTens--;
if (minuteTens < 0) minuteTens = 5;
}
minute = minuteTens * 10 + minuteOnes;
UpdateDigitDisplays();
}
@@ -337,10 +336,10 @@ namespace Ink_Canvas
int currentSecond = second;
int secondTens = currentSecond / 10;
int secondOnes = currentSecond % 10;
secondTens++;
if (secondTens >= 6) secondTens = 0;
second = secondTens * 10 + secondOnes;
UpdateDigitDisplays();
}
@@ -351,10 +350,10 @@ namespace Ink_Canvas
int currentSecond = second;
int secondTens = currentSecond / 10;
int secondOnes = currentSecond % 10;
secondTens--;
if (secondTens < 0) secondTens = 5;
second = secondTens * 10 + secondOnes;
UpdateDigitDisplays();
}
@@ -366,15 +365,15 @@ namespace Ink_Canvas
int currentSecond = second;
int secondTens = currentSecond / 10;
int secondOnes = currentSecond % 10;
secondOnes++;
if (secondOnes >= 10)
if (secondOnes >= 10)
{
secondOnes = 0;
secondTens++;
if (secondTens >= 6) secondTens = 0;
}
second = secondTens * 10 + secondOnes;
UpdateDigitDisplays();
}
@@ -385,15 +384,15 @@ namespace Ink_Canvas
int currentSecond = second;
int secondTens = currentSecond / 10;
int secondOnes = currentSecond % 10;
secondOnes--;
if (secondOnes < 0)
if (secondOnes < 0)
{
secondOnes = 9;
secondTens--;
if (secondTens < 0) secondTens = 5;
}
second = secondTens * 10 + secondOnes;
UpdateDigitDisplays();
}
@@ -428,13 +427,13 @@ namespace Ink_Canvas
second = 1;
UpdateDigitDisplays();
}
startTime = DateTime.Now;
StartPauseIcon.Data = Geometry.Parse(PauseIconData);
isPaused = false;
isTimerRunning = true;
timer.Start();
// 保存到最近计时记录
SaveRecentTimer();
}
@@ -518,7 +517,7 @@ namespace Ink_Canvas
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
isTimerRunning = false;
if (MainWindow.Settings != null)
{
var mainWindow = Application.Current.MainWindow as MainWindow;
@@ -526,7 +525,7 @@ namespace Ink_Canvas
{
try
{
var currentModeField = mainWindow.GetType().GetField("currentMode",
var currentModeField = mainWindow.GetType().GetField("currentMode",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (currentModeField != null)
{
@@ -565,23 +564,23 @@ namespace Ink_Canvas
{
CommonTimersGrid.Visibility = Visibility.Visible;
RecentTimersGrid.Visibility = Visibility.Collapsed;
// 更新字体粗细、透明度和颜色
var commonText = this.FindName("CommonTabText") as TextBlock;
var recentText = this.FindName("RecentTabText") as TextBlock;
if (commonText != null)
if (commonText != null)
{
commonText.FontWeight = FontWeights.Bold;
commonText.Opacity = 1.0;
commonText.Foreground = new SolidColorBrush(Colors.White);
}
if (recentText != null)
if (recentText != null)
{
recentText.FontWeight = FontWeights.Normal;
recentText.Opacity = 0.8;
recentText.Foreground = new SolidColorBrush(Color.FromRgb(102, 102, 102));
}
// 移动指示器到左侧
var indicator = this.FindName("SegmentedIndicator") as Border;
if (indicator != null)
@@ -589,7 +588,7 @@ namespace Ink_Canvas
// 设置左侧圆角
indicator.CornerRadius = new CornerRadius(7, 0, 0, 7);
var animation = new System.Windows.Media.Animation.ThicknessAnimation(
new Thickness(0, 0, 0, 0),
new Thickness(0, 0, 0, 0),
TimeSpan.FromMilliseconds(200));
indicator.BeginAnimation(Border.MarginProperty, animation);
}
@@ -599,23 +598,23 @@ namespace Ink_Canvas
{
CommonTimersGrid.Visibility = Visibility.Collapsed;
RecentTimersGrid.Visibility = Visibility.Visible;
// 更新字体粗细、透明度和颜色
var commonText = this.FindName("CommonTabText") as TextBlock;
var recentText = this.FindName("RecentTabText") as TextBlock;
if (commonText != null)
if (commonText != null)
{
commonText.FontWeight = FontWeights.Normal;
commonText.Opacity = 0.8;
commonText.Foreground = new SolidColorBrush(Color.FromRgb(102, 102, 102));
}
if (recentText != null)
if (recentText != null)
{
recentText.FontWeight = FontWeights.Bold;
recentText.Opacity = 1.0;
recentText.Foreground = new SolidColorBrush(Colors.White);
}
// 移动指示器到右侧
var indicator = this.FindName("SegmentedIndicator") as Border;
if (indicator != null)
@@ -623,7 +622,7 @@ namespace Ink_Canvas
// 设置右侧圆角
indicator.CornerRadius = new CornerRadius(0, 7, 7, 0);
var animation = new System.Windows.Media.Animation.ThicknessAnimation(
new Thickness(118, 0, 0, 0),
new Thickness(118, 0, 0, 0),
TimeSpan.FromMilliseconds(200));
indicator.BeginAnimation(Border.MarginProperty, animation);
}
@@ -716,7 +715,7 @@ namespace Ink_Canvas
private void ApplyRecentTimer(string timeString)
{
if (timeString == "--:--") return;
try
{
var parts = timeString.Split(':');
@@ -737,9 +736,9 @@ namespace Ink_Canvas
private void SaveRecentTimer()
{
if (hour == 0 && minute == 0 && second == 0) return;
string currentTime = $"{minute:D2}:{second:D2}";
// 如果当前时间与最近记录不同,则更新
if (currentTime != recentTimer1)
{
@@ -835,7 +834,7 @@ namespace Ink_Canvas
{
if (MainBorder != null)
{
MainBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(64, 64, 64));
MainBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(64, 64, 64));
}
}
catch