Skip to content

Commit ca6cb3a

Browse files
committed
ux: checking update at startup (#2438)
- When `Check4Update` is called automatically at startup, do not show the result. - Instead, show a `New version available` button in main title bar - Before `Check4Update` is called manually, clear the existed `NewVersion` data Signed-off-by: leo <longshuang@msn.cn>
1 parent d2d4229 commit ca6cb3a

7 files changed

Lines changed: 50 additions & 14 deletions

File tree

src/App.axaml.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ private void TryLaunchAsNormal(IClassicDesktopStyleApplicationLifetime desktop)
524524
#region Check for Updates
525525
private void Check4Update(bool manually = false)
526526
{
527+
if (_launcher != null)
528+
_launcher.NewVersion = null;
529+
527530
Task.Run(async () =>
528531
{
529532
try
@@ -537,23 +540,20 @@ private void Check4Update(bool manually = false)
537540
if (ver == null)
538541
return;
539542

540-
// Check if already up-to-date.
541-
if (!ver.IsNewVersion)
543+
if (manually)
542544
{
543-
if (manually)
545+
if (ver.IsNewVersion)
546+
ShowSelfUpdateResult(ver);
547+
else
544548
ShowSelfUpdateResult(new Models.AlreadyUpToDate());
545-
return;
546549
}
547-
548-
// Should not check ignored tag if this is called manually.
549-
if (!manually)
550+
else if (_launcher != null)
550551
{
551-
var pref = ViewModels.Preferences.Instance;
552-
if (ver.TagName == pref.IgnoreUpdateTag)
552+
if (!ver.IsNewVersion || ver.TagName == ViewModels.Preferences.Instance.IgnoreUpdateTag)
553553
return;
554-
}
555554

556-
ShowSelfUpdateResult(ver);
555+
_launcher.NewVersion = ver;
556+
}
557557
}
558558
catch (Exception e)
559559
{

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@
580580
<x:String x:Key="Text.Launcher.Commands" xml:space="preserve">Commands</x:String>
581581
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">ERROR</x:String>
582582
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">NOTICE</x:String>
583+
<x:String x:Key="Text.Launcher.NewVersion" xml:space="preserve">New Version Available</x:String>
583584
<x:String x:Key="Text.Launcher.OpenRepository" xml:space="preserve">Open Repositories</x:String>
584585
<x:String x:Key="Text.Launcher.Pages" xml:space="preserve">Tabs</x:String>
585586
<x:String x:Key="Text.Launcher.Workspaces" xml:space="preserve">Workspaces</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@
584584
<x:String x:Key="Text.Launcher.Commands" xml:space="preserve">命令列表</x:String>
585585
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">出错了</x:String>
586586
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">系统提示</x:String>
587+
<x:String x:Key="Text.Launcher.NewVersion" xml:space="preserve">检测到新版本</x:String>
587588
<x:String x:Key="Text.Launcher.OpenRepository" xml:space="preserve">打开其他仓库</x:String>
588589
<x:String x:Key="Text.Launcher.Pages" xml:space="preserve">页面列表</x:String>
589590
<x:String x:Key="Text.Launcher.Workspaces" xml:space="preserve">工作区列表</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@
584584
<x:String x:Key="Text.Launcher.Commands" xml:space="preserve">命令列表</x:String>
585585
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">發生錯誤</x:String>
586586
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">系統提示</x:String>
587+
<x:String x:Key="Text.Launcher.NewVersion" xml:space="preserve">檢測到新版本</x:String>
587588
<x:String x:Key="Text.Launcher.OpenRepository" xml:space="preserve">開啟存放庫</x:String>
588589
<x:String x:Key="Text.Launcher.Pages" xml:space="preserve">頁面列表</x:String>
589590
<x:String x:Key="Text.Launcher.Workspaces" xml:space="preserve">工作區列表</x:String>

src/ViewModels/Launcher.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public ICommandPalette CommandPalette
4545
set => SetProperty(ref _commandPalette, value);
4646
}
4747

48+
public Models.Version NewVersion
49+
{
50+
get => _newVersion;
51+
set => SetProperty(ref _newVersion, value);
52+
}
53+
4854
public Launcher(string startupRepo)
4955
{
5056
Models.Notification.Raised += DispatchNotification;
@@ -467,5 +473,6 @@ private void PostActivePageChanged()
467473
private bool _ignoreIndexChange;
468474
private string _title = string.Empty;
469475
private ICommandPalette _commandPalette;
476+
private Models.Version _newVersion = null;
470477
}
471478
}

src/Views/Launcher.axaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
</Grid.RowDefinitions>
2020

2121
<!-- Custom TitleBar -->
22-
<Grid Grid.Row="0" ColumnDefinitions="Auto,32,32,*,Auto">
22+
<Grid Grid.Row="0" ColumnDefinitions="Auto,32,32,*,Auto,Auto">
2323
<!-- Bottom border -->
24-
<Border Grid.Column="0" Grid.ColumnSpan="5"
24+
<Border Grid.Column="0" Grid.ColumnSpan="6"
2525
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
2626
Background="{DynamicResource Brush.TitleBar}"
2727
DoubleTapped="MaximizeOrRestoreWindow"
@@ -111,8 +111,20 @@
111111
<!-- Pages Tabs -->
112112
<v:LauncherTabBar Grid.Column="3" Height="30" Margin="0,0,16,0" VerticalAlignment="Bottom"/>
113113

114+
<!-- Update Available Button -->
115+
<Button Grid.Column="4"
116+
Classes="icon_button"
117+
Height="30"
118+
Margin="0,0,4,0"
119+
VerticalAlignment="Top"
120+
IsVisible="{Binding NewVersion, Converter={x:Static ObjectConverters.IsNotNull}}"
121+
Click="OnShowNewVersion"
122+
ToolTip.Tip="{DynamicResource Text.Launcher.NewVersion}">
123+
<Path Width="15" Height="15" Margin="0,4,0,0" Data="{StaticResource Icons.SoftwareUpdate}" Fill="{DynamicResource Brush.Accent}"/>
124+
</Button>
125+
114126
<!-- Caption Buttons (Windows/Linux) -->
115-
<Border Grid.Column="4" Margin="16,0,0,0" IsVisible="{Binding #ThisControl.HasRightCaptionButton}">
127+
<Border Grid.Column="5" IsVisible="{Binding #ThisControl.HasRightCaptionButton}">
116128
<v:CaptionButtons Height="30" VerticalAlignment="Top"/>
117129
</Border>
118130
</Grid>

src/Views/Launcher.axaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,20 @@ private void OnCloseCommandPalette(object sender, PointerPressedEventArgs e)
423423
e.Handled = true;
424424
}
425425

426+
private async void OnShowNewVersion(object sender, RoutedEventArgs e)
427+
{
428+
if (DataContext is ViewModels.Launcher { NewVersion: { } ver } vm)
429+
{
430+
vm.NewVersion = null;
431+
432+
var ctx = new ViewModels.SelfUpdate { Data = ver };
433+
var dialog = new SelfUpdate() { DataContext = ctx };
434+
await dialog.ShowDialog(this);
435+
}
436+
437+
e.Handled = true;
438+
}
439+
426440
private GridLength _captionHeight = new(32);
427441
private WindowState _lastWindowState = WindowState.Normal;
428442
}

0 commit comments

Comments
 (0)