improve:ROT联动
This commit is contained in:
@@ -50,6 +50,10 @@ namespace Ink_Canvas.Helpers
|
|||||||
public void StartMonitoring() => _inner.StartMonitoring();
|
public void StartMonitoring() => _inner.StartMonitoring();
|
||||||
|
|
||||||
public void StopMonitoring() => _inner.StopMonitoring();
|
public void StopMonitoring() => _inner.StopMonitoring();
|
||||||
|
|
||||||
|
public void ReloadConnection()
|
||||||
|
{
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 放映控制
|
#region 放映控制
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ namespace Ink_Canvas.Helpers
|
|||||||
void StartMonitoring();
|
void StartMonitoring();
|
||||||
void StopMonitoring();
|
void StopMonitoring();
|
||||||
|
|
||||||
|
void ReloadConnection();
|
||||||
|
|
||||||
// 放映控制
|
// 放映控制
|
||||||
bool TryStartSlideShow();
|
bool TryStartSlideShow();
|
||||||
bool TryEndSlideShow();
|
bool TryEndSlideShow();
|
||||||
|
|||||||
@@ -209,6 +209,13 @@ namespace Ink_Canvas.Helpers
|
|||||||
DisconnectFromPPT();
|
DisconnectFromPPT();
|
||||||
LogHelper.WriteLogToFile("[ROT] PPT 监控已停止", LogHelper.LogType.Trace);
|
LogHelper.WriteLogToFile("[ROT] PPT 监控已停止", LogHelper.LogType.Trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ReloadConnection()
|
||||||
|
{
|
||||||
|
if (_disposed) return;
|
||||||
|
LogHelper.WriteLogToFile("[ROT] 执行热重载:强制断开并重新连接", LogHelper.LogType.Event);
|
||||||
|
DisconnectFromPPT();
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Connection Management
|
#region Connection Management
|
||||||
@@ -246,6 +253,12 @@ namespace Ink_Canvas.Helpers
|
|||||||
{
|
{
|
||||||
if (_isModuleUnloading) return;
|
if (_isModuleUnloading) return;
|
||||||
|
|
||||||
|
if (_pptApplication != null && !IsConnected)
|
||||||
|
{
|
||||||
|
DisconnectFromPPT();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lock (_lockObject)
|
lock (_lockObject)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -440,18 +453,18 @@ namespace Ink_Canvas.Helpers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
System.Threading.Thread.Sleep(2000);
|
System.Threading.Thread.Sleep(300);
|
||||||
|
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
GC.WaitForPendingFinalizers();
|
GC.WaitForPendingFinalizers();
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
|
|
||||||
System.Threading.Thread.Sleep(1000);
|
System.Threading.Thread.Sleep(200);
|
||||||
|
|
||||||
_isModuleUnloading = false;
|
_isModuleUnloading = false;
|
||||||
_unifiedRotTimer?.Start();
|
_unifiedRotTimer?.Start();
|
||||||
|
|
||||||
LogHelper.WriteLogToFile("[ROT] PPT 联动模块已重新进入联动状态", LogHelper.LogType.Trace);
|
LogHelper.WriteLogToFile("[ROT] PPT 联动模块已重新进入联动状态(热重载)", LogHelper.LogType.Trace);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -123,13 +123,28 @@ namespace Ink_Canvas
|
|||||||
// 初始化长按定时器
|
// 初始化长按定时器
|
||||||
InitializeLongPressTimer();
|
InitializeLongPressTimer();
|
||||||
|
|
||||||
// 如有旧实例,先停止监控,避免重复
|
// 完全清理旧模式
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_pptManager?.StopMonitoring();
|
_pptManager?.StopMonitoring();
|
||||||
|
_pptManager?.Dispose();
|
||||||
|
_pptManager = null;
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
LogHelper.WriteLogToFile($"清理旧 PPT 管理器异常: {ex}", LogHelper.LogType.Warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StopPowerPointProcessMonitoring();
|
||||||
|
_powerPointProcessMonitorTimer = null;
|
||||||
|
ClosePowerPointApplication();
|
||||||
|
ClearStaticInteropState();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogHelper.WriteLogToFile($"清理 Interop 状态异常: {ex}", LogHelper.LogType.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据设置选择 COM / ROT 架构
|
// 根据设置选择 COM / ROT 架构
|
||||||
@@ -202,6 +217,7 @@ namespace Ink_Canvas
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!Settings.PowerPointSettings.EnablePowerPointEnhancement) return;
|
if (!Settings.PowerPointSettings.EnablePowerPointEnhancement) return;
|
||||||
|
if (Settings.PowerPointSettings.UseRotPptLink) return;
|
||||||
|
|
||||||
// 创建PowerPoint应用程序实例
|
// 创建PowerPoint应用程序实例
|
||||||
CreatePowerPointApplication();
|
CreatePowerPointApplication();
|
||||||
@@ -251,6 +267,7 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (Settings.PowerPointSettings.UseRotPptLink) return;
|
||||||
// 如果应用程序已存在且有效,则不重复创建
|
// 如果应用程序已存在且有效,则不重复创建
|
||||||
if (pptApplication != null && IsPowerPointApplicationValid())
|
if (pptApplication != null && IsPowerPointApplicationValid())
|
||||||
{
|
{
|
||||||
@@ -304,6 +321,7 @@ namespace Ink_Canvas
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_pptManager == null) return;
|
if (_pptManager == null) return;
|
||||||
|
if (Settings.PowerPointSettings.UseRotPptLink) return;
|
||||||
|
|
||||||
// 使用反射调用PPTManager的ConnectToPPT方法
|
// 使用反射调用PPTManager的ConnectToPPT方法
|
||||||
var pptManagerType = _pptManager.GetType();
|
var pptManagerType = _pptManager.GetType();
|
||||||
@@ -398,11 +416,40 @@ namespace Ink_Canvas
|
|||||||
pptApplication = null;
|
pptApplication = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClearStaticInteropState();
|
||||||
LogHelper.WriteLogToFile("PowerPoint应用程序已关闭", LogHelper.LogType.Event);
|
LogHelper.WriteLogToFile("PowerPoint应用程序已关闭", LogHelper.LogType.Event);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogHelper.WriteLogToFile($"关闭PowerPoint应用程序失败: {ex}", LogHelper.LogType.Error);
|
LogHelper.WriteLogToFile($"关闭PowerPoint应用程序失败: {ex}", LogHelper.LogType.Error);
|
||||||
|
ClearStaticInteropState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClearStaticInteropState()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (presentation != null)
|
||||||
|
{
|
||||||
|
try { if (Marshal.IsComObject(presentation)) Marshal.ReleaseComObject(presentation); } catch { }
|
||||||
|
presentation = null;
|
||||||
|
}
|
||||||
|
if (slides != null)
|
||||||
|
{
|
||||||
|
try { if (Marshal.IsComObject(slides)) Marshal.ReleaseComObject(slides); } catch { }
|
||||||
|
slides = null;
|
||||||
|
}
|
||||||
|
if (slide != null)
|
||||||
|
{
|
||||||
|
try { if (Marshal.IsComObject(slide)) Marshal.ReleaseComObject(slide); } catch { }
|
||||||
|
slide = null;
|
||||||
|
}
|
||||||
|
slidescount = 0;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogHelper.WriteLogToFile($"ClearStaticInteropState 异常: {ex}", LogHelper.LogType.Warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,6 +465,7 @@ namespace Ink_Canvas
|
|||||||
StopPowerPointProcessMonitoring();
|
StopPowerPointProcessMonitoring();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (Settings.PowerPointSettings.UseRotPptLink) return;
|
||||||
|
|
||||||
// 检查应用程序是否还在运行
|
// 检查应用程序是否还在运行
|
||||||
if (!IsPowerPointApplicationValid())
|
if (!IsPowerPointApplicationValid())
|
||||||
@@ -437,6 +485,7 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_pptManager?.StopMonitoring();
|
||||||
_pptManager?.Dispose();
|
_pptManager?.Dispose();
|
||||||
_singlePPTInkManager?.Dispose();
|
_singlePPTInkManager?.Dispose();
|
||||||
_longPressTimer?.Stop();
|
_longPressTimer?.Stop();
|
||||||
@@ -448,6 +497,8 @@ namespace Ink_Canvas
|
|||||||
// 清理PowerPoint进程守护
|
// 清理PowerPoint进程守护
|
||||||
StopPowerPointProcessMonitoring();
|
StopPowerPointProcessMonitoring();
|
||||||
_powerPointProcessMonitorTimer = null;
|
_powerPointProcessMonitorTimer = null;
|
||||||
|
ClosePowerPointApplication();
|
||||||
|
ClearStaticInteropState();
|
||||||
|
|
||||||
LogHelper.WriteLogToFile("PPT管理器已释放", LogHelper.LogType.Event);
|
LogHelper.WriteLogToFile("PPT管理器已释放", LogHelper.LogType.Event);
|
||||||
}
|
}
|
||||||
@@ -1329,11 +1380,10 @@ namespace Ink_Canvas
|
|||||||
InitializePPTManagers();
|
InitializePPTManagers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手动触发一次连接检查
|
_pptManager?.ReloadConnection();
|
||||||
_pptManager?.StartMonitoring();
|
_pptManager?.StartMonitoring();
|
||||||
|
|
||||||
// 等待一小段时间让连接建立
|
Task.Delay(800).ContinueWith(_ =>
|
||||||
Task.Delay(500).ContinueWith(_ =>
|
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user