improve:自动更新
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 () =>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 186 KiB |
Binary file not shown.
Reference in New Issue
Block a user