Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(update): distinguish a failed download from a failed check
Etienne Lescotdbe8a1f6981e
diff --git a/electron/auto-updater.test.ts b/electron/auto-updater.test.tsindex 276155ef6..17958b54a 100644--- a/electron/auto-updater.test.ts+++ b/electron/auto-updater.test.ts@@ -1,5 +1,28 @@-import { describe, expect, it } from "vitest";-import { blockedFromInstalling, type InstallReadiness } from "./auto-updater";+import { beforeEach, describe, expect, it, vi } from "vitest";+import {+ blockedFromInstalling,+ checkForSelfUpdate,+ downloadSelfUpdate,+ type InstallReadiness,+ installSelfUpdate,+} from "./auto-updater";++const mocks = vi.hoisted(() => ({+ // Deliberately initialised to electron-updater's DEFAULTS, so a test asserting they are+ // false proves our configuration ran rather than reading a value that was never touched.+ autoUpdater: {+ autoDownload: true,+ autoInstallOnAppQuit: true,+ logger: {} as unknown,+ checkForUpdates: vi.fn(),+ downloadUpdate: vi.fn(),+ quitAndInstall: vi.fn(),+ },+ app: { isPackaged: true, getVersion: vi.fn(() => "1.9.2") },+}));++vi.mock("electron", () => ({ app: mocks.app }));+vi.mock("electron-updater", () => ({ autoUpdater: mocks.autoUpdater }));function state(overrides: Partial<InstallReadiness> = {}): InstallReadiness {return { recording: false, inApplicationsFolder: true, platform: "linux", ...overrides };@@ -43,3 +66,78 @@ describe("blockedFromInstalling", () => {).toBe("recording");});});++describe("self-update flow", () => {+ beforeEach(() => {+ mocks.app.isPackaged = true;+ mocks.autoUpdater.checkForUpdates.mockReset();+ mocks.autoUpdater.downloadUpdate.mockReset();+ mocks.autoUpdater.quitAndInstall.mockReset();+ });++ it("never touches the updater on a channel a package manager owns", async () => {+ for (const channel of ["store", "flatpak", "snap", "nix"] as const) {+ await expect(checkForSelfUpdate(channel)).resolves.toEqual({ kind: "unsupported" });+ }+ expect(mocks.autoUpdater.checkForUpdates).not.toHaveBeenCalled();+ });++ it("refuses to self-update an unpacked build", async () => {+ mocks.app.isPackaged = false;+ await expect(checkForSelfUpdate("nsis")).resolves.toEqual({ kind: "unsupported" });+ expect(mocks.autoUpdater.checkForUpdates).not.toHaveBeenCalled();+ });++ // These three settings are the difference between an update and a lost recording, and each+ // looks like harmless boilerplate to delete. `window-all-closed` quits this app and the HUD+ // is a window, so the stock autoInstallOnAppQuit would fire a ~243 MB installer when the+ // user merely closed the HUD.+ it("disables auto-download and install-on-quit before doing anything", async () => {+ mocks.autoUpdater.checkForUpdates.mockResolvedValue({ updateInfo: { version: "1.9.2" } });+ await checkForSelfUpdate("nsis");+ expect(mocks.autoUpdater.autoDownload).toBe(false);+ expect(mocks.autoUpdater.autoInstallOnAppQuit).toBe(false);+ });++ it("reports current when the feed offers the running version", async () => {+ mocks.autoUpdater.checkForUpdates.mockResolvedValue({ updateInfo: { version: "1.9.2" } });+ await expect(checkForSelfUpdate("appimage")).resolves.toEqual({ kind: "current" });+ });++ it("reports current when no feed resolves, rather than claiming an update", async () => {+ mocks.autoUpdater.checkForUpdates.mockResolvedValue(null);+ await expect(checkForSelfUpdate("deb")).resolves.toEqual({ kind: "current" });+ });++ it("surfaces an available version", async () => {+ mocks.autoUpdater.checkForUpdates.mockResolvedValue({ updateInfo: { version: "1.10.0" } });+ await expect(checkForSelfUpdate("dmg")).resolves.toEqual({+ kind: "downloaded",+ version: "1.10.0",+ });+ });++ // A release published before the update feeds existed has no latest*.yml. That must degrade+ // to the release-page fallback, not throw into main-process-errors, which re-throws.+ it("reports a missing or broken feed as failed instead of throwing", async () => {+ mocks.autoUpdater.checkForUpdates.mockRejectedValue(new Error("404 latest.yml"));+ const result = await checkForSelfUpdate("nsis");+ expect(result.kind).toBe("failed");+ expect(result).toMatchObject({ error: { message: "404 latest.yml" } });+ });++ it("reports a failed download instead of throwing", async () => {+ mocks.autoUpdater.downloadUpdate.mockRejectedValue(new Error("connection reset"));+ const result = await downloadSelfUpdate();+ expect(result.kind).toBe("failed");+ expect(result).toMatchObject({ error: { message: "connection reset" } });+ });++ // isSilent=false so a per-machine Windows install can show its UAC prompt — a silent upgrade+ // of a Program Files install hits elevation and, if dismissed, quits having done nothing.+ // isForceRunAfter=true so the app comes back.+ it("hands over to the installer non-silently and relaunches", async () => {+ await installSelfUpdate();+ expect(mocks.autoUpdater.quitAndInstall).toHaveBeenCalledWith(false, true);+ });+});diff --git a/electron/main.ts b/electron/main.tsindex f51bcafa5..60313e3ed 100644--- a/electron/main.ts+++ b/electron/main.ts@@ -378,7 +378,9 @@ async function downloadAndInstall(latestVersion: string) {await dialog.showMessageBox({type: "error",title: app.name,- message: mainT("common", "updates.failed"),+ // Not `updates.failed`: the CHECK succeeded — that is how we got here — and telling+ // the user we could not check for updates sends them looking in the wrong place.+ message: mainT("common", "updates.downloadFailed"),detail: downloaded.error.message,});return;diff --git a/src/i18n/locales/ar/common.json b/src/i18n/locales/ar/common.jsonindex 4790f15c6..29acacda1 100644--- a/src/i18n/locales/ar/common.json+++ b/src/i18n/locales/ar/common.json@@ -47,7 +47,8 @@"readyToInstall": "تم تنزيل OpenScreen {{latestVersion}}. أعد التشغيل لإكمال التثبيت.","blockedRecording": "أنهِ التسجيل قبل تثبيت التحديث.","blockedLocation": "انقل OpenScreen إلى مجلد التطبيقات قبل التحديث.",- "failed": "تعذّر التحقق من وجود تحديثات."+ "failed": "تعذّر التحقق من وجود تحديثات.",+ "downloadFailed": "تعذّر تنزيل التحديث."},"playback": {"play": "تشغيل",diff --git a/src/i18n/locales/en/common.json b/src/i18n/locales/en/common.jsonindex 7bb798c3d..f08159335 100644--- a/src/i18n/locales/en/common.json+++ b/src/i18n/locales/en/common.json@@ -47,7 +47,8 @@"readyToInstall": "OpenScreen {{latestVersion}} has been downloaded. Restart to finish installing.","blockedRecording": "Finish your recording before installing the update.","blockedLocation": "Move OpenScreen to your Applications folder before updating.",- "failed": "Could not check for updates."+ "failed": "Could not check for updates.",+ "downloadFailed": "Could not download the update."},"playback": {"play": "Play",diff --git a/src/i18n/locales/es/common.json b/src/i18n/locales/es/common.jsonindex 17dec8e2f..d65cac3aa 100644--- a/src/i18n/locales/es/common.json+++ b/src/i18n/locales/es/common.json@@ -47,7 +47,8 @@"readyToInstall": "Se ha descargado OpenScreen {{latestVersion}}. Reinicia para completar la instalación.","blockedRecording": "Termina la grabación antes de instalar la actualización.","blockedLocation": "Mueve OpenScreen a la carpeta Aplicaciones antes de actualizar.",- "failed": "No se pudieron buscar actualizaciones."+ "failed": "No se pudieron buscar actualizaciones.",+ "downloadFailed": "No se pudo descargar la actualización."},"playback": {"play": "Reproducir",diff --git a/src/i18n/locales/fr/common.json b/src/i18n/locales/fr/common.jsonindex 32dce1fe1..1041a771a 100644--- a/src/i18n/locales/fr/common.json+++ b/src/i18n/locales/fr/common.json@@ -47,7 +47,8 @@"readyToInstall": "OpenScreen {{latestVersion}} a été téléchargé. Redémarrez pour terminer l'installation.","blockedRecording": "Terminez votre enregistrement avant d'installer la mise à jour.","blockedLocation": "Déplacez OpenScreen dans le dossier Applications avant de le mettre à jour.",- "failed": "Impossible de rechercher les mises à jour."+ "failed": "Impossible de rechercher les mises à jour.",+ "downloadFailed": "Impossible de télécharger la mise à jour."},"playback": {"play": "Lecture",diff --git a/src/i18n/locales/it/common.json b/src/i18n/locales/it/common.jsonindex d1dce3518..ca715f234 100644--- a/src/i18n/locales/it/common.json+++ b/src/i18n/locales/it/common.json@@ -47,7 +47,8 @@"readyToInstall": "OpenScreen {{latestVersion}} è stato scaricato. Riavvia per completare l'installazione.","blockedRecording": "Termina la registrazione prima di installare l'aggiornamento.","blockedLocation": "Sposta OpenScreen nella cartella Applicazioni prima di aggiornare.",- "failed": "Impossibile controllare gli aggiornamenti."+ "failed": "Impossibile controllare gli aggiornamenti.",+ "downloadFailed": "Impossibile scaricare l'aggiornamento."},"playback": {"play": "Riproduci",diff --git a/src/i18n/locales/ja-JP/common.json b/src/i18n/locales/ja-JP/common.jsonindex ddbf3a6a4..c2dba1331 100644--- a/src/i18n/locales/ja-JP/common.json+++ b/src/i18n/locales/ja-JP/common.json@@ -47,7 +47,8 @@"readyToInstall": "OpenScreen {{latestVersion}} をダウンロードしました。再起動してインストールを完了してください。","blockedRecording": "アップデートをインストールする前に録画を終了してください。","blockedLocation": "アップデートする前に OpenScreen をアプリケーションフォルダに移動してください。",- "failed": "アップデートを確認できませんでした。"+ "failed": "アップデートを確認できませんでした。",+ "downloadFailed": "アップデートをダウンロードできませんでした。"},"playback": {"play": "再生",diff --git a/src/i18n/locales/ko-KR/common.json b/src/i18n/locales/ko-KR/common.jsonindex 6d8e18b58..2a9593155 100644--- a/src/i18n/locales/ko-KR/common.json+++ b/src/i18n/locales/ko-KR/common.json@@ -47,7 +47,8 @@"readyToInstall": "OpenScreen {{latestVersion}}을(를) 다운로드했습니다. 다시 시작하여 설치를 완료하세요.","blockedRecording": "업데이트를 설치하기 전에 녹화를 마치세요.","blockedLocation": "업데이트하기 전에 OpenScreen을 응용 프로그램 폴더로 옮기세요.",- "failed": "업데이트를 확인할 수 없습니다."+ "failed": "업데이트를 확인할 수 없습니다.",+ "downloadFailed": "업데이트를 다운로드하지 못했습니다."},"playback": {"play": "재생",diff --git a/src/i18n/locales/pt-BR/common.json b/src/i18n/locales/pt-BR/common.jsonindex db985cb7b..7cdad691c 100644--- a/src/i18n/locales/pt-BR/common.json+++ b/src/i18n/locales/pt-BR/common.json@@ -47,7 +47,8 @@"readyToInstall": "O OpenScreen {{latestVersion}} foi baixado. Reinicie para concluir a instalação.","blockedRecording": "Conclua a gravação antes de instalar a atualização.","blockedLocation": "Mova o OpenScreen para a pasta Aplicativos antes de atualizar.",- "failed": "Não foi possível verificar atualizações."+ "failed": "Não foi possível verificar atualizações.",+ "downloadFailed": "Não foi possível baixar a atualização."},"playback": {"play": "Play",diff --git a/src/i18n/locales/ru/common.json b/src/i18n/locales/ru/common.jsonindex 699a6c68f..4cfca236e 100644--- a/src/i18n/locales/ru/common.json+++ b/src/i18n/locales/ru/common.json@@ -47,7 +47,8 @@"readyToInstall": "OpenScreen {{latestVersion}} загружен. Перезапустите, чтобы завершить установку.","blockedRecording": "Завершите запись перед установкой обновления.","blockedLocation": "Переместите OpenScreen в папку «Программы» перед обновлением.",- "failed": "Не удалось проверить наличие обновлений."+ "failed": "Не удалось проверить наличие обновлений.",+ "downloadFailed": "Не удалось загрузить обновление."},"playback": {"play": "Воспроизвести",diff --git a/src/i18n/locales/tr/common.json b/src/i18n/locales/tr/common.jsonindex 23c790d18..c2ca46a0f 100644--- a/src/i18n/locales/tr/common.json+++ b/src/i18n/locales/tr/common.json@@ -47,7 +47,8 @@"readyToInstall": "OpenScreen {{latestVersion}} indirildi. Kurulumu tamamlamak için yeniden başlatın.","blockedRecording": "Güncellemeyi yüklemeden önce kaydınızı tamamlayın.","blockedLocation": "Güncellemeden önce OpenScreen'i Uygulamalar klasörüne taşıyın.",- "failed": "Güncellemeler denetlenemedi."+ "failed": "Güncellemeler denetlenemedi.",+ "downloadFailed": "Güncelleme indirilemedi."},"playback": {"play": "Oynat",diff --git a/src/i18n/locales/vi/common.json b/src/i18n/locales/vi/common.jsonindex 7bfbe4b1a..d5e2ed4c0 100644--- a/src/i18n/locales/vi/common.json+++ b/src/i18n/locales/vi/common.json@@ -47,7 +47,8 @@"readyToInstall": "Đã tải xuống OpenScreen {{latestVersion}}. Khởi động lại để hoàn tất cài đặt.","blockedRecording": "Hãy kết thúc bản ghi trước khi cài đặt bản cập nhật.","blockedLocation": "Hãy chuyển OpenScreen vào thư mục Applications trước khi cập nhật.",- "failed": "Không thể kiểm tra bản cập nhật."+ "failed": "Không thể kiểm tra bản cập nhật.",+ "downloadFailed": "Không thể tải xuống bản cập nhật."},"playback": {"play": "Phát",diff --git a/src/i18n/locales/zh-CN/common.json b/src/i18n/locales/zh-CN/common.jsonindex 6408caf0e..7607db7ab 100644--- a/src/i18n/locales/zh-CN/common.json+++ b/src/i18n/locales/zh-CN/common.json@@ -47,7 +47,8 @@"readyToInstall": "OpenScreen {{latestVersion}} 已下载完成。重启以完成安装。","blockedRecording": "请先结束录制,再安装更新。","blockedLocation": "更新前请将 OpenScreen 移动到「应用程序」文件夹。",- "failed": "无法检查更新。"+ "failed": "无法检查更新。",+ "downloadFailed": "无法下载更新。"},"playback": {"play": "播放",diff --git a/src/i18n/locales/zh-TW/common.json b/src/i18n/locales/zh-TW/common.jsonindex 5c8c2f440..186e68224 100644--- a/src/i18n/locales/zh-TW/common.json+++ b/src/i18n/locales/zh-TW/common.json@@ -47,7 +47,8 @@"readyToInstall": "OpenScreen {{latestVersion}} 已下載完成。請重新啟動以完成安裝。","blockedRecording": "請先結束錄影,再安裝更新。","blockedLocation": "更新前請將 OpenScreen 移至「應用程式」資料夾。",- "failed": "無法檢查更新。"+ "failed": "無法檢查更新。",+ "downloadFailed": "無法下載更新。"},"playback": {"play": "播放",