Skip to content

Commit

Permalink
Show warning when using macOS legacy version unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed May 23, 2024
1 parent 7dcd1bd commit dd0f805
Showing 1 changed file with 41 additions and 24 deletions.
65 changes: 41 additions & 24 deletions src-main/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ const openUpdatePage = () => {
safelyOpenExternal('https://desktop.turbowarp.org/');
};

/**
* @returns {number}
*/
const getElectronMajorVersion = () => +process.versions.electron.split('.')[0];

/**
* @returns {number}
*/
const getKernelMajorVersion = () => {
// This is the only place that uses os, so try to load it lazily
const os = require('os');
return +os.release().split('.')[0];
};

/**
* @returns {boolean} true if the app should continue to launch
*/
Expand All @@ -53,32 +67,35 @@ const migrate = async () => {
return false;
}

// Legacy version (Electron 22) should only be used on Windows 7, 8, and 8.1
if (packageJSON.tw_warn_legacy && process.platform === 'win32') {
const electronMajorVersion = +process.versions.electron.split('.')[0];
if (electronMajorVersion === 22) {
// Note that the real version number before 10 is actually 6.x
const os = require('os');
const windowsMajorVersion = +os.release().split('.')[0];
if (windowsMajorVersion >= 10 && dialog.showMessageBoxSync({
title: APP_NAME,
type: 'warning',
message: translate('unnecessary-legacy.title'),
detail: translate('unnecessary-legacy.message').replace('{APP_NAME}', APP_NAME),
buttons: [
translate('unnecessary-legacy.ok'),
translate('unnecessary-legacy.ignore'),
],
cancelId: 0,
defaultId: 0,
noLink: true
}) === 0) {
openUpdatePage();
return false;
}
// Ask people not to use legacy versions unnecessarily
if (packageJSON.tw_warn_legacy && (
// Legacy build for Windows before version 10 uses Electron 22
// See https://en.wikipedia.org/wiki/Windows_NT#Releases for kernel versions
(process.platform === 'win32' && getElectronMajorVersion() === 22 && getKernelMajorVersion() >= 10) ||

// Legacy build for macOS 10.13 and 10.14 uses Electron 26
// See https://en.wikipedia.org/wiki/Darwin_%28operating_system%29#Release_history for kernel versions
(process.platform === 'darwin' && getElectronMajorVersion() === 26 && getKernelMajorVersion() >= 19)
)) {
const result = dialog.showMessageBoxSync({
title: APP_NAME,
type: 'warning',
message: translate('unnecessary-legacy.title'),
detail: translate('unnecessary-legacy.message').replace('{APP_NAME}', APP_NAME),
buttons: [
translate('unnecessary-legacy.ok'),
translate('unnecessary-legacy.ignore'),
],
cancelId: 0,
defaultId: 0,
noLink: true
})
if (result === 0) {
openUpdatePage();
return false;
}
}

// On first launch, there is no data to migrate, so just save the current versions.
if (isFirstLaunch) {
await writeCurrentVersion();
Expand Down

0 comments on commit dd0f805

Please sign in to comment.