From 65e76d8e99b0c20c2b077ffcc4d786b04fea4ab8 Mon Sep 17 00:00:00 2001 From: Muffin Date: Sat, 25 Nov 2023 17:17:06 -0600 Subject: [PATCH] Warn when someone downgrades across dataVersion boundaries --- src-main/l10n/en.json | 12 ++++++++++++ src-main/migrate.js | 31 ++++++++++++++++++++++++++++++- src-main/windows/migrate.js | 2 +- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src-main/l10n/en.json b/src-main/l10n/en.json index 6501acde..d2c97b27 100644 --- a/src-main/l10n/en.json +++ b/src-main/l10n/en.json @@ -287,6 +287,18 @@ "string": "Deleting old data...", "developer_comment": "Status message that appears while finishing an update. Old data refers to data stored by old versions of the app that is now redundant after updates." }, + "migrate-future.message": { + "string": "It looks like you installed an older version of {APP_NAME} after using a later version. Downgrading is not guaranteed to be safe; you may lose data such as your settings and backpack. Please exit and download the latest version from {website}. (Debug info: {debugInfo})", + "developer_comment": "May appear when someone installs the latest version of the dekstop app, runs it, then installs and runs an older version. {APP_NAME} becomes 'TurboWarp Desktop'. {website} becomes a URL like 'desktop.turbowarp.org'. {debugInfo} becomes something like '2 < 3' (internal version numbers) to aid with debugging." + }, + "migrate-future.exit": { + "string": "Exit and Update", + "developer_comment": "May appear when someone installs the latest version of the dekstop app, runs it, then installs and runs an older version. This button exits the app and opens the website for someone to download the latest version." + }, + "migrate-future.continue-anyways": { + "string": "Continue Anyways (Unsafe)", + "developer_comment": "May appear when someone installs the latest version of the dekstop app, runs it, then installs and runs an older version. This button accepts the warning and will just continue anyways, hoping for the best." + }, "update.window-title": { "string": "Update Available", "developer_comment": "Title of update available window" diff --git a/src-main/migrate.js b/src-main/migrate.js index 8249d1f9..30a79e33 100644 --- a/src-main/migrate.js +++ b/src-main/migrate.js @@ -1,8 +1,11 @@ -const {app} = require('electron'); +const {app, dialog} = require('electron'); const fs = require('fs'); const path = require('path'); const settings = require('./settings'); const MigrateWindow = require('./windows/migrate'); +const {APP_NAME} = require('./brand'); +const {translate} = require('./l10n'); +const safelyOpenExternal = require('./open-external'); // Avoid running migrate logic on fresh installs when we can. Not required, just helps // user experience. This must run before the ready event. @@ -14,6 +17,32 @@ const isFirstLaunch = ( ); const migrate = async () => { + if (settings.dataVersion > MigrateWindow.LATEST_VERSION) { + const result = dialog.showMessageBoxSync({ + type: 'error', + title: APP_NAME, + message: translate('migrate-future.message') + .replace('{APP_NAME}', APP_NAME) + .replace('{website}', 'desktop.turbowarp.org') + .replace('{debugInfo}', `${MigrateWindow.LATEST_VERSION} < ${settings.dataVersion}`), + buttons: [ + translate('migrate-future.exit'), + translate('migrate-future.continue-anyways') + ], + cancelId: 0, + defaultId: 0 + }); + if (result === 0) { + safelyOpenExternal('https://desktop.turbowarp.org/'); + app.exit(1); + } else { + // Hope for the best! + settings.dataVersion = MigrateWindow.LATEST_VERSION; + await settings.save(); + return; + } + } + if (settings.dataVersion === MigrateWindow.LATEST_VERSION) { return; } diff --git a/src-main/windows/migrate.js b/src-main/windows/migrate.js index dcbac3de..97e42ca7 100644 --- a/src-main/windows/migrate.js +++ b/src-main/windows/migrate.js @@ -8,7 +8,7 @@ const {APP_NAME} = require('../brand'); const EMAIL = 'contact@turbowarp.org'; class MigrateWindow extends BaseWindow { - static LATEST_VERSION = 3; + static LATEST_VERSION = 2; constructor () { super();