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.

When the in-app update fails, say so before opening filee.sh

KnifeLemonedae42f93174
diff --git a/src/Filee.App/App.axaml.cs b/src/Filee.App/App.axaml.cs
index 3378ca5b..c5391aa8 100644
--- a/src/Filee.App/App.axaml.cs
+++ b/src/Filee.App/App.axaml.cs
@@ -99,6 +99,7 @@ public partial class App : Application
store.SaveSettings();
AppHost.Get<WindowService>().ShowUpdateNotice(version);
};
+ updates.UpdateFailed += async (_, _) => await AppHost.Get<WindowService>().ShowUpdateFailedAsync();
updates.StartPeriodicChecks(() => store.Settings.CheckForUpdates, TimeSpan.FromSeconds(20));
}
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index bf8f43bc..227da8f8 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -155,7 +155,8 @@
"update.downloading": "Downloading the update… {0}%",
"update.installing_short": "Installing…",
"update.installing": "The installer is running. Filee starts again when it is done.",
- "update.failed": "Couldn't update automatically, so the download page is open in your browser.",
+ "update.failed": "Couldn't update automatically. Download the new version from filee.sh.",
+ "update.failed_alert": "Couldn't download the update. Press OK to open filee.sh and download the new version there.",
"update.cancelled": "Update cancelled. Press Update again to install it.",
"general.data_folder": "Settings folder",
"general.open_data_folder": "Open",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index 52134a67..57757dbd 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -155,7 +155,8 @@
"update.downloading": "새 버전 받는 중… {0}%",
"update.installing_short": "설치하는 중…",
"update.installing": "설치 프로그램이 열렸어요. 설치가 끝나면 Filee가 다시 켜져요.",
- "update.failed": "자동 업데이트가 안 돼서 브라우저에 다운로드 페이지를 열었어요.",
+ "update.failed": "자동 업데이트가 안 됐어요. filee.sh에서 새 버전을 받아 주세요.",
+ "update.failed_alert": "업데이트를 받지 못했어요. 확인을 누르면 filee.sh를 열어 드릴게요. 거기서 새 버전을 받을 수 있어요.",
"update.cancelled": "업데이트를 취소했어요. 다시 누르면 설치해요.",
"general.data_folder": "설정 폴더",
"general.open_data_folder": "열기",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index 247a2cc5..422750d8 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -155,7 +155,8 @@
"update.downloading": "正在下载更新… {0}%",
"update.installing_short": "正在安装…",
"update.installing": "安装程序正在运行,完成后 Filee 会重新启动。",
- "update.failed": "无法自动更新,已在浏览器中打开下载页面。",
+ "update.failed": "无法自动更新,请从 filee.sh 下载新版本。",
+ "update.failed_alert": "无法下载更新。点击“确定”后会打开 filee.sh,可以在那里下载新版本。",
"update.cancelled": "已取消更新,再次点击“更新”即可安装。",
"general.data_folder": "设置文件夹",
"general.open_data_folder": "打开",
diff --git a/src/Filee.App/Services/UpdateService.cs b/src/Filee.App/Services/UpdateService.cs
index 73cfdf29..ae385337 100644
--- a/src/Filee.App/Services/UpdateService.cs
+++ b/src/Filee.App/Services/UpdateService.cs
@@ -90,6 +90,9 @@ public sealed partial class UpdateService : ObservableObject
public static bool IsInstalled { get; } = OperatingSystem.IsWindows()
&& File.Exists(Path.Combine(AppContext.BaseDirectory, "unins000.exe"));
+ /// <summary>Whether <see cref="UpdateAsync"/> installs by itself (<see cref="IsInstalled"/>; tests set it).</summary>
+ internal bool InstallsItself { get; init; } = IsInstalled;
+
/// <summary>The newer version found by the last check (e.g. "1.0.2"), or null when up to date / unknown.</summary>
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsUpdateAvailable))]
@@ -172,11 +175,16 @@ public sealed partial class UpdateService : ObservableObject
{
if (IsBusy)
return;
- if (!IsInstalled || _installer is null || _checksums is null)
+ if (!InstallsItself)
{
OpenDownloadPage();
return;
}
+ if (_installer is null || _checksums is null)
+ {
+ Fail("release", new InvalidDataException("The latest release has no installer or no checksum file"));
+ return;
+ }
Step = UpdateStep.Downloading;
DownloadPercent = 0;
@@ -313,11 +321,17 @@ public sealed partial class UpdateService : ObservableObject
}
}
+ /// <summary>
+ /// Raised on the UI thread when an installed copy could not download or start the new installer. The app says so
+ /// and, once the user presses OK, opens <see cref="WebsiteUrl"/> (<see cref="OpenDownloadPage"/>).
+ /// </summary>
+ public event EventHandler? UpdateFailed;
+
private void Fail(string stage, Exception ex)
{
- _log.LogWarning(ex, "In-app update failed ({Stage}); opening the download page", stage);
+ _log.LogWarning(ex, "In-app update failed ({Stage})", stage);
Step = UpdateStep.Failed;
- OpenDownloadPage();
+ UpdateFailed?.Invoke(this, EventArgs.Empty);
}
private void Publish(string? newer)
diff --git a/src/Filee.App/Services/WindowService.cs b/src/Filee.App/Services/WindowService.cs
index 222a8c9b..b70ceb92 100644
--- a/src/Filee.App/Services/WindowService.cs
+++ b/src/Filee.App/Services/WindowService.cs
@@ -124,10 +124,18 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services)
public Task<bool> ConfirmAsync(Window owner, string message, bool destructive = false) =>
ShowMessageAsync(owner, message, destructive, withCancel: true);
- /// <summary>A message with only an OK button.</summary>
- public Task MessageAsync(Window owner, string message) => ShowMessageAsync(owner, message, destructive: false, withCancel: false);
+ /// <summary>A message with only an OK button. Without a visible owner it shows on its own, centred on the screen.</summary>
+ public Task MessageAsync(Window? owner, string message) => ShowMessageAsync(owner, message, destructive: false, withCancel: false);
- private async Task<bool> ShowMessageAsync(Window owner, string message, bool destructive, bool withCancel)
+ /// <summary>The in-app update failed: say so, then open the website to download the new version there.</summary>
+ public async Task ShowUpdateFailedAsync()
+ {
+ _updateNotice?.Close();
+ await MessageAsync(_main is { IsVisible: true } main ? main : null, loc["update.failed_alert"]);
+ services.GetRequiredService<UpdateService>().OpenDownloadPage();
+ }
+
+ private async Task<bool> ShowMessageAsync(Window? owner, string message, bool destructive, bool withCancel)
{
var dialog = new Window
{
@@ -142,7 +150,8 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services)
var yes = new Button { Content = destructive ? loc["common.delete"] : loc["common.ok"], IsDefault = true };
yes.Classes.Add("accent");
var no = new Button { Content = loc["common.cancel"], IsCancel = true };
- yes.Click += (_, _) => dialog.Close(true);
+ var answer = false;
+ yes.Click += (_, _) => { answer = true; dialog.Close(true); };
no.Click += (_, _) => dialog.Close(false);
no.IsVisible = withCancel;
dialog.Content = new StackPanel
@@ -161,7 +170,19 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services)
},
},
};
- return await dialog.ShowDialog<bool>(owner);
+ if (owner is { IsVisible: true })
+ return await dialog.ShowDialog<bool>(owner);
+
+ // From the tray or the bottom-right notice there is no window to sit on: a normal window on top instead.
+ var closed = new TaskCompletionSource();
+ dialog.Closed += (_, _) => closed.TrySetResult();
+ dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
+ dialog.ShowInTaskbar = true;
+ dialog.Topmost = true;
+ dialog.Show();
+ dialog.Activate();
+ await closed.Task;
+ return answer;
}
private static Window? MainWindowOrNull() =>
diff --git a/tests/Filee.App.Tests/UpdateServiceTests.cs b/tests/Filee.App.Tests/UpdateServiceTests.cs
index 38f1e879..bf77ffe8 100644
--- a/tests/Filee.App.Tests/UpdateServiceTests.cs
+++ b/tests/Filee.App.Tests/UpdateServiceTests.cs
@@ -227,6 +227,21 @@ public class UpdateServiceTests
}
}
+ [Fact]
+ public async Task A_failed_update_is_reported_instead_of_opening_a_page_right_away()
+ {
+ // Installed copy, but the release offers no installer to download: the app shows an alert first and opens
+ // the website only after OK (WindowService.ShowUpdateFailedAsync).
+ var updates = new UpdateService(NullLogger<UpdateService>.Instance, new FakeNetwork("no network")) { InstallsItself = true };
+ var reported = 0;
+ updates.UpdateFailed += (_, _) => reported++;
+
+ await updates.UpdateAsync();
+
+ Assert.Equal(1, reported);
+ Assert.Equal(UpdateStep.Failed, updates.Step);
+ }
+
[Fact]
public void Download_page_is_the_latest_release()
{