Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

feat(update): show dialog with progress bar while downloading update

gtxPrime7db84e4e6923
diff --git a/src/Filee.App/App.axaml.cs b/src/Filee.App/App.axaml.cs
index 618e0d55..ae6b67d8 100644
--- a/src/Filee.App/App.axaml.cs
+++ b/src/Filee.App/App.axaml.cs
@@ -212,6 +212,11 @@ public partial class App : Application
AppHost.Get<WindowService>().ShowUpdateNotice(version);
};
updates.UpdateFailed += async (_, _) => await AppHost.Get<WindowService>().ShowUpdateFailedAsync();
+ updates.PropertyChanged += (_, e) =>
+ {
+ if (e.PropertyName == nameof(UpdateService.Step) && updates.Step == UpdateStep.Downloading)
+ Dispatcher.UIThread.Post(() => AppHost.Get<WindowService>().ShowUpdateProgress(updates));
+ };
updates.StartPeriodicChecks(() => store.Settings.CheckForUpdates, TimeSpan.FromSeconds(20));
DispatcherTimer.RunOnce(() => NotifyEngineUpdates(store), TimeSpan.FromSeconds(25));
}
diff --git a/src/Filee.App/Services/TrayService.cs b/src/Filee.App/Services/TrayService.cs
index a84c1292..cc714b4d 100644
--- a/src/Filee.App/Services/TrayService.cs
+++ b/src/Filee.App/Services/TrayService.cs
@@ -30,7 +30,15 @@ public sealed class TrayService(UserDataStore store, ILocalizer loc, IPlatformSe
_quit = new NativeMenuItem();
_quit.Click += (_, _) => (app.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.Shutdown();
_update = new NativeMenuItem();
- _update.Click += async (_, _) => await updates.UpdateAsync();
+ _update.Click += async (_, _) =>
+ {
+ if (updates.IsBusy)
+ {
+ windows.ShowUpdateProgress(updates);
+ return;
+ }
+ await updates.UpdateAsync();
+ };
_tray = new TrayIcon
{
diff --git a/src/Filee.App/Services/WindowService.cs b/src/Filee.App/Services/WindowService.cs
index ac4347e7..eea2f37d 100644
--- a/src/Filee.App/Services/WindowService.cs
+++ b/src/Filee.App/Services/WindowService.cs
@@ -22,6 +22,8 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services, Mem
private ToastWindow? _toast;
private EngineSetupWindow? _engineSetup;
private UpdateNoticeWindow? _updateNotice;
+ private UpdateProgressWindow? _updateProgress;
+ internal UpdateProgressWindow? UpdateProgress => _updateProgress;
private EngineUpdateNoticeWindow? _engineNotice;
private FeedbackNoticeWindow? _feedbackNotice;
private FormatRequestNoticeWindow? _formatRequestNotice;
@@ -196,6 +198,38 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services, Mem
notice.Show();
}
+ /// <summary>Shows the update download progress dialog with a progress bar.</summary>
+ public void ShowUpdateProgress(UpdateService updates)
+ {
+ if (_updateProgress is not null)
+ {
+ _updateProgress.Activate();
+ return;
+ }
+
+ _updateNotice?.Close();
+ var dialog = new UpdateProgressWindow(updates, loc);
+ if (_main is { IsVisible: true } main && main.WindowState != WindowState.Minimized)
+ {
+ dialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
+ dialog.Show(main);
+ }
+ else
+ {
+ dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
+ dialog.ShowInTaskbar = true;
+ dialog.Show();
+ }
+
+ dialog.Closed += (_, _) =>
+ {
+ if (_updateProgress == dialog)
+ _updateProgress = null;
+ };
+ _updateProgress = dialog;
+ dialog.Activate();
+ }
+
/// <summary>
/// Says that engines the user downloaded have a newer version. "Update" queues them (one after another) and opens
/// Settings → Engines to show the progress.
diff --git a/src/Filee.App/ViewModels/MainWindowViewModel.cs b/src/Filee.App/ViewModels/MainWindowViewModel.cs
index 07161c55..24747659 100644
--- a/src/Filee.App/ViewModels/MainWindowViewModel.cs
+++ b/src/Filee.App/ViewModels/MainWindowViewModel.cs
@@ -86,7 +86,15 @@ public sealed partial class MainWindowViewModel : ObservableObject, IDisposable
/// <summary>Downloads and runs the new installer (or opens the download page in a portable copy).</summary>
[RelayCommand]
- private Task DownloadUpdate() => Updates.UpdateAsync();
+ private async Task DownloadUpdate()
+ {
+ if (Updates.IsBusy)
+ {
+ AppHost.Get<WindowService>().ShowUpdateProgress(Updates);
+ return;
+ }
+ await Updates.UpdateAsync();
+ }
private void OnUpdatesChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
diff --git a/src/Filee.App/ViewModels/Pages/AboutPageViewModel.cs b/src/Filee.App/ViewModels/Pages/AboutPageViewModel.cs
index dcfb250f..1e25909c 100644
--- a/src/Filee.App/ViewModels/Pages/AboutPageViewModel.cs
+++ b/src/Filee.App/ViewModels/Pages/AboutPageViewModel.cs
@@ -70,7 +70,15 @@ public sealed partial class AboutPageViewModel : ObservableObject, IDisposable
/// <summary>Downloads and runs the new installer, which updates Filee in place (a portable copy opens the download page).</summary>
[RelayCommand]
- private Task DownloadUpdate() => _updates.UpdateAsync();
+ private async Task DownloadUpdate()
+ {
+ if (_updates.IsBusy)
+ {
+ AppHost.Get<WindowService>().ShowUpdateProgress(_updates);
+ return;
+ }
+ await _updates.UpdateAsync();
+ }
private void ShowUpdateState(string? newer, bool afterCheck = false)
{
diff --git a/src/Filee.App/Views/UpdateProgressWindow.axaml b/src/Filee.App/Views/UpdateProgressWindow.axaml
new file mode 100644
index 00000000..d7d94a3b
--- /dev/null
+++ b/src/Filee.App/Views/UpdateProgressWindow.axaml
@@ -0,0 +1,35 @@
+<!-- Dialog showing download progress and status while an in-app update is downloading or being installed. -->
+<Window xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ x:Class="Filee.App.Views.UpdateProgressWindow"
+ Title="Filee"
+ Icon="avares://Filee/Assets/Icons/filee.ico"
+ Width="440"
+ SizeToContent="Height"
+ CanResize="False"
+ WindowStartupLocation="CenterOwner"
+ ShowInTaskbar="False">
+ <Border Classes="card" Margin="16" Padding="20">
+ <DockPanel>
+ <Image DockPanel.Dock="Left" Source="avares://Filee/Assets/Icons/filee.png" Width="44" Height="44"
+ VerticalAlignment="Top" Margin="0,0,16,0" />
+ <StackPanel Spacing="10">
+ <StackPanel Spacing="3">
+ <TextBlock x:Name="TitleText" Classes="h2" FontWeight="SemiBold" TextWrapping="Wrap" />
+ <TextBlock x:Name="VersionText" Classes="caption" TextWrapping="Wrap" />
+ </StackPanel>
+
+ <ProgressBar x:Name="ProgressBar" Classes="soft" Minimum="0" Maximum="100" Height="6" Margin="0,4,0,2" />
+
+ <DockPanel>
+ <TextBlock x:Name="PercentText" DockPanel.Dock="Right" Classes="caption" FontWeight="Medium" />
+ <TextBlock x:Name="StatusText" Classes="caption" TextWrapping="Wrap" />
+ </DockPanel>
+
+ <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8" Margin="0,6,0,0">
+ <Button x:Name="ActionButton" Content="{DynamicResource common.close}" Click="OnClose" MinWidth="80" HorizontalContentAlignment="Center" />
+ </StackPanel>
+ </StackPanel>
+ </DockPanel>
+ </Border>
+</Window>
diff --git a/src/Filee.App/Views/UpdateProgressWindow.axaml.cs b/src/Filee.App/Views/UpdateProgressWindow.axaml.cs
new file mode 100644
index 00000000..eeedb002
--- /dev/null
+++ b/src/Filee.App/Views/UpdateProgressWindow.axaml.cs
@@ -0,0 +1,98 @@
+// Dialog showing download progress and status while an in-app update is downloading or being installed.
+
+using System.ComponentModel;
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Threading;
+using Filee.App.Services;
+using Filee.Core.Localization;
+
+namespace Filee.App.Views;
+
+/// <summary>
+/// Dialog box showing the progress bar and status while downloading an update.
+/// </summary>
+public partial class UpdateProgressWindow : Window
+{
+ private readonly UpdateService? _updates;
+ private readonly ILocalizer? _loc;
+
+ public UpdateProgressWindow()
+ {
+ InitializeComponent();
+ Motion.Track(this);
+ }
+
+ public UpdateProgressWindow(UpdateService updates, ILocalizer loc) : this()
+ {
+ _updates = updates;
+ _loc = loc;
+ Title = loc["app.name"];
+ TitleText.Text = loc["about.updates"];
+ VersionText.Text = updates.LatestVersion is { } ver ? loc.Format("general.update_available", ver) : "";
+
+ updates.PropertyChanged += OnUpdatesChanged;
+ Closed += (_, _) => updates.PropertyChanged -= OnUpdatesChanged;
+ UpdateState();
+ }
+
+ private void OnClose(object? sender, RoutedEventArgs e) => Close();
+
+ private void OnUpdatesChanged(object? sender, PropertyChangedEventArgs e)
+ {
+ if (UpdateTexts.Affects(e.PropertyName))
+ {
+ if (Dispatcher.UIThread.CheckAccess())
+ UpdateState();
+ else
+ Dispatcher.UIThread.Post(UpdateState);
+ }
+ }
+
+ private void UpdateState()
+ {
+ if (_updates is null || _loc is null)
+ return;
+
+ if (_updates.LatestVersion is { } ver)
+ VersionText.Text = _loc.Format("general.update_available", ver);
+
+ switch (_updates.Step)
+ {
+ case UpdateStep.Downloading:
+ ProgressBar.IsVisible = true;
+ ProgressBar.IsIndeterminate = false;
+ ProgressBar.Value = _updates.DownloadPercent;
+ PercentText.Text = $"{_updates.DownloadPercent}%";
+ StatusText.Text = _loc.Format("update.downloading", _updates.DownloadPercent);
+ break;
+
+ case UpdateStep.Installing:
+ ProgressBar.IsVisible = true;
+ ProgressBar.IsIndeterminate = true;
+ PercentText.Text = "";
+ StatusText.Text = _loc["update.installing"];
+ break;
+
+ case UpdateStep.Cancelled:
+ ProgressBar.IsVisible = false;
+ PercentText.Text = "";
+ StatusText.Text = _loc["update.cancelled"];
+ break;
+
+ case UpdateStep.Failed:
+ ProgressBar.IsVisible = false;
+ PercentText.Text = "";
+ StatusText.Text = _loc["update.failed"];
+ break;
+
+ case UpdateStep.Idle:
+ ProgressBar.IsVisible = false;
+ PercentText.Text = "";
+ StatusText.Text = "";
+ if (!IsVisible)
+ Close();
+ break;
+ }
+ }
+}
diff --git a/tests/Filee.App.Tests/UpdateServiceTests.cs b/tests/Filee.App.Tests/UpdateServiceTests.cs
index 45a81812..500ee0f8 100644
--- a/tests/Filee.App.Tests/UpdateServiceTests.cs
+++ b/tests/Filee.App.Tests/UpdateServiceTests.cs
@@ -346,4 +346,31 @@ public class UpdateServiceTests
Assert.EndsWith("/releases/latest", UpdateService.LatestReleaseUrl);
Assert.StartsWith(UpdateService.RepositoryUrl.TrimEnd('/'), UpdateService.LatestReleaseUrl);
}
+
+ [AvaloniaFact]
+ public void UpdateProgressWindow_tracks_download_percentage_and_status()
+ {
+ TestServices.EnsureInitialized();
+ var updates = new UpdateService(NullLogger<UpdateService>.Instance, new FakeNetwork("no network"));
+ updates.LatestVersion = "2.1.0";
+ updates.Step = UpdateStep.Downloading;
+ updates.DownloadPercent = 45;
+
+ var loc = AppHost.Get<Filee.Core.Localization.ILocalizer>();
+ var window = new Views.UpdateProgressWindow(updates, loc);
+
+ Assert.Equal(45, window.ProgressBar.Value);
+ Assert.Equal("45%", window.PercentText.Text);
+ Assert.Contains("45%", window.StatusText.Text);
+
+ updates.DownloadPercent = 90;
+ Assert.Equal(90, window.ProgressBar.Value);
+ Assert.Equal("90%", window.PercentText.Text);
+
+ updates.Step = UpdateStep.Installing;
+ Assert.True(window.ProgressBar.IsIndeterminate);
+
+ updates.Step = UpdateStep.Cancelled;
+ Assert.False(window.ProgressBar.IsVisible);
+ }
}