代码优化

This commit is contained in:
2026-03-21 16:13:42 +08:00
parent 3934270ed2
commit 74b64bd21f
5 changed files with 20 additions and 25 deletions
+7 -7
View File
@@ -1,8 +1,10 @@
using Hardcodet.Wpf.TaskbarNotification; using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers; using Ink_Canvas.Helpers;
using Ink_Canvas.Properties;
using iNKORE.UI.WPF.Modern.Controls; using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Win32; using Microsoft.Win32;
using Newtonsoft.Json; using Newtonsoft.Json;
using Sentry;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@@ -18,10 +20,8 @@ using System.Windows.Input;
using System.Windows.Threading; using System.Windows.Threading;
using Application = System.Windows.Application; using Application = System.Windows.Application;
using MessageBox = System.Windows.MessageBox; using MessageBox = System.Windows.MessageBox;
using Ink_Canvas.Properties;
using SplashScreen = Ink_Canvas.Windows.SplashScreen; using SplashScreen = Ink_Canvas.Windows.SplashScreen;
using Timer = System.Threading.Timer; using Timer = System.Threading.Timer;
using Sentry;
namespace Ink_Canvas namespace Ink_Canvas
{ {
@@ -1088,7 +1088,7 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"启动完成心跳已记录"); LogHelper.WriteLogToFile($"启动完成心跳已记录");
} }
LogHelper.WriteLogToFile($"启动时长: {(startupCompleteHeartbeat - appStartupStartTime).TotalSeconds:F2}秒"); LogHelper.WriteLogToFile($"启动时长: {(startupCompleteHeartbeat - appStartupStartTime).TotalSeconds:F2}秒");
if (_isSplashScreenShown) if (_isSplashScreenShown)
{ {
SetSplashMessage("完成初始化..."); SetSplashMessage("完成初始化...");
@@ -1223,8 +1223,8 @@ namespace Ink_Canvas
if (!isStartupComplete && appStartupStartTime != DateTime.MinValue) if (!isStartupComplete && appStartupStartTime != DateTime.MinValue)
{ {
DateTime startTime = _isSplashScreenShown && splashScreenStartTime != DateTime.MinValue DateTime startTime = _isSplashScreenShown && splashScreenStartTime != DateTime.MinValue
? splashScreenStartTime ? splashScreenStartTime
: appStartupStartTime; : appStartupStartTime;
TimeSpan elapsedSinceStart = DateTime.Now - startTime; TimeSpan elapsedSinceStart = DateTime.Now - startTime;
if (elapsedSinceStart.TotalMinutes >= 2) if (elapsedSinceStart.TotalMinutes >= 2)
@@ -1405,7 +1405,7 @@ namespace Ink_Canvas
string assemblyLocation = Assembly.GetExecutingAssembly().Location; string assemblyLocation = Assembly.GetExecutingAssembly().Location;
string currentDir = Path.GetDirectoryName(assemblyLocation); string currentDir = Path.GetDirectoryName(assemblyLocation);
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
string dsnFilePath = Path.Combine(currentDir, "telemetry_dsn.txt"); string dsnFilePath = Path.Combine(currentDir, "telemetry_dsn.txt");
@@ -1417,7 +1417,7 @@ namespace Ink_Canvas
return dsn; return dsn;
} }
} }
DirectoryInfo parentDir = Directory.GetParent(currentDir); DirectoryInfo parentDir = Directory.GetParent(currentDir);
if (parentDir == null) if (parentDir == null)
{ {
+1 -3
View File
@@ -264,7 +264,6 @@ namespace Ink_Canvas.Helpers
public void Enable() public void Enable()
{ {
IsEnabled = true; IsEnabled = true;
LogHelper.WriteLogToFile("墨迹渐隐功能已启用");
} }
/// <summary> /// <summary>
@@ -273,7 +272,6 @@ namespace Ink_Canvas.Helpers
public void Disable() public void Disable()
{ {
IsEnabled = false; IsEnabled = false;
LogHelper.WriteLogToFile("墨迹渐隐功能已禁用");
} }
#endregion #endregion
@@ -894,4 +892,4 @@ namespace Ink_Canvas.Helpers
} }
#endregion #endregion
} }
} }
+10 -10
View File
@@ -150,13 +150,13 @@ namespace Ink_Canvas.Helpers
private void CheckAndConnectToPPT() private void CheckAndConnectToPPT()
{ {
if (_isModuleUnloading) return; if (_isModuleUnloading) return;
lock (_lockObject) lock (_lockObject)
{ {
try try
{ {
if (_isModuleUnloading) return; if (_isModuleUnloading) return;
// 尝试连接到PowerPoint // 尝试连接到PowerPoint
var pptApp = TryConnectToPowerPoint(); var pptApp = TryConnectToPowerPoint();
if (pptApp == null && IsSupportWPS) if (pptApp == null && IsSupportWPS)
@@ -421,7 +421,7 @@ namespace Ink_Canvas.Helpers
SafeReleaseComObject(CurrentSlide, "CurrentSlide"); SafeReleaseComObject(CurrentSlide, "CurrentSlide");
SafeReleaseComObject(CurrentSlides, "CurrentSlides"); SafeReleaseComObject(CurrentSlides, "CurrentSlides");
SafeReleaseComObject(CurrentPresentation, "CurrentPresentation"); SafeReleaseComObject(CurrentPresentation, "CurrentPresentation");
if (PPTApplication != null && Marshal.IsComObject(PPTApplication)) if (PPTApplication != null && Marshal.IsComObject(PPTApplication))
{ {
try try
@@ -474,13 +474,13 @@ namespace Ink_Canvas.Helpers
_isModuleUnloading = false; _isModuleUnloading = false;
return; return;
} }
GC.Collect(); GC.Collect();
GC.WaitForPendingFinalizers(); GC.WaitForPendingFinalizers();
GC.Collect(); GC.Collect();
Thread.Sleep(1000); Thread.Sleep(1000);
_isModuleUnloading = false; _isModuleUnloading = false;
try try
@@ -494,7 +494,7 @@ namespace Ink_Canvas.Helpers
{ {
LogHelper.WriteLogToFile("PPT联动模块重载时计时器已释放,跳过重启", LogHelper.LogType.Trace); LogHelper.WriteLogToFile("PPT联动模块重载时计时器已释放,跳过重启", LogHelper.LogType.Trace);
} }
LogHelper.WriteLogToFile("PPT联动模块已重新加载", LogHelper.LogType.Trace); LogHelper.WriteLogToFile("PPT联动模块已重新加载", LogHelper.LogType.Trace);
} }
catch (Exception ex) catch (Exception ex)
@@ -555,7 +555,7 @@ namespace Ink_Canvas.Helpers
object view = null; object view = null;
object selection = null; object selection = null;
object slideRange = null; object slideRange = null;
try try
{ {
if (PPTApplication != null && Marshal.IsComObject(PPTApplication)) if (PPTApplication != null && Marshal.IsComObject(PPTApplication))
@@ -605,7 +605,7 @@ namespace Ink_Canvas.Helpers
if (view != null) if (view != null)
{ {
dynamic viewObj = view; dynamic viewObj = view;
CurrentSlide = viewObj.Slide as Slide; CurrentSlide = viewObj.Slide as Slide;
} }
} }
} }
@@ -632,7 +632,7 @@ namespace Ink_Canvas.Helpers
} }
} }
} }
if (CurrentSlide == null && SlidesCount > 0) if (CurrentSlide == null && SlidesCount > 0)
{ {
CurrentSlide = CurrentSlides[1]; CurrentSlide = CurrentSlides[1];
+1 -3
View File
@@ -3535,7 +3535,6 @@ namespace Ink_Canvas
ToggleSwitchInkFadeInPanel2.IsOn = Settings.Canvas.EnableInkFade; ToggleSwitchInkFadeInPanel2.IsOn = Settings.Canvas.EnableInkFade;
} }
LogHelper.WriteLogToFile($"墨迹渐隐功能已{(Settings.Canvas.EnableInkFade ? "" : "")}", LogHelper.LogType.Event);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -3587,7 +3586,6 @@ namespace Ink_Canvas
ToggleSwitchInkFadeInPanel2.IsOn = Settings.Canvas.EnableInkFade; ToggleSwitchInkFadeInPanel2.IsOn = Settings.Canvas.EnableInkFade;
} }
LogHelper.WriteLogToFile($"批注子面板中墨迹渐隐功能已{(Settings.Canvas.EnableInkFade ? "" : "")}", LogHelper.LogType.Event);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -4812,4 +4810,4 @@ namespace Ink_Canvas
#endregion #endregion
} }
} }
+1 -2
View File
@@ -1441,7 +1441,6 @@ namespace Ink_Canvas
if (_eraserAutoSwitchBackTimer != null) if (_eraserAutoSwitchBackTimer != null)
{ {
_eraserAutoSwitchBackTimer.Stop(); _eraserAutoSwitchBackTimer.Stop();
LogHelper.WriteLogToFile("橡皮擦自动切换计时器已停止", LogHelper.LogType.Trace);
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -1486,4 +1485,4 @@ namespace Ink_Canvas
} }
} }
} }
} }