Skip to content

Commit dfc1449

Browse files
committed
功能:启动时自动检查更新
- 应用启动后延迟 2 秒自动检查更新 - 有新版本时弹出更新对话框 - 无更新或检查失败时静默处理,不打扰用户
1 parent a9f7be7 commit dfc1449

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

ViewModels/MainViewModel.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,37 @@ public MainViewModel()
117117

118118
UpdateResultsSource();
119119

120+
// 启动时自动检查更新
121+
_ = CheckUpdateOnStartupAsync();
122+
}
123+
124+
private async Task CheckUpdateOnStartupAsync()
125+
{
126+
try
127+
{
128+
// 延迟 2 秒,让主界面先完成加载
129+
await Task.Delay(2000);
130+
131+
if (UpdateViewModel.IsUpdateDialogOpen) return;
132+
133+
var updateInfo = await _updateService.CheckForUpdatesAsync();
134+
if (updateInfo != null)
135+
{
136+
var vm = new UpdateViewModel(_updateService, updateInfo);
137+
await OverlayDialog.ShowModal<UpdateDialog, UpdateViewModel>(
138+
vm,
139+
options: new OverlayDialogOptions
140+
{
141+
Buttons = DialogButton.None,
142+
Title = "软件更新",
143+
CanLightDismiss = false
144+
});
145+
}
146+
}
147+
catch
148+
{
149+
// 静默失败,不打扰用户
150+
}
120151
}
121152

122153
partial void OnConcurrencyChanged(int value)

0 commit comments

Comments
 (0)