Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 79 additions & 12 deletions Ink Canvas/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using H.NotifyIcon;
using Ink_Canvas.Helpers;
using Ink_Canvas.Plugins;
using Ink_Canvas.Services;
using Ink_Canvas.Properties;
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Win32;
Expand Down Expand Up @@ -209,6 +210,8 @@ public App()
}
catch
{
// 此处守卫的正是日志写入本身:日志系统尚未就绪或写盘失败时无法再记录,
// 只能静默吞掉以保证启动流程不被日志故障中断(这是全仓唯一允许无日志的空 catch)。
}

System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
Expand Down Expand Up @@ -237,7 +240,7 @@ public App()
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[App] 设置 AppUserModelID 失败(任务栏分组可能异常): {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}

// 配置TLS协议以支持Windows 7
Expand Down Expand Up @@ -434,7 +437,7 @@ private void ConfigureTlsForWindows7()
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[App] TLS 兼容配置失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}

Expand Down Expand Up @@ -524,7 +527,7 @@ private void BindMainWindowLifecycle()
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[Crash] 绑定主窗口 SourceInitialized 事件失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}

Expand All @@ -547,7 +550,7 @@ private void MainWindow_SourceInitialized(object sender, EventArgs e)
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[Crash] 注册主窗口销毁监听失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}

Expand Down Expand Up @@ -605,7 +608,7 @@ private void CleanupTerminationMonitoring()
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[Crash] 卸载窗口销毁 WinEvent 钩子失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}

Expand Down Expand Up @@ -1039,16 +1042,15 @@ private static void SyncCrashActionFromParsed(dynamic parsedSettings)
try
{
int crashAction = 2;
try { crashAction = (int)(parsedSettings?["startup"]?["crashAction"] ?? 2); }
catch (Exception ex)
try { crashAction = (int)(parsedSettings?["startup"]?["crashAction"] ?? 2); } catch (Exception ex)
{
LogHelper.WriteLogToFile($"[App] 解析崩溃后动作设置失败,改用默认值 2: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
CrashAction = (CrashActionType)crashAction;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[App] 同步崩溃后动作失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}

Expand Down Expand Up @@ -2260,9 +2262,74 @@ public static void RunWatchdogIfNeeded()
}
}

// 装配托盘服务的依赖委托。MainWindow/App 私有成员的访问全部经此处注入,
// TrayIconService 不引用 MainWindow 类型(事件出抛方向唯一:Service → App)。
private TrayIconService CreateTrayIconService()
{
var service = new TrayIconService(new TrayIconService.Hooks
{
GetMainWindow = () => Current.MainWindow,
GetTrayLeftClickAction = () => Ink_Canvas.MainWindow.Settings.Appearance.TrayLeftClickAction,
GetTrayRightClickAction = () => Ink_Canvas.MainWindow.Settings.Appearance.TrayRightClickAction,
IsAlwaysOnTop = () => Ink_Canvas.MainWindow.Settings.Advanced.IsAlwaysOnTop,
IsNoFocusMode = () => Ink_Canvas.MainWindow.Settings.Advanced.IsNoFocusMode,
IsFloatingBarFolded = () => ((MainWindow)Current.MainWindow).isFloatingBarFolded,
FoldFloatingBar = () => ((MainWindow)Current.MainWindow).FoldFloatingBar_MouseUp(new object(), null),
UnfoldFloatingBar = () => ((MainWindow)Current.MainWindow).UnFoldFloatingBar_MouseUp(new object(), null),
ResetFloatingBarPosition = () =>
{
var mw = (MainWindow)Current.MainWindow;
var isInPPTPresentationMode = mw.IsInPPTPresentationMode;
if (!mw.isFloatingBarFolded)
{
// 清空保存的状态,强制动画走默认位置分支
mw._userHasDraggedFloatingBar = false;
mw.pointDesktop = new Point(-1, -1);
mw.pointPPT = new Point(-1, -1);

if (!isInPPTPresentationMode) mw.PureViewboxFloatingBarMarginAnimationInDesktopMode();
else mw.PureViewboxFloatingBarMarginAnimationInPPTMode();
}
},
SetTrayTemporaryShowUntilUtc = value => Ink_Canvas.MainWindow.TrayTemporaryShowUntilUtc = value,
UiInvoke = action => Dispatcher.BeginInvoke(action),
OpenSettings = () =>
{
try
{
var method = typeof(MainWindow).GetMethod("BtnSettings_Click", BindingFlags.NonPublic | BindingFlags.Instance);
method?.Invoke(Current.MainWindow, new object[] { null, null });
}
catch (Exception ex) { LogHelper.WriteLogToFile($"Open settings from tray failed: {ex.Message}", LogHelper.LogType.Error); }
},
MarkExitByUser = () => IsAppExitByUser = true,
ExitApplicationByUser = () =>
{
IsAppExitByUser = true;
((MainWindow)Current.MainWindow).ExitApplication(null, null);
},
Shutdown = () => Current.Shutdown(),
ForceFullScreen = () =>
{
var mw = (MainWindow)Current.MainWindow;
Ink_Canvas.MainWindow.MoveWindow(new WindowInteropHelper(mw).Handle, 0, 0,
Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, true);
Ink_Canvas.MainWindow.ShowNewMessage($"已强制全屏化:{Screen.PrimaryScreen.Bounds.Width}x{Screen.PrimaryScreen.Bounds.Height}(缩放比例为{Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth}x{Screen.PrimaryScreen.Bounds.Height / SystemParameters.PrimaryScreenHeight})");
},
CheckMainWindowVisibility = () => ((MainWindow)Current.MainWindow).CheckMainWindowVisibility(),
GetGlobalHotkeyManager = () => typeof(MainWindow)
.GetField("_globalHotkeyManager", BindingFlags.NonPublic | BindingFlags.Instance)
?.GetValue(Current.MainWindow) as GlobalHotkeyManager,
});
service.TrayLeftClicked += () => PluginTrayLeftClicked?.Invoke();
service.TrayRightClicked += () => PluginTrayRightClicked?.Invoke();
return service;
}

private void App_Exit(object sender, ExitEventArgs e)
{
isAppExiting = true;
_trayIconService?.Dispose();
LogHelper.WriteLogToFile(
$"[Exit] 开始应用退出清理: user={IsAppExitByUser}, code={e.ApplicationExitCode}, crashAction={CrashAction}",
LogHelper.LogType.Info);
Expand All @@ -2279,11 +2346,11 @@ private void App_Exit(object sender, ExitEventArgs e)

try { heartbeatTimer?.Stop(); } catch (Exception ex)
{
LogHelper.WriteLogToFile($"[Exit] 停止心跳计时器失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
try { watchdogTimer?.Change(Timeout.Infinite, Timeout.Infinite); watchdogTimer?.Dispose(); } catch (Exception ex)
{
LogHelper.WriteLogToFile($"[Exit] 释放看门狗计时器失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
MemoryBreakdownHelper.StopAutomaticDumpMonitor();

Expand Down Expand Up @@ -2311,7 +2378,7 @@ private void App_Exit(object sender, ExitEventArgs e)
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[Exit] 释放单实例互斥体失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}

// 卸载所有插件
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ public KillProcessActionHandler(IActionService actionService)
{
foreach (var process in Process.GetProcessesByName(s.ProcessName))
{
try { process.Kill(); }
catch (Exception ex)
try { process.Kill(); } catch (System.Exception ex)
{
LogHelper.WriteLogToFile($"[Automation] 结束进程 处理器: 结束进程 \"{s.ProcessName}\" 中的某个进程失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}
}
catch (Exception ex)
catch (System.Exception ex)
{
LogHelper.WriteLogToFile($"[Automation] 结束进程 处理器: 枚举进程 \"{s.ProcessName}\" 失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions Ink Canvas/Automation/Actions/KillProcessAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public static ActionRegistryInfo Register()
{
process.Kill();
}
catch (Exception ex)
catch (System.Exception ex)
{
LogHelper.WriteLogToFile($"[Automation] 结束进程 行动: 结束进程 \"{s.ProcessName}\" 中的某个进程失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}
}
catch (Exception ex)
catch (System.Exception ex)
{
LogHelper.WriteLogToFile($"[Automation] 结束进程 行动: 枚举进程 \"{s.ProcessName}\" 失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
};

Expand Down
5 changes: 2 additions & 3 deletions Ink Canvas/Automation/AutomationBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,9 @@ public static void Initialize()
{
// 任意步骤失败时整体回滚到未初始化状态,避免后续 AutomationBootstrap 调用走错误路径
LogHelper.WriteLogToFile($"[Automation] 初始化失败,已回滚: {ex.Message}", LogHelper.LogType.Error);
try { Shutdown(); }
catch (Exception shutdownEx)
try { Shutdown(); } catch (Exception shutdownEx)
{
LogHelper.WriteLogToFile($"[Automation] 初始化失败后回滚 Shutdown 也失败: {shutdownEx.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(shutdownEx);
}
throw;
}
Expand Down
2 changes: 1 addition & 1 deletion Ink Canvas/Automation/Services/AutomationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private void UnloadTrigger(Workflow workflow, TriggerSettings trigger)
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"[Automation] 卸载触发器 \"{trigger.Id}\" 的 UnLoaded() 失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}

trigger.TriggerInstance.Triggered -= TriggerTriggered;
Expand Down
7 changes: 3 additions & 4 deletions Ink Canvas/Automation/Services/SystemEventMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private void OnForegroundFallbackElapsed(object sender, ElapsedEventArgs e)
}
catch (Exception ex)
{
LogCallbackException("前台窗口兜底轮询获取当前前台窗口", ex);
Helpers.LogService.LogException(ex);
}
}

Expand All @@ -284,10 +284,9 @@ public void Dispose()

if (_foregroundHook != HWINEVENTHOOK.Null)
{
try { PInvoke.UnhookWinEvent(_foregroundHook); }
catch (Exception ex)
try { PInvoke.UnhookWinEvent(_foregroundHook); } catch (Exception ex)
{
LogHelper.WriteLogToFile($"[Automation] SystemEventMonitor 释放时卸载前台窗口 WinEvent 钩子失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
_foregroundHook = HWINEVENTHOOK.Null;
}
Expand Down
8 changes: 4 additions & 4 deletions Ink Canvas/Automation/Triggers/AnnotationModeEnterTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ private void TrySubscribeInkCanvas()
mw.inkCanvas.EditingModeChanged += OnEditingModeChanged;
}
}
catch (Exception ex)
catch (System.Exception ex)
{
LogHelper.WriteLogToFile($"[Automation] 批注模式进入触发器订阅 inkCanvas.EditingModeChanged 失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}

Expand All @@ -81,9 +81,9 @@ private void TryUnsubscribeInkCanvas()
mw.inkCanvas.EditingModeChanged -= OnEditingModeChanged;
}
}
catch (Exception ex)
catch (System.Exception ex)
{
LogHelper.WriteLogToFile($"[Automation] 批注模式进入触发器退订 inkCanvas.EditingModeChanged 失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}

Expand Down
8 changes: 4 additions & 4 deletions Ink Canvas/Automation/Triggers/AnnotationModeExitTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ private void TrySubscribeInkCanvas()
mw.inkCanvas.EditingModeChanged += OnEditingModeChanged;
}
}
catch (Exception ex)
catch (System.Exception ex)
{
LogHelper.WriteLogToFile($"[Automation] 批注模式退出触发器订阅 inkCanvas.EditingModeChanged 失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}

Expand All @@ -81,9 +81,9 @@ private void TryUnsubscribeInkCanvas()
mw.inkCanvas.EditingModeChanged -= OnEditingModeChanged;
}
}
catch (Exception ex)
catch (System.Exception ex)
{
LogHelper.WriteLogToFile($"[Automation] 批注模式退出触发器退订 inkCanvas.EditingModeChanged 失败: {ex.Message}", LogHelper.LogType.Info);
Helpers.LogService.LogException(ex);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Ink Canvas/Automation/Triggers/PptSlideShowEnterTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ private static bool IsPowerPointInSlideShow()
return true;
}
}
catch (Exception ex)
catch (System.Exception ex)
{
LogCallbackException("读取 POWERPNT 进程主窗口标题判断是否处于放映", ex);
Helpers.LogService.LogException(ex);
}
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions Ink Canvas/Automation/Triggers/PptSlideShowExitTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ private static bool IsPowerPointInSlideShow()
return true;
}
}
catch (Exception ex)
catch (System.Exception ex)
{
LogCallbackException("读取 POWERPNT 进程主窗口标题判断是否处于放映", ex);
Helpers.LogService.LogException(ex);
}
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions Ink Canvas/Automation/Triggers/PptSlideShowTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ private static bool IsPowerPointInSlideShow()
return true;
}
}
catch (Exception ex)
catch (System.Exception ex)
{
LogCallbackException("读取 POWERPNT 进程主窗口标题判断是否处于放映", ex);
Helpers.LogService.LogException(ex);
}
}
return false;
Expand Down
Loading