Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Queueify.Core/Services/Strings.En.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ public static partial class Loc
["update.available"] = "A new version is out: Queueify {0}.",
["update.retry"] = "Try again",
["update.cancel"] = "Cancel",
["update.skip"] = "Skip this version",
["update.start_failed"] = "Queueify {0} is in place but didn't start, so your Queueify exe won't open until it's replaced. Keep this window open and download a version that works from the releases page (an earlier one, if this one is broken). Try again only helps if something on this PC got in the way, like a full disk or an antivirus.",
["update.releases"] = "Releases page",
["update.ok"] = "OK",
["update.restarting"] = "Starting Queueify {0}…",
["update.install"] = "Update and restart",
["update.whats_new"] = "What's new",
Expand Down
4 changes: 4 additions & 0 deletions Queueify.Core/Services/Strings.Es.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ public static partial class Loc
["update.available"] = "Hay una versión nueva: Queueify {0}.",
["update.retry"] = "Probar de nuevo",
["update.cancel"] = "Cancelar",
["update.skip"] = "Saltear esta versión",
["update.start_failed"] = "Queueify {0} quedó en su lugar pero no arrancó, así que tu exe de Queueify no va a abrir hasta que lo reemplaces. Dejá esta ventana abierta y descargá una versión que funcione desde la página de versiones (una anterior, si esta viene fallada). Probar de nuevo solo sirve si algo de esta PC se interpuso, como un disco lleno o un antivirus.",
["update.releases"] = "Página de versiones",
["update.ok"] = "Entendido",
["update.restarting"] = "Abriendo Queueify {0}…",
["update.install"] = "Actualizar y reiniciar",
["update.whats_new"] = "Novedades",
Expand Down
3 changes: 3 additions & 0 deletions Queueify.Core/Services/UiState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public sealed class UiState
/// <summary>Ask GitHub for a newer version at each start (Settings → Updates).</summary>
public bool CheckForUpdates { get; set; } = true;

/// <summary>"Skip this version" on the offer: not offered at start again, only by Check for updates.</summary>
public string? SkippedVersion { get; set; }

/// <summary>Back to the original layout (panel, list view, order, window size); the tour isn't repeated.</summary>
public void ResetLayout()
{
Expand Down
6 changes: 6 additions & 0 deletions Queueify.Core/Services/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public sealed record UpdateSource(Uri Latest, string DownloadPrefix)
/// <summary>The releases page, for when the app can't update itself.</summary>
public static Uri Releases { get; } = new("https://github.com/PAumedes/Queueify/releases/latest");

/// <summary>Every version, for when the latest one doesn't work here.</summary>
public static Uri AllReleases { get; } = new("https://github.com/PAumedes/Queueify/releases");

/// <summary>
/// GitHub, unless QUEUEIFY_UPDATE_SERVER names a server on this PC: the UI tests serve a release from
/// one. Anything else is ignored, so the variable can't point updates elsewhere.
Expand Down Expand Up @@ -95,6 +98,9 @@ public sealed class Updater(HttpClient http, UpdateSource source, TimeSpan? stal
public static bool IsNewer(string candidate, string current) =>
System.Version.TryParse(candidate, out var c) && System.Version.TryParse(current, out var v) && c > v;

/// <summary>Whether to offer a release: one the user skipped only when they asked (Check for updates).</summary>
public static bool IsWanted(AppRelease release, string? skipped, bool asked) => asked || release.Version != skipped;

/// <summary>The latest release when it's newer than this version; null when this is the latest.</summary>
public async Task<AppRelease?> CheckAsync(string currentVersion, CancellationToken ct)
{
Expand Down
6 changes: 3 additions & 3 deletions Queueify.Tests/AppDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ public void Layout_survives_a_save_and_load()
{
PaneWidth = 512, PaneVisible = false, CoverView = true, Sort = "artist",
WindowBounds = [10, 20, 1300, 900], Maximized = true, TourSeen = true,
Theme = "dark", Language = "es", OcrLanguage = "en-US", OcrHintDismissed = true, CheckForUpdates = false,
Theme = "dark", Language = "es", OcrLanguage = "en-US", OcrHintDismissed = true, CheckForUpdates = false, SkippedVersion = "1.4.0",
};

saved.Save(path);
var loaded = UiState.Load(path);

Assert.Equal(
(saved.PaneWidth, saved.PaneVisible, saved.CoverView, saved.Sort, saved.Maximized, saved.TourSeen, saved.Theme, saved.Language, saved.OcrLanguage, saved.OcrHintDismissed, saved.CheckForUpdates),
(loaded.PaneWidth, loaded.PaneVisible, loaded.CoverView, loaded.Sort, loaded.Maximized, loaded.TourSeen, loaded.Theme, loaded.Language, loaded.OcrLanguage, loaded.OcrHintDismissed, loaded.CheckForUpdates));
(saved.PaneWidth, saved.PaneVisible, saved.CoverView, saved.Sort, saved.Maximized, saved.TourSeen, saved.Theme, saved.Language, saved.OcrLanguage, saved.OcrHintDismissed, saved.CheckForUpdates, saved.SkippedVersion),
(loaded.PaneWidth, loaded.PaneVisible, loaded.CoverView, loaded.Sort, loaded.Maximized, loaded.TourSeen, loaded.Theme, loaded.Language, loaded.OcrLanguage, loaded.OcrHintDismissed, loaded.CheckForUpdates, loaded.SkippedVersion));
Assert.Equal(saved.WindowBounds, loaded.WindowBounds);
}

Expand Down
9 changes: 9 additions & 0 deletions Queueify.Tests/UpdaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ public void Only_a_newer_version_is_an_update(string candidate, string current,
Assert.Equal(newer, Updater.IsNewer(candidate, current));
}

[Theory]
[InlineData(null, false, true)] // nothing skipped
[InlineData("1.4.0", false, false)] // skipped: not offered at start
[InlineData("1.4.0", true, true)] // but Check for updates still finds it
[InlineData("1.3.5", false, true)] // a newer one than the skipped one is offered again
public void A_skipped_version_is_only_offered_when_asked_for(string? skipped, bool asked, bool offered)
{
Assert.Equal(offered, Updater.IsWanted(Release(), skipped, asked));
}
// ── Asking GitHub ──

[Fact]
Expand Down
105 changes: 70 additions & 35 deletions Queueify/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public MainWindow()
RefreshQueue();
ShowResults([]);
FillHelp();
// The bar keeps its height from state to state while open; a new window size starts it over.
UpdateBar.Closed += (_, _) => UpdateBar.MinHeight = 0;
SizeChanged += (_, _) => UpdateBar.MinHeight = 0;

// Pick up other PCs' changes when coming back to the window (at most every 20 s).
Activated += (_, args) =>
Expand Down Expand Up @@ -1087,15 +1090,17 @@ private Button RestartButton()
return restart;
}

private enum Restart { Closed, NotStarted, StarterFailed }

/// <summary>
/// Starts a fresh copy and closes this one (which saves the window and layout as usual); false when it
/// couldn't. Through the download's starter, this window stays until the starter has unpacked the new
/// copy and started it, so there's never a moment without Queueify on screen.
/// Starts a fresh copy and closes this one (which saves the window and layout as usual). Through the
/// download's starter, this window stays until the starter has unpacked the new copy and its window is
/// open, so there's never a moment without Queueify on screen, nor two of them.
/// </summary>
private async Task<bool> RestartAppAsync()
private async Task<Restart> RestartAppAsync()
{
// A second click while the new copy starts would start another one.
if (_restarting) return true;
if (_restarting) return Restart.Closed;
_restarting = true;
// Saved first, so the new copy opens where this one was.
SaveWindow();
Expand All @@ -1110,38 +1115,29 @@ private async Task<bool> RestartAppAsync()
{
ShowToast(Loc.F("app.restart_failed", ex.Message), severity: InfoBarSeverity.Warning);
_restarting = false;
return false;
return Restart.NotStarted;
}
using (started)
{
if (started != null && AppData.StarterExe != null)
{
try
// However long the first unpack takes, or the starter's message waits to be read: until
// it's done, nothing else is running.
await started.WaitForExitAsync();
if (started.ExitCode != 0)
{
using var limit = new CancellationTokenSource(TimeSpan.FromMinutes(2));
await started.WaitForExitAsync(limit.Token);
// The starter showed its own message about what went wrong.
if (started.ExitCode != 0)
{
_restarting = false;
return false;
}
// The starter is done once the new copy runs; its window takes a moment more.
while (!NewQueueifyWindow(running))
await Task.Delay(200, limit.Token);
}
catch (OperationCanceledException)
{
// Two minutes without a new window (the starter may be showing an error): this one stays.
_restarting = false;
return false;
return Restart.StarterFailed;
}
// The new copy runs; its window takes a moment more. A minute at most, then this one goes anyway.
for (int i = 0; i < 300 && !NewQueueifyWindow(running); i++)
await Task.Delay(200);
}
}
Close();
return true;
return Restart.Closed;
}

private bool _restarting;

// ───────────────────────── Sync between PCs ─────────────────────────
Expand Down Expand Up @@ -1532,7 +1528,7 @@ private async Task CheckForUpdatesAsync(bool quiet)
try
{
var release = await _updater.CheckAsync(AppInfo.Version, CancellationToken.None);
if (release != null && !_updating) OfferUpdate(release);
if (release != null && !_updating && Updater.IsWanted(release, _ui.SkippedVersion, asked: _reportCheck)) OfferUpdate(release);
if (_reportCheck) ShowUpdateStatus(release != null ? Loc.F("update.available", release.Version) : Loc.T("update.latest"));
}
catch (Exception ex)
Expand All @@ -1557,9 +1553,19 @@ private void ShowUpdateStatus(string text)

private void OfferUpdate(AppRelease release)
{
var whatsNew = new HyperlinkButton { Content = Loc.T("update.whats_new"), Padding = new Thickness(0, 2, 0, 2), Margin = new Thickness(0, 0, 0, 8) };
var whatsNew = new HyperlinkButton { Content = Loc.T("update.whats_new"), Padding = new Thickness(0, 2, 0, 2) };
whatsNew.Click += (_, _) => OpenInBrowser(release.Page);
ShowUpdateBar(InfoBarSeverity.Informational, Loc.F("update.available", release.Version), InstallButton(release, "update.install"), whatsNew, closable: true);
// Not now, and not at the next starts either; Check for updates in About still finds it.
var skip = new HyperlinkButton { Content = Loc.T("update.skip"), Padding = new Thickness(0, 2, 0, 2) };
AutomationProperties.SetAutomationId(skip, "SkipUpdateButton");
skip.Click += (_, _) =>
{
_ui.SkippedVersion = release.Version;
_ui.Save();
UpdateBar.IsOpen = false;
};
var links = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 20, Margin = new Thickness(0, 0, 0, 8), Children = { whatsNew, skip } };
ShowUpdateBar(InfoBarSeverity.Informational, Loc.F("update.available", release.Version), InstallButton(release, "update.install"), links, closable: true);
}

private Button InstallButton(AppRelease release, string text)
Expand Down Expand Up @@ -1612,13 +1618,39 @@ private async Task InstallUpdateAsync(AppRelease release)
_download.Dispose();
_download = null;
}
// The new version unpacks before its window opens: this one says so and stays until then.
ShowUpdateBar(InfoBarSeverity.Informational, Loc.F("update.restarting", release.Version), null,
new ProgressBar { IsIndeterminate = true, Margin = new Thickness(0, 0, 0, 12) }, closable: false);
// The new exe is in place either way; if it can't be started now, the next start uses it. _updating
// stays set, so it isn't downloaded again.
if (!await RestartAppAsync())
ShowUpdateBar(InfoBarSeverity.Warning, Loc.F("update.restart_failed", release.Version), null, null, closable: true);
// The new version unpacks before its window opens: this one says so and stays until then. The
// keyboard waits on the progress indicator (named, so it's read out) instead of falling into the page.
var starting = Loc.F("update.restarting", release.Version);
var wait = new ProgressBar { IsIndeterminate = true, IsTabStop = true, Margin = new Thickness(0, 0, 0, 12) };
AutomationProperties.SetName(wait, starting);
ShowUpdateBar(InfoBarSeverity.Informational, starting, null, wait, closable: false);
switch (await RestartAppAsync())
{
case Restart.StarterFailed:
{
// The new exe itself didn't start (its starter said why), and it's the user's only Queueify
// exe now. What helps first is a version that works, maybe an older one if this release is
// broken: all of them are on the releases page. The same download again only helps when the
// cause was on this PC (disk space, an antivirus).
_updating = false;
var releases = new Button { Content = Loc.T("update.releases"), Style = (Style)Application.Current.Resources["AccentButtonStyle"] };
releases.Click += (_, _) => OpenInBrowser(UpdateSource.AllReleases);
var retry = new HyperlinkButton { Content = Loc.T("update.retry"), Padding = new Thickness(0, 2, 0, 2), Margin = new Thickness(0, 0, 0, 8) };
AutomationProperties.SetAutomationId(retry, "InstallUpdateButton");
retry.Click += (_, _) => _ = InstallUpdateAsync(release);
ShowUpdateBar(InfoBarSeverity.Error, Loc.F("update.start_failed", release.Version), releases, retry, closable: false);
break;
}
case Restart.NotStarted:
{
// The new exe is in place; the next start uses it. _updating stays set, so it isn't
// downloaded again. OK closes the bar, and gives the keyboard somewhere to be meanwhile.
var ok = new Button { Content = Loc.T("update.ok") };
ok.Click += (_, _) => UpdateBar.IsOpen = false;
ShowUpdateBar(InfoBarSeverity.Warning, Loc.F("update.restart_failed", release.Version), ok, null, closable: true);
break;
}
}
}

private static HashSet<int> QueueifyProcesses()
Expand Down Expand Up @@ -1661,7 +1693,10 @@ private void ShowUpdateBar(InfoBarSeverity severity, string message, Microsoft.U
UpdateBar.IsOpen = true;
// Opening, the bar announces itself; later states are said here.
if (wasOpen) Announce(UpdateBar, message);
if (focusInBar && action != null) action.Loaded += (_, _) => action.Focus(FocusState.Keyboard);
// Only grows while open, so the page below doesn't jump up and down from one state to the next.
if (wasOpen) UpdateBar.MinHeight = Math.Max(UpdateBar.MinHeight, UpdateBar.ActualHeight);
if (focusInBar && ((Control?)action ?? content as Control) is { IsTabStop: true } target)
target.Loaded += (_, _) => target.Focus(FocusState.Keyboard);
}

private static bool IsInside(DependencyObject? element, DependencyObject container)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ warn the first time because the app isn't signed: *More info → Run anyway*. Th
version takes a moment longer: the exe unpacks the app into `%LOCALAPPDATA%\Queueify\app` (about 70 MB)
and runs it from there. The copy of the previous version is removed by itself.

**Updates**: when a new version is out, a bar at the top of the window offers it. *Update and restart*
**Updates**: when a new version is out, a bar under the page title offers it. *Update and restart*
downloads it, checks it against the release and puts it in place of your exe, under the same name. Help →
About → *Check for updates* asks right away; Settings → Updates turns off the check at start. (From 1.3.0 or
About → *Check for updates* asks right away; *Skip this version* stops one version from being offered at start; Settings → Updates turns off the check at start. (From 1.3.0 or
earlier, download 1.4.0 by hand once.)

Your queue, keys and layout live in `%LOCALAPPDATA%\Queueify` (Help → *Open data folder*). To move to a new
Expand Down
7 changes: 5 additions & 2 deletions docs/adr/0009-update-from-github-releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ and while the app runs nothing has that exe open: the starter unpacks the app, s
exe is as it was. There's no backup copy: the old version is always on the releases page. A read-only exe
is updated too.
- The app then restarts through the new exe, and its window stays (saying so) until the new version's
window is open: the first start of a version unpacks for a few seconds.
window is open: the first start of a version unpacks for a few seconds. It waits for the starter however
long that takes, so there are never two windows; if the new exe doesn't start (its starter says why),
the bar says so and offers to download it again.
- A failed update says why in plain words and offers **Try again** and the release page.
- When the folder can't be written to, or the app wasn't started from a download (a build folder), the bar
offers the release page instead.
Expand All @@ -38,7 +40,8 @@ and while the app runs nothing has that exe open: the starter unpacks the app, s
- One request to GitHub per start: GitHub sees the address and that Queueify is starting, nothing else;
the setting turns it off. GitHub allows 60 unauthenticated requests an hour per address, plenty for a few
starts a day.
- A closed offer comes back at the next start; there's no "skip this version", only the setting.
- A closed offer comes back at the next start; **Skip this version** keeps that version from being offered at
start (Check for updates still finds it, and a newer one is offered again).
- The release's asset name and its digest are now a contract: renaming the asset, or publishing it somewhere
else, breaks updating for everyone on older versions ([RELEASING.md](../RELEASING.md)).
- The trust is GitHub's: the digest comes from the same API as the download link, over HTTPS. It catches a
Expand Down
Loading
Loading