add:更新面板
This commit is contained in:
+10
-123
@@ -45,7 +45,7 @@ namespace Ink_Canvas
|
||||
private List<System.Windows.Controls.Canvas> whiteboardPages = new List<System.Windows.Controls.Canvas>();
|
||||
private int currentPageIndex;
|
||||
private System.Windows.Controls.Canvas currentCanvas;
|
||||
private AutoUpdateHelper.UpdateLineGroup AvailableLatestLineGroup;
|
||||
internal AutoUpdateHelper.UpdateLineGroup AvailableLatestLineGroup;
|
||||
|
||||
// 全局快捷键管理器
|
||||
private GlobalHotkeyManager _globalHotkeyManager;
|
||||
@@ -1203,7 +1203,6 @@ namespace Ink_Canvas
|
||||
LoadCustomBackgroundColor();
|
||||
SetWindowMode();
|
||||
|
||||
// HasNewUpdateWindow hasNewUpdateWindow = new HasNewUpdateWindow();
|
||||
// 根据设置应用主题
|
||||
switch (Settings.Appearance.Theme)
|
||||
{
|
||||
@@ -1846,6 +1845,7 @@ namespace Ink_Canvas
|
||||
var (remoteVersion, lineGroup, apiReleaseNotes) = await AutoUpdateHelper.CheckForUpdates(Settings.Startup.UpdateChannel);
|
||||
AvailableLatestVersion = remoteVersion;
|
||||
AvailableLatestLineGroup = lineGroup;
|
||||
AvailableLatestReleaseNotes = apiReleaseNotes;
|
||||
|
||||
// 声明下载状态变量,用于整个方法
|
||||
bool isDownloadSuccessful = false;
|
||||
@@ -1882,9 +1882,6 @@ namespace Ink_Canvas
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
// 获取当前版本
|
||||
string currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
|
||||
// 如果启用了静默更新,则自动下载更新而不显示提示
|
||||
if (Settings.Startup.IsAutoUpdateWithSilence)
|
||||
{
|
||||
@@ -1908,121 +1905,10 @@ namespace Ink_Canvas
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果没有启用静默更新,则显示常规更新窗口
|
||||
string releaseDate = DateTime.Now.ToString("yyyy年MM月dd日");
|
||||
|
||||
// 从服务器获取更新日志
|
||||
string releaseNotes = await AutoUpdateHelper.GetUpdateLog(Settings.Startup.UpdateChannel);
|
||||
|
||||
// 如果获取失败,使用默认文本
|
||||
if (string.IsNullOrEmpty(releaseNotes))
|
||||
{
|
||||
releaseNotes = $@"# InkCanvasForClass v{AvailableLatestVersion}更新
|
||||
|
||||
无法获取更新日志,但新版本已准备就绪。";
|
||||
}
|
||||
|
||||
// 创建并显示更新窗口
|
||||
HasNewUpdateWindow updateWindow = new HasNewUpdateWindow(currentVersion, AvailableLatestVersion, releaseDate, releaseNotes);
|
||||
updateWindow.Owner = this;
|
||||
bool? dialogResult = updateWindow.ShowDialog();
|
||||
|
||||
// 如果窗口被关闭但没有点击按钮,则不执行任何操作
|
||||
if (dialogResult != true)
|
||||
{
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Update dialog closed without selection");
|
||||
return;
|
||||
}
|
||||
|
||||
// 不再从更新窗口获取自动更新设置
|
||||
|
||||
// 根据用户选择处理更新
|
||||
switch (updateWindow.Result)
|
||||
{
|
||||
case HasNewUpdateWindow.UpdateResult.UpdateNow:
|
||||
// 立即更新:显示下载进度,下载完成后立即安装
|
||||
LogHelper.WriteLogToFile("AutoUpdate | User chose to update now");
|
||||
|
||||
// 显示下载进度提示
|
||||
MessageBox.Show("开始下载更新,请稍候...", "正在更新", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
// 下载更新文件,使用多线路组下载功能
|
||||
isDownloadSuccessful = await DownloadUpdateWithFallback(AvailableLatestVersion, AvailableLatestLineGroup, Settings.Startup.UpdateChannel);
|
||||
|
||||
if (isDownloadSuccessful)
|
||||
{
|
||||
// 下载成功,提示用户准备安装
|
||||
MessageBoxResult result = MessageBox.Show("更新已下载完成,点击确定后将关闭软件并安装新版本!", "安装更新", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
||||
|
||||
// 只有当用户点击确定按钮后才关闭软件
|
||||
if (result == MessageBoxResult.OK)
|
||||
{
|
||||
// 设置为用户主动退出,避免被看门狗判定为崩溃
|
||||
App.IsAppExitByUser = true;
|
||||
|
||||
// 准备批处理脚本
|
||||
AutoUpdateHelper.InstallNewVersionApp(AvailableLatestVersion, true); // 修改为静默模式,避免重复启动进程
|
||||
|
||||
// 关闭软件,让安装程序接管
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.WriteLogToFile("AutoUpdate | User cancelled update installation");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 下载失败
|
||||
MessageBox.Show("更新下载失败,请检查网络连接后重试。", "下载失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
break;
|
||||
|
||||
case HasNewUpdateWindow.UpdateResult.UpdateLater:
|
||||
// 稍后更新:静默下载,在软件关闭时自动安装
|
||||
LogHelper.WriteLogToFile("AutoUpdate | User chose to update later");
|
||||
|
||||
// 不管设置如何,都进行下载,使用多线路组下载功能
|
||||
isDownloadSuccessful = await DownloadUpdateWithFallback(AvailableLatestVersion, AvailableLatestLineGroup, Settings.Startup.UpdateChannel);
|
||||
|
||||
if (isDownloadSuccessful)
|
||||
{
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Update downloaded successfully, will install when application closes");
|
||||
|
||||
// 设置标志,在应用程序关闭时安装
|
||||
Settings.Startup.IsAutoUpdate = true;
|
||||
Settings.Startup.IsAutoUpdateWithSilence = true;
|
||||
|
||||
// 启动检查定时器
|
||||
timerCheckAutoUpdateWithSilence.Start();
|
||||
|
||||
// 通知用户
|
||||
MessageBox.Show("更新已下载完成,将在软件关闭时自动安装。", "更新已准备就绪", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Update download failed", LogHelper.LogType.Error);
|
||||
MessageBox.Show("更新下载失败,请检查网络连接后重试。", "下载失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
break;
|
||||
|
||||
case HasNewUpdateWindow.UpdateResult.SkipVersion:
|
||||
// 跳过该版本:记录到设置中
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | User chose to skip version {AvailableLatestVersion}");
|
||||
|
||||
// 记录要跳过的版本号
|
||||
Settings.Startup.SkippedVersion = AvailableLatestVersion;
|
||||
|
||||
// 保存设置到文件
|
||||
SaveSettingsToFile();
|
||||
|
||||
// 通知用户
|
||||
MessageBox.Show($"已设置跳过版本 {AvailableLatestVersion},在下次发布新版本之前不会再提示更新。",
|
||||
"已跳过此版本",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
break;
|
||||
}
|
||||
// 如果没有启用静默更新,则记录日志并依赖 Toast 通知用户。
|
||||
// 用户可在 设置 → 更新 中查看版本说明并选择更新方式。
|
||||
LogHelper.WriteLogToFile(
|
||||
$"AutoUpdate | New version {AvailableLatestVersion} available; user notified via toast, will act from settings page.");
|
||||
}
|
||||
else if (hasValidLineGroup)
|
||||
{
|
||||
@@ -2271,9 +2157,10 @@ namespace Ink_Canvas
|
||||
|
||||
private void HistoryRollbackButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var win = new HistoryRollbackWindow(Settings.Startup.UpdateChannel);
|
||||
win.Owner = this;
|
||||
win.ShowDialog();
|
||||
var settingsWindow = new Windows.SettingsViews.SettingsWindow();
|
||||
settingsWindow.Owner = this;
|
||||
settingsWindow.Show();
|
||||
settingsWindow.NavigateToPage("UpdatePage");
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
|
||||
Reference in New Issue
Block a user