Skip to content

Commit

Permalink
Warn when someone downgrades across dataVersion boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Nov 25, 2023
1 parent 5feb544 commit 65e76d8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src-main/l10n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 30 additions & 1 deletion src-main/migrate.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src-main/windows/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {APP_NAME} = require('../brand');
const EMAIL = '[email protected]';

class MigrateWindow extends BaseWindow {
static LATEST_VERSION = 3;
static LATEST_VERSION = 2;

constructor () {
super();
Expand Down

0 comments on commit 65e76d8

Please sign in to comment.