improve:改进自动更新
This commit is contained in:
@@ -21,16 +21,33 @@ namespace Ink_Canvas {
|
||||
private void ToggleSwitchIsAutoUpdate_Toggled(object sender, RoutedEventArgs e) {
|
||||
if (!isLoaded) return;
|
||||
Settings.Startup.IsAutoUpdate = ToggleSwitchIsAutoUpdate.IsOn;
|
||||
ToggleSwitchIsAutoUpdateWithSilence.Visibility =
|
||||
|
||||
// 自动更新关闭时隐藏静默更新选项
|
||||
ToggleSwitchIsAutoUpdateWithSilence.Visibility =
|
||||
ToggleSwitchIsAutoUpdate.IsOn ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
// 如果关闭了自动更新,同时也关闭静默更新
|
||||
if (!ToggleSwitchIsAutoUpdate.IsOn) {
|
||||
Settings.Startup.IsAutoUpdateWithSilence = false;
|
||||
ToggleSwitchIsAutoUpdateWithSilence.IsOn = false;
|
||||
}
|
||||
|
||||
// 无论如何,静默更新时间区域的显示都要跟随静默更新设置
|
||||
AutoUpdateTimePeriodBlock.Visibility =
|
||||
(Settings.Startup.IsAutoUpdateWithSilence && Settings.Startup.IsAutoUpdate) ?
|
||||
Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
private void ToggleSwitchIsAutoUpdateWithSilence_Toggled(object sender, RoutedEventArgs e) {
|
||||
if (!isLoaded) return;
|
||||
Settings.Startup.IsAutoUpdateWithSilence = ToggleSwitchIsAutoUpdateWithSilence.IsOn;
|
||||
|
||||
// 静默更新的时间设置区域只在静默更新开启时显示
|
||||
AutoUpdateTimePeriodBlock.Visibility =
|
||||
Settings.Startup.IsAutoUpdateWithSilence ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
@@ -1515,8 +1532,8 @@ namespace Ink_Canvas {
|
||||
Settings.Startup.IsEnableNibMode = false;
|
||||
Settings.Startup.IsAutoUpdate = true;
|
||||
Settings.Startup.IsAutoUpdateWithSilence = true;
|
||||
Settings.Startup.AutoUpdateWithSilenceStartTime = "18:20";
|
||||
Settings.Startup.AutoUpdateWithSilenceEndTime = "07:40";
|
||||
Settings.Startup.AutoUpdateWithSilenceStartTime = "06:00";
|
||||
Settings.Startup.AutoUpdateWithSilenceEndTime = "22:00";
|
||||
Settings.Startup.IsFoldAtStartup = false;
|
||||
}
|
||||
|
||||
@@ -1781,5 +1798,61 @@ namespace Ink_Canvas {
|
||||
Process.Start("https://github.com/WXRIW/Ink-Canvas");
|
||||
HideSubPanels();
|
||||
}
|
||||
|
||||
private void UpdateChannelSelector_Checked(object sender, RoutedEventArgs e) {
|
||||
if (!isLoaded) return;
|
||||
var radioButton = sender as System.Windows.Controls.RadioButton;
|
||||
if (radioButton != null) {
|
||||
string channel = radioButton.Tag.ToString();
|
||||
Settings.Startup.UpdateChannel = channel == "Beta" ? UpdateChannel.Beta : UpdateChannel.Release;
|
||||
LogHelper.WriteLogToFile($"Settings | Update channel changed to {Settings.Startup.UpdateChannel}");
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
}
|
||||
|
||||
private async void FixVersionButton_Click(object sender, RoutedEventArgs e) {
|
||||
// 显示确认对话框
|
||||
var confirm = MessageBox.Show(
|
||||
"此操作将下载当前选择通道的最新版本并安装,软件将自动关闭并更新。\n\n确定要执行版本修复吗?",
|
||||
"版本修复确认",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (confirm == MessageBoxResult.Yes) {
|
||||
// 禁用按钮,避免重复点击
|
||||
FixVersionButton.IsEnabled = false;
|
||||
FixVersionButton.Content = "正在修复...";
|
||||
|
||||
try {
|
||||
// 执行版本修复
|
||||
bool result = await AutoUpdateHelper.FixVersion(Settings.Startup.UpdateChannel);
|
||||
|
||||
if (!result) {
|
||||
MessageBox.Show(
|
||||
"版本修复失败,可能是网络问题或当前已是最新版本。",
|
||||
"修复失败",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
|
||||
// 恢复按钮状态
|
||||
FixVersionButton.IsEnabled = true;
|
||||
FixVersionButton.Content = "版本修复";
|
||||
}
|
||||
// 成功则会自动关闭应用程序并安装
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogHelper.WriteLogToFile($"Error in FixVersionButton_Click: {ex.Message}", LogHelper.LogType.Error);
|
||||
MessageBox.Show(
|
||||
$"版本修复过程中发生错误: {ex.Message}",
|
||||
"修复错误",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
|
||||
// 恢复按钮状态
|
||||
FixVersionButton.IsEnabled = true;
|
||||
FixVersionButton.Content = "版本修复";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,18 +70,20 @@ namespace Ink_Canvas {
|
||||
BoundsWidth = Settings.Advanced.FingerModeBoundsWidth;
|
||||
}
|
||||
|
||||
// Always show update setting in UI based on stored preference
|
||||
// 设置自动更新相关选项
|
||||
ToggleSwitchIsAutoUpdate.IsOn = Settings.Startup.IsAutoUpdate;
|
||||
|
||||
// Always check for updates at startup, regardless of the setting
|
||||
// 只有在启用了自动更新功能时才检查更新
|
||||
if (Settings.Startup.IsAutoUpdate) {
|
||||
if (isStartup) {
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Running auto-update check at startup");
|
||||
AutoUpdate();
|
||||
}
|
||||
// Call auto-update when setting is changed (not at startup)
|
||||
else if (Settings.Startup.IsAutoUpdate) {
|
||||
// 当设置被修改时也检查更新(非启动时)
|
||||
else {
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Running auto-update check after settings change");
|
||||
AutoUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
// ToggleSwitchIsAutoUpdateWithSilence.Visibility = Settings.Startup.IsAutoUpdate ? Visibility.Visible : Visibility.Collapsed;
|
||||
@@ -89,6 +91,16 @@ namespace Ink_Canvas {
|
||||
ToggleSwitchIsAutoUpdateWithSilence.IsOn = true;
|
||||
}
|
||||
|
||||
// 初始化更新通道选择
|
||||
foreach (var radioButton in UpdateChannelSelector.Items) {
|
||||
if (radioButton is System.Windows.Controls.RadioButton rb) {
|
||||
if (rb.Tag.ToString() == Settings.Startup.UpdateChannel.ToString()) {
|
||||
rb.IsChecked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AutoUpdateTimePeriodBlock.Visibility = Settings.Startup.IsAutoUpdateWithSilence
|
||||
? Visibility.Visible
|
||||
: Visibility.Collapsed;
|
||||
|
||||
@@ -9,6 +9,7 @@ using MessageBox = System.Windows.MessageBox;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Ink_Canvas {
|
||||
public class TimeViewModel : INotifyPropertyChanged {
|
||||
@@ -355,22 +356,24 @@ namespace Ink_Canvas {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查应用程序状态,确保可以安全更新
|
||||
// 检查应用程序状态,确保可以安全更新
|
||||
// 空闲状态的判定为不处于批注模式和画板模式
|
||||
bool canSafelyUpdate = false;
|
||||
|
||||
Dispatcher.Invoke(() => {
|
||||
try {
|
||||
// 检查是否处于桌面模式(Topmost为true)且没有墨迹内容
|
||||
if (Topmost && inkCanvas.Strokes.Count == 0) {
|
||||
// 判断是否处于批注模式(inkCanvas.EditingMode == InkCanvasEditingMode.Ink)
|
||||
// 判断是否处于画板模式(!Topmost)
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.Ink && Topmost) {
|
||||
// 检查是否有未保存的内容或正在进行的操作
|
||||
if (!isHidingSubPanelsWhenInking) {
|
||||
canSafelyUpdate = true;
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Application is in a safe state for update");
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Application is in a safe state for update - not in ink or board mode");
|
||||
} else {
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Application is currently performing operations");
|
||||
}
|
||||
} else {
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Application has unsaved content or is not in desktop mode");
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Application is in ink or board mode, cannot update now");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
Reference in New Issue
Block a user