diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 79c2e7da..f5626d32 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -834,6 +834,10 @@ namespace Ink_Canvas if (AvailableLatestVersion != null) { + // 检测到新版本,停止重试定时器 + timerCheckAutoUpdateRetry.Stop(); + updateCheckRetryCount = 0; + // 检测到新版本 LogHelper.WriteLogToFile($"AutoUpdate | New version available: {AvailableLatestVersion}"); @@ -999,6 +1003,16 @@ namespace Ink_Canvas } else { + // 检查更新失败,启动重试定时器 + LogHelper.WriteLogToFile("AutoUpdate | Update check failed, starting retry timer"); + + // 重置重试计数 + updateCheckRetryCount = 0; + + // 启动重试定时器,10分钟后重新检查 + timerCheckAutoUpdateRetry.Start(); + + // 清理更新文件夹 AutoUpdateHelper.DeleteUpdatesFolder(); } } diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs index 5c06d12f..3e8dc065 100644 --- a/Ink Canvas/MainWindow_cs/MW_Settings.cs +++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs @@ -3126,6 +3126,7 @@ namespace Ink_Canvas if (Settings.Startup.IsAutoUpdate) { LogHelper.WriteLogToFile($"AutoUpdate | Channel changed to {newChannel}, performing immediate update check"); + ResetUpdateCheckRetry(); // 执行完整的更新检查 await Task.Run(async () => diff --git a/Ink Canvas/MainWindow_cs/MW_Timer.cs b/Ink Canvas/MainWindow_cs/MW_Timer.cs index c8d97dd9..8b83a223 100644 --- a/Ink Canvas/MainWindow_cs/MW_Timer.cs +++ b/Ink Canvas/MainWindow_cs/MW_Timer.cs @@ -61,8 +61,10 @@ namespace Ink_Canvas private Timer timerCheckAutoFold = new Timer(); private string AvailableLatestVersion; private Timer timerCheckAutoUpdateWithSilence = new Timer(); + private Timer timerCheckAutoUpdateRetry = new Timer(); private bool isHidingSubPanelsWhenInking; // 避免书写时触发二次关闭二级菜单导致动画不连续 - + 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(); @@ -117,6 +119,8 @@ namespace Ink_Canvas timerCheckAutoFold.Interval = 500; timerCheckAutoUpdateWithSilence.Elapsed += timerCheckAutoUpdateWithSilence_Elapsed; timerCheckAutoUpdateWithSilence.Interval = 1000 * 60 * 10; + timerCheckAutoUpdateRetry.Elapsed += timerCheckAutoUpdateRetry_Elapsed; + timerCheckAutoUpdateRetry.Interval = 1000 * 60 * 10; WaterMarkTime.DataContext = nowTimeVM; WaterMarkDate.DataContext = nowTimeVM; timerDisplayTime.Elapsed += TimerDisplayTime_Elapsed; @@ -830,5 +834,92 @@ namespace Ink_Canvas timerCheckAutoUpdateWithSilence.Start(); } } + + // 检查更新失败重试定时器事件处理 + private async void timerCheckAutoUpdateRetry_Elapsed(object sender, ElapsedEventArgs e) + { + // 停止定时器,避免重复触发 + timerCheckAutoUpdateRetry.Stop(); + + try + { + // 检查是否启用了自动更新 + if (!Settings.Startup.IsAutoUpdate) + { + LogHelper.WriteLogToFile("AutoUpdate | Auto update is disabled, stopping retry timer"); + return; + } + + // 增加重试计数 + updateCheckRetryCount++; + LogHelper.WriteLogToFile($"AutoUpdate | Retry check attempt {updateCheckRetryCount}/{MAX_UPDATE_CHECK_RETRIES}"); + + // 检查是否超过最大重试次数 + if (updateCheckRetryCount > MAX_UPDATE_CHECK_RETRIES) + { + LogHelper.WriteLogToFile("AutoUpdate | Maximum retry attempts reached, stopping retry timer", LogHelper.LogType.Warning); + return; + } + + // 执行更新检查 + LogHelper.WriteLogToFile("AutoUpdate | Retrying update check after failure"); + + // 清除之前的更新状态 + AvailableLatestVersion = null; + AvailableLatestLineGroup = null; + + // 使用当前选择的更新通道检查更新 + var (remoteVersion, lineGroup, apiReleaseNotes) = await AutoUpdateHelper.CheckForUpdates(Settings.Startup.UpdateChannel); + AvailableLatestVersion = remoteVersion; + AvailableLatestLineGroup = lineGroup; + + if (AvailableLatestVersion != null) + { + // 检查更新成功,重置重试计数 + updateCheckRetryCount = 0; + LogHelper.WriteLogToFile($"AutoUpdate | Retry successful, found new version: {AvailableLatestVersion}"); + + // 停止重试定时器,因为已经找到了更新 + return; + } + else + { + // 检查更新仍然失败,继续重试 + LogHelper.WriteLogToFile($"AutoUpdate | Retry {updateCheckRetryCount} failed, will retry in 10 minutes"); + + // 重新启动定时器,10分钟后再次尝试 + timerCheckAutoUpdateRetry.Start(); + } + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"AutoUpdate | Error in retry check: {ex.Message}", LogHelper.LogType.Error); + + // 出错时也重新启动定时器,稍后再检查 + if (updateCheckRetryCount <= MAX_UPDATE_CHECK_RETRIES) + { + timerCheckAutoUpdateRetry.Start(); + } + } + } + + // 重置更新检查重试状态 + public void ResetUpdateCheckRetry() + { + try + { + // 停止重试定时器 + timerCheckAutoUpdateRetry.Stop(); + + // 重置重试计数 + updateCheckRetryCount = 0; + + LogHelper.WriteLogToFile("AutoUpdate | Update check retry state reset"); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"AutoUpdate | Error resetting retry state: {ex.Message}", LogHelper.LogType.Error); + } + } } } diff --git a/Ink Canvas/Resources/Icons-png/icc-dark.png b/Ink Canvas/Resources/Icons-png/icc-dark.png index d682ec8c..c76d2373 100644 Binary files a/Ink Canvas/Resources/Icons-png/icc-dark.png and b/Ink Canvas/Resources/Icons-png/icc-dark.png differ diff --git a/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache b/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache index c8c2dfbd..57d842b8 100644 Binary files a/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache and b/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache differ