Files
community/Ink Canvas/MainWindow_cs/MW_Timer.cs
T

654 lines
32 KiB
C#
Raw Normal View History

2025-08-31 11:43:52 +08:00
using Ink_Canvas.Helpers;
using System;
2025-05-25 09:29:48 +08:00
using System.ComponentModel;
using System.Diagnostics;
2025-06-19 11:47:16 +08:00
using System.IO;
2025-07-28 14:40:44 +08:00
using System.Linq;
using System.Net;
using System.Net.Sockets;
2025-06-19 11:47:16 +08:00
using System.Reflection;
2025-07-28 14:40:44 +08:00
using System.Runtime.CompilerServices;
2025-06-19 11:47:16 +08:00
using System.Threading.Tasks;
2025-07-28 14:40:44 +08:00
using System.Timers;
using System.Windows;
2025-06-29 11:56:38 +08:00
using System.Windows.Controls;
2025-05-25 09:29:48 +08:00
2025-08-03 16:46:33 +08:00
namespace Ink_Canvas
{
public class TimeViewModel : INotifyPropertyChanged
{
2025-05-25 09:29:48 +08:00
private string _nowTime;
private string _nowDate;
2025-08-03 16:46:33 +08:00
public string nowTime
{
2025-05-25 09:29:48 +08:00
get => _nowTime;
2025-08-03 16:46:33 +08:00
set
{
if (_nowTime != value)
{
2025-05-25 09:29:48 +08:00
_nowTime = value;
OnPropertyChanged();
}
}
}
2025-08-03 16:46:33 +08:00
public string nowDate
{
2025-05-25 09:29:48 +08:00
get => _nowDate;
2025-08-03 16:46:33 +08:00
set
{
if (_nowDate != value)
{
2025-05-25 09:29:48 +08:00
_nowDate = value;
OnPropertyChanged();
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
2025-08-03 16:46:33 +08:00
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
2025-05-25 09:29:48 +08:00
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
2025-08-03 16:46:33 +08:00
public partial class MainWindow : Window
{
2025-05-25 09:29:48 +08:00
private Timer timerCheckPPT = new Timer();
private Timer timerKillProcess = new Timer();
private Timer timerCheckAutoFold = new Timer();
2025-07-28 14:40:44 +08:00
private string AvailableLatestVersion;
2025-05-25 09:29:48 +08:00
private Timer timerCheckAutoUpdateWithSilence = new Timer();
2025-07-28 14:40:44 +08:00
private bool isHidingSubPanelsWhenInking; // 避免书写时触发二次关闭二级菜单导致动画不连续
2025-05-25 09:29:48 +08:00
private Timer timerDisplayTime = new Timer();
private Timer timerDisplayDate = new Timer();
private TimeViewModel nowTimeVM = new TimeViewModel();
2025-07-22 16:12:42 +08:00
private async Task<DateTime> GetNetworkTimeAsync()
{
try
{
const string ntpServer = "ntp.ntsc.ac.cn";
var ntpData = new byte[48];
ntpData[0] = 0x1B;
var addresses = await Dns.GetHostAddressesAsync(ntpServer);
var ipEndPoint = new IPEndPoint(addresses[0], 123);
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
{
socket.ReceiveTimeout = 2000;
socket.Connect(ipEndPoint);
await Task.Factory.FromAsync(socket.BeginSend(ntpData, 0, ntpData.Length, SocketFlags.None, null, socket), socket.EndSend);
await Task.Factory.FromAsync(socket.BeginReceive(ntpData, 0, ntpData.Length, SocketFlags.None, null, socket), socket.EndReceive);
}
const byte serverReplyTime = 40;
ulong intPart = BitConverter.ToUInt32(ntpData.Skip(serverReplyTime).Take(4).Reverse().ToArray(), 0);
ulong fractPart = BitConverter.ToUInt32(ntpData.Skip(serverReplyTime + 4).Take(4).Reverse().ToArray(), 0);
var milliseconds = (intPart * 1000) + ((fractPart * 1000) / 0x100000000L);
var networkDateTime = (new DateTime(1900, 1, 1)).AddMilliseconds((long)milliseconds);
return networkDateTime.ToLocalTime();
}
catch
{
return DateTime.Now;
}
}
2025-08-01 02:56:24 +08:00
// 修改InitTimers方法中的初始时间和日期格式
2025-08-03 16:46:33 +08:00
private void InitTimers()
{
2025-07-29 01:15:32 +08:00
// PPT检查现在由PPTManager处理,不再需要定时器
// timerCheckPPT.Elapsed += TimerCheckPPT_Elapsed;
// timerCheckPPT.Interval = 500;
2025-05-25 09:29:48 +08:00
timerKillProcess.Elapsed += TimerKillProcess_Elapsed;
timerKillProcess.Interval = 2000;
timerCheckAutoFold.Elapsed += timerCheckAutoFold_Elapsed;
timerCheckAutoFold.Interval = 500;
timerCheckAutoUpdateWithSilence.Elapsed += timerCheckAutoUpdateWithSilence_Elapsed;
timerCheckAutoUpdateWithSilence.Interval = 1000 * 60 * 10;
WaterMarkTime.DataContext = nowTimeVM;
WaterMarkDate.DataContext = nowTimeVM;
2025-07-22 16:12:42 +08:00
timerDisplayTime.Elapsed += async (s, e) => await TimerDisplayTime_ElapsedAsync();
2025-05-25 09:29:48 +08:00
timerDisplayTime.Interval = 1000;
timerDisplayTime.Start();
timerDisplayDate.Elapsed += TimerDisplayDate_Elapsed;
timerDisplayDate.Interval = 1000 * 60 * 60 * 1;
timerDisplayDate.Start();
timerKillProcess.Start();
2025-08-01 02:56:24 +08:00
nowTimeVM.nowDate = DateTime.Now.ToString("yyyy'年'MM'月'dd'日' dddd");
nowTimeVM.nowTime = DateTime.Now.ToString("tt hh'时'mm'分'ss'秒'");
2025-05-25 09:29:48 +08:00
}
2025-09-06 15:09:34 +08:00
// 修改TimerDisplayTime_ElapsedAsync方法中的时间格式,实现校验制
2025-07-22 16:12:42 +08:00
private async Task TimerDisplayTime_ElapsedAsync()
{
2025-09-06 15:09:34 +08:00
DateTime localTime = DateTime.Now;
DateTime displayTime = localTime; // 默认使用本地时间
try
{
DateTime networkTime = await GetNetworkTimeAsync();
// 计算时间差
TimeSpan timeDifference = networkTime - localTime;
double timeDifferenceMinutes = Math.Abs(timeDifference.TotalMinutes);
// 如果网络时间与本地时间相差不超过1分钟,则使用本地时间
// 否则使用网络时间
displayTime = timeDifferenceMinutes <= 1.0 ? localTime : networkTime;
}
catch
{
// 网络时间获取失败时,使用本地时间
displayTime = localTime;
}
2025-07-22 16:12:42 +08:00
// 只更新时间,日期由原有逻辑定时更新即可
Dispatcher.Invoke(() =>
{
2025-09-06 15:09:34 +08:00
nowTimeVM.nowTime = displayTime.ToString("tt hh'时'mm'分'ss'秒'");
2025-07-22 16:12:42 +08:00
});
2025-05-25 09:29:48 +08:00
}
2025-08-01 02:56:24 +08:00
// 修改TimerDisplayDate_Elapsed方法中的日期格式
2025-08-03 16:46:33 +08:00
private void TimerDisplayDate_Elapsed(object sender, ElapsedEventArgs e)
{
2025-08-01 02:56:24 +08:00
nowTimeVM.nowDate = DateTime.Now.ToString("yyyy'年'MM'月'dd'日' dddd");
2025-05-25 09:29:48 +08:00
}
2025-08-03 16:46:33 +08:00
private void TimerKillProcess_Elapsed(object sender, ElapsedEventArgs e)
{
try
{
2025-05-25 09:29:48 +08:00
// 希沃相关: easinote swenserver RemoteProcess EasiNote.MediaHttpService smartnote.cloud EasiUpdate smartnote EasiUpdate3 EasiUpdate3Protect SeewoP2P CefSharp.BrowserSubprocess SeewoUploadService
var arg = "/F";
2025-08-03 16:46:33 +08:00
if (Settings.Automation.IsAutoKillPptService)
{
2025-05-25 09:29:48 +08:00
var processes = Process.GetProcessesByName("PPTService");
if (processes.Length > 0) arg += " /IM PPTService.exe";
processes = Process.GetProcessesByName("SeewoIwbAssistant");
if (processes.Length > 0) arg += " /IM SeewoIwbAssistant.exe" + " /IM Sia.Guard.exe";
}
2025-08-03 16:46:33 +08:00
if (Settings.Automation.IsAutoKillEasiNote)
{
2025-05-25 09:29:48 +08:00
var processes = Process.GetProcessesByName("EasiNote");
if (processes.Length > 0) arg += " /IM EasiNote.exe";
}
2025-08-03 16:46:33 +08:00
if (Settings.Automation.IsAutoKillHiteAnnotation)
{
2025-05-25 09:29:48 +08:00
var processes = Process.GetProcessesByName("HiteAnnotation");
if (processes.Length > 0) arg += " /IM HiteAnnotation.exe";
}
if (Settings.Automation.IsAutoKillVComYouJiao)
{
var processes = Process.GetProcessesByName("VcomTeach");
if (processes.Length > 0) arg += " /IM VcomTeach.exe" + " /IM VcomDaemon.exe" + " /IM VcomRender.exe";
}
2025-08-03 16:46:33 +08:00
if (Settings.Automation.IsAutoKillICA)
{
2025-05-25 09:29:48 +08:00
var processesAnnotation = Process.GetProcessesByName("Ink Canvas Annotation");
var processesArtistry = Process.GetProcessesByName("Ink Canvas Artistry");
if (processesAnnotation.Length > 0) arg += " /IM \"Ink Canvas Annotation.exe\"";
if (processesArtistry.Length > 0) arg += " /IM \"Ink Canvas Artistry.exe\"";
}
2025-08-03 16:46:33 +08:00
if (Settings.Automation.IsAutoKillInkCanvas)
{
2025-05-25 09:29:48 +08:00
var processes = Process.GetProcessesByName("Ink Canvas");
if (processes.Length > 0) arg += " /IM \"Ink Canvas.exe\"";
}
2025-08-03 16:46:33 +08:00
if (Settings.Automation.IsAutoKillIDT)
{
2025-06-08 10:12:35 +08:00
var processes = Process.GetProcessesByName("Inkeys");
if (processes.Length > 0) arg += " /IM \"Inkeys.exe\"";
2025-05-25 09:29:48 +08:00
}
2025-08-03 16:46:33 +08:00
if (Settings.Automation.IsAutoKillSeewoLauncher2DesktopAnnotation)
{
2025-05-25 09:29:48 +08:00
//由于希沃桌面2.0提供的桌面批注是64位应用程序,32位程序无法访问,目前暂不做精准匹配,只匹配进程名称,后面会考虑封装一套基于P/Invoke和WMI的综合进程识别方案。
var processes = Process.GetProcessesByName("DesktopAnnotation");
if (processes.Length > 0) arg += " /IM DesktopAnnotation.exe";
}
2025-08-03 16:46:33 +08:00
if (arg != "/F")
{
2025-05-25 09:29:48 +08:00
var p = new Process();
p.StartInfo = new ProcessStartInfo("taskkill", arg);
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
2025-08-03 16:46:33 +08:00
if (arg.Contains("EasiNote"))
{
Dispatcher.Invoke(() =>
{
2025-05-25 09:29:48 +08:00
ShowNotification("“希沃白板 5”已自动关闭");
});
}
2025-08-03 16:46:33 +08:00
if (arg.Contains("HiteAnnotation"))
{
Dispatcher.Invoke(() =>
{
2025-05-25 09:29:48 +08:00
ShowNotification("“鸿合屏幕书写”已自动关闭");
2025-08-03 16:46:33 +08:00
if (Settings.Automation.IsAutoKillHiteAnnotation && Settings.Automation.IsAutoEnterAnnotationAfterKillHite)
{
// 自动进入批注状态
PenIcon_Click(null, null);
}
2025-05-25 09:29:48 +08:00
});
}
2025-08-03 16:46:33 +08:00
if (arg.Contains("Ink Canvas Annotation") || arg.Contains("Ink Canvas Artistry"))
{
Dispatcher.Invoke(() =>
{
2025-05-25 09:29:48 +08:00
ShowNewMessage("“ICA”已自动关闭");
});
}
2025-08-03 16:46:33 +08:00
if (arg.Contains("\"Ink Canvas.exe\""))
{
Dispatcher.Invoke(() =>
{
2025-05-25 09:29:48 +08:00
ShowNotification("“Ink Canvas”已自动关闭");
});
}
2025-08-03 16:46:33 +08:00
if (arg.Contains("Inkeys"))
{
Dispatcher.Invoke(() =>
{
2025-06-08 10:12:35 +08:00
ShowNotification("“智绘教Inkeys”已自动关闭");
2025-05-25 09:29:48 +08:00
});
}
if (arg.Contains("VcomTeach"))
{
2025-08-03 16:46:33 +08:00
Dispatcher.Invoke(() =>
{
2025-05-25 09:29:48 +08:00
ShowNotification("“优教授课端”已自动关闭");
});
}
if (arg.Contains("DesktopAnnotation"))
{
2025-08-03 16:46:33 +08:00
Dispatcher.Invoke(() =>
{
2025-06-08 10:12:35 +08:00
ShowNotification("“希沃桌面2.0 桌面批注”已自动关闭");
2025-05-25 09:29:48 +08:00
});
}
}
}
2025-08-03 16:46:33 +08:00
catch { }
2025-05-25 09:29:48 +08:00
}
2025-07-28 14:40:44 +08:00
private bool foldFloatingBarByUser, // 保持收纳操作不受自动收纳的控制
unfoldFloatingBarByUser; // 允许用户在希沃软件内进行展开操作
2025-05-25 09:29:48 +08:00
2025-09-06 15:16:03 +08:00
/// <summary>
/// 检测是否为批注窗口(窗口标题为空且高度小于500像素)
/// </summary>
/// <returns>如果是批注窗口返回true,否则返回false</returns>
private bool IsAnnotationWindow()
{
var windowTitle = ForegroundWindowInfo.WindowTitle();
var windowRect = ForegroundWindowInfo.WindowRect();
return windowTitle.Length == 0 && windowRect.Height < 500;
}
2025-08-03 16:46:33 +08:00
private void timerCheckAutoFold_Elapsed(object sender, ElapsedEventArgs e)
{
2025-05-25 09:29:48 +08:00
if (isFloatingBarChangingHideMode) return;
2025-08-03 16:46:33 +08:00
try
{
2025-05-25 09:29:48 +08:00
var windowProcessName = ForegroundWindowInfo.ProcessName();
var windowTitle = ForegroundWindowInfo.WindowTitle();
//LogHelper.WriteLogToFile("windowTitle | " + windowTitle + " | windowProcessName | " + windowProcessName);
2025-08-03 16:46:33 +08:00
if (windowProcessName == "EasiNote")
{
2025-05-25 09:29:48 +08:00
// 检测到有可能是EasiNote5或者EasiNote3/3C
2025-08-03 16:46:33 +08:00
if (ForegroundWindowInfo.ProcessPath() != "Unknown")
{
2025-05-25 09:29:48 +08:00
var versionInfo = FileVersionInfo.GetVersionInfo(ForegroundWindowInfo.ProcessPath());
string version = versionInfo.FileVersion;
string prodName = versionInfo.ProductName;
Trace.WriteLine(ForegroundWindowInfo.ProcessPath());
Trace.WriteLine(version);
Trace.WriteLine(prodName);
if (version.StartsWith("5.") && Settings.Automation.IsAutoFoldInEasiNote && (!(windowTitle.Length == 0 && ForegroundWindowInfo.WindowRect().Height < 500) ||
2025-08-03 16:46:33 +08:00
!Settings.Automation.IsAutoFoldInEasiNoteIgnoreDesktopAnno))
{ // EasiNote5
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
2025-08-03 16:46:33 +08:00
}
else if (version.StartsWith("3.") && Settings.Automation.IsAutoFoldInEasiNote3)
{ // EasiNote3
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
2025-08-03 16:46:33 +08:00
}
else if (prodName.Contains("3C") && Settings.Automation.IsAutoFoldInEasiNote3C &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{ // EasiNote3C
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
}
}
// EasiCamera
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInEasiCamera && windowProcessName == "EasiCamera" &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
2025-09-06 15:16:03 +08:00
// 检测到批注窗口时保持收纳状态
if (IsAnnotationWindow())
{
// 批注窗口打开时,如果当前是展开状态则收纳
if (!isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
}
else
{
// 非批注窗口时正常处理
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
}
2025-05-25 09:29:48 +08:00
// EasiNote5C
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInEasiNote5C && windowProcessName == "EasiNote5C" &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
// SeewoPinco
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInSeewoPincoTeacher && (windowProcessName == "BoardService" || windowProcessName == "seewoPincoTeacher"))
{
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
// HiteCamera
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInHiteCamera && windowProcessName == "HiteCamera" &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
2025-09-06 15:16:03 +08:00
// 检测到批注窗口时保持收纳状态
if (IsAnnotationWindow())
{
// 批注窗口打开时,如果当前是展开状态则收纳
if (!isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
}
else
{
// 非批注窗口时正常处理
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
}
2025-05-25 09:29:48 +08:00
// HiteTouchPro
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInHiteTouchPro && windowProcessName == "HiteTouchPro" &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
2025-09-06 15:16:03 +08:00
// 检测到批注窗口时保持收纳状态
if (IsAnnotationWindow())
{
// 批注窗口打开时,如果当前是展开状态则收纳
if (!isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
}
else
{
// 非批注窗口时正常处理
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
}
2025-05-25 09:29:48 +08:00
// WxBoardMain
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInWxBoardMain && windowProcessName == "WxBoardMain" &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
// MSWhiteboard
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInMSWhiteboard && (windowProcessName == "MicrosoftWhiteboard" ||
windowProcessName == "msedgewebview2"))
{
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
// OldZyBoard
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInOldZyBoard && // 中原旧白板
2025-05-25 09:29:48 +08:00
(WinTabWindowsChecker.IsWindowExisted("WhiteBoard - DrawingWindow")
2025-08-03 16:46:33 +08:00
|| WinTabWindowsChecker.IsWindowExisted("InstantAnnotationWindow")))
{
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
// HiteLightBoard
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInHiteLightBoard && windowProcessName == "HiteLightBoard" &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
2025-09-06 15:16:03 +08:00
// 检测到批注窗口时保持收纳状态
if (IsAnnotationWindow())
{
// 批注窗口打开时,如果当前是展开状态则收纳
if (!isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
}
else
{
// 非批注窗口时正常处理
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
}
2025-05-25 09:29:48 +08:00
// AdmoxWhiteboard
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInAdmoxWhiteboard && windowProcessName == "Amdox.WhiteBoard" &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
// AdmoxBooth
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInAdmoxBooth && windowProcessName == "Amdox.Booth" &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
// QPoint
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInQPoint && windowProcessName == "QPoint" &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
// YiYunVisualPresenter
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInYiYunVisualPresenter && windowProcessName == "YiYunVisualPresenter" &&
2025-05-25 09:29:48 +08:00
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
2025-05-25 09:29:48 +08:00
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
// MaxHubWhiteboard
2025-08-03 16:46:33 +08:00
}
else if (Settings.Automation.IsAutoFoldInMaxHubWhiteboard && windowProcessName == "WhiteBoard" &&
2025-05-25 09:29:48 +08:00
WinTabWindowsChecker.IsWindowExisted("白板书写") &&
ForegroundWindowInfo.WindowRect().Height >= SystemParameters.WorkArea.Height - 16 &&
2025-08-03 16:46:33 +08:00
ForegroundWindowInfo.WindowRect().Width >= SystemParameters.WorkArea.Width - 16)
{
if (ForegroundWindowInfo.ProcessPath() != "Unknown")
{
2025-05-25 09:29:48 +08:00
var versionInfo = FileVersionInfo.GetVersionInfo(ForegroundWindowInfo.ProcessPath());
var version = versionInfo.FileVersion; var prodName = versionInfo.ProductName;
2025-08-03 16:46:33 +08:00
if (version.StartsWith("6.") && prodName == "WhiteBoard") if (!unfoldFloatingBarByUser && !isFloatingBarFolded) FoldFloatingBar_MouseUp(null, null);
2025-05-25 09:29:48 +08:00
}
2025-08-03 16:46:33 +08:00
}
else if (WinTabWindowsChecker.IsWindowExisted("幻灯片放映", false))
{
2025-05-25 09:29:48 +08:00
// 处于幻灯片放映状态
if (!Settings.Automation.IsAutoFoldInPPTSlideShow && isFloatingBarFolded && !foldFloatingBarByUser)
UnFoldFloatingBar_MouseUp(new object(), null);
2025-08-03 16:46:33 +08:00
}
else
{
2025-05-25 09:29:48 +08:00
if (isFloatingBarFolded && !foldFloatingBarByUser) UnFoldFloatingBar_MouseUp(new object(), null);
unfoldFloatingBarByUser = false;
}
}
catch { }
}
2025-08-03 16:46:33 +08:00
private void timerCheckAutoUpdateWithSilence_Elapsed(object sender, ElapsedEventArgs e)
{
2025-06-19 11:47:16 +08:00
// 停止计时器,避免重复触发
timerCheckAutoUpdateWithSilence.Stop();
2025-08-03 16:46:33 +08:00
try
{
2025-06-19 11:47:16 +08:00
// 检查是否有可用的更新
2025-08-03 16:46:33 +08:00
if (string.IsNullOrEmpty(AvailableLatestVersion))
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile("AutoUpdate | No available update version found");
return;
2025-05-25 09:29:48 +08:00
}
2025-08-03 16:46:33 +08:00
2025-06-19 11:47:16 +08:00
// 检查是否启用了静默更新
2025-08-03 16:46:33 +08:00
if (!Settings.Startup.IsAutoUpdateWithSilence)
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile("AutoUpdate | Silent update is disabled");
return;
2025-05-25 09:29:48 +08:00
}
2025-08-03 16:46:33 +08:00
2025-06-19 11:47:16 +08:00
// 检查更新文件是否已下载
string updatesFolderPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "AutoUpdate");
string statusFilePath = Path.Combine(updatesFolderPath, $"DownloadV{AvailableLatestVersion}Status.txt");
2025-08-03 16:46:33 +08:00
if (!File.Exists(statusFilePath) || File.ReadAllText(statusFilePath).Trim().ToLower() != "true")
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile("AutoUpdate | Update file not downloaded yet");
2025-08-03 16:46:33 +08:00
2025-07-19 16:03:45 +08:00
// 尝试下载更新文件,使用多线路组下载功能
2025-08-03 16:46:33 +08:00
Task.Run(async () =>
{
2025-07-19 15:36:05 +08:00
bool isDownloadSuccessful = false;
2025-08-03 16:46:33 +08:00
2025-07-19 16:03:45 +08:00
try
2025-07-19 15:36:05 +08:00
{
2025-07-19 16:03:45 +08:00
// 如果主要线路组可用,直接使用
if (AvailableLatestLineGroup != null)
{
LogHelper.WriteLogToFile($"AutoUpdate | 使用主要线路组下载: {AvailableLatestLineGroup.GroupName}");
isDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFile(AvailableLatestVersion, AvailableLatestLineGroup);
}
2025-08-03 16:46:33 +08:00
2025-07-19 16:03:45 +08:00
// 如果主要线路组不可用或下载失败,获取所有可用线路组
if (!isDownloadSuccessful)
{
LogHelper.WriteLogToFile("AutoUpdate | 主要线路组不可用或下载失败,获取所有可用线路组");
var availableGroups = await AutoUpdateHelper.GetAvailableLineGroupsOrdered(Settings.Startup.UpdateChannel);
if (availableGroups.Count > 0)
{
LogHelper.WriteLogToFile($"AutoUpdate | 使用 {availableGroups.Count} 个可用线路组进行下载");
isDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFileWithFallback(AvailableLatestVersion, availableGroups);
}
}
2025-07-19 15:36:05 +08:00
}
2025-07-19 16:03:45 +08:00
catch (Exception ex)
{
LogHelper.WriteLogToFile($"AutoUpdate | 下载更新时出错: {ex.Message}", LogHelper.LogType.Error);
}
2025-08-03 16:46:33 +08:00
if (isDownloadSuccessful)
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile("AutoUpdate | Update downloaded successfully, will check again for installation");
// 重新启动计时器,下次检查时安装
timerCheckAutoUpdateWithSilence.Start();
2025-08-03 16:46:33 +08:00
}
else
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile("AutoUpdate | Failed to download update", LogHelper.LogType.Error);
}
});
2025-08-03 16:46:33 +08:00
2025-06-19 11:47:16 +08:00
return;
}
2025-08-03 16:46:33 +08:00
2025-06-19 11:47:16 +08:00
// 检查是否在静默更新时间段内
bool isInSilencePeriod = AutoUpdateWithSilenceTimeComboBox.CheckIsInSilencePeriod(
Settings.Startup.AutoUpdateWithSilenceStartTime,
Settings.Startup.AutoUpdateWithSilenceEndTime);
2025-08-03 16:46:33 +08:00
if (!isInSilencePeriod)
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile("AutoUpdate | Not in silence update time period");
// 重新启动计时器,稍后再检查
timerCheckAutoUpdateWithSilence.Start();
return;
}
2025-08-03 16:46:33 +08:00
2025-06-29 11:56:38 +08:00
// 检查应用程序状态,确保可以安全更新
// 空闲状态的判定为不处于批注模式和画板模式
2025-06-19 11:47:16 +08:00
bool canSafelyUpdate = false;
2025-08-03 16:46:33 +08:00
Dispatcher.Invoke(() =>
{
try
{
2025-06-29 11:56:38 +08:00
// 判断是否处于批注模式(inkCanvas.EditingMode == InkCanvasEditingMode.Ink
// 判断是否处于画板模式(!Topmost)
2025-08-03 16:46:33 +08:00
if (inkCanvas.EditingMode != InkCanvasEditingMode.Ink && Topmost)
{
2025-06-19 11:47:16 +08:00
// 检查是否有未保存的内容或正在进行的操作
2025-08-03 16:46:33 +08:00
if (!isHidingSubPanelsWhenInking)
{
2025-06-19 11:47:16 +08:00
canSafelyUpdate = true;
2025-06-29 11:56:38 +08:00
LogHelper.WriteLogToFile("AutoUpdate | Application is in a safe state for update - not in ink or board mode");
2025-08-03 16:46:33 +08:00
}
else
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile("AutoUpdate | Application is currently performing operations");
}
2025-08-03 16:46:33 +08:00
}
else
{
2025-06-29 11:56:38 +08:00
LogHelper.WriteLogToFile("AutoUpdate | Application is in ink or board mode, cannot update now");
2025-06-19 11:47:16 +08:00
}
}
2025-08-03 16:46:33 +08:00
catch (Exception ex)
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile($"AutoUpdate | Error checking application state: {ex.Message}", LogHelper.LogType.Error);
}
});
2025-08-03 16:46:33 +08:00
if (canSafelyUpdate)
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile("AutoUpdate | Installing update now");
2025-08-03 16:46:33 +08:00
2025-06-19 11:47:16 +08:00
// 设置为用户主动退出,避免被看门狗判定为崩溃
App.IsAppExitByUser = true;
2025-08-03 16:46:33 +08:00
2025-06-19 11:47:16 +08:00
// 执行更新安装
2025-05-25 09:29:48 +08:00
AutoUpdateHelper.InstallNewVersionApp(AvailableLatestVersion, true);
2025-08-03 16:46:33 +08:00
2025-06-19 11:47:16 +08:00
// 关闭应用程序
2025-08-03 16:46:33 +08:00
Dispatcher.Invoke(() =>
{
2025-06-19 11:47:16 +08:00
Application.Current.Shutdown();
});
2025-08-03 16:46:33 +08:00
}
else
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile("AutoUpdate | Cannot safely update now, will try again later");
// 重新启动计时器,稍后再检查
timerCheckAutoUpdateWithSilence.Start();
2025-05-25 09:29:48 +08:00
}
}
2025-08-03 16:46:33 +08:00
catch (Exception ex)
{
2025-06-19 11:47:16 +08:00
LogHelper.WriteLogToFile($"AutoUpdate | Error in silent update check: {ex.Message}", LogHelper.LogType.Error);
// 出错时重新启动计时器,稍后再检查
timerCheckAutoUpdateWithSilence.Start();
2025-05-25 09:29:48 +08:00
}
}
}
}