autoUpdater.quitAndInstall fails to relaunch on Mac OS 11 Big Sur
See original GitHub issueWhen restarting an upgraded Electron application with autoUpdater.quitAndInstall
, the application quits and upgrades successfully, but is NOT relaunched. There’s also an issue about this in the Electron repository.
It works as expected for me with Electron 11.1.1, but it fails with 11.1.1-wvvmp. It only fails on Big Sur and succeeds on Catalina and Mojave. I’ve created a minimal code example to reproduce:
import {
BrowserWindow,
Notification,
app,
autoUpdater,
dialog,
globalShortcut,
} from 'electron';
import * as path from 'path';
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'production';
}
interface VersionInfo {
appVersion: string;
packageVersion: string;
}
function getVersion(): VersionInfo {
return {
appVersion: process.env.APP_VERSION || 'DEVELOP',
packageVersion: process.env.PACKAGE_VERSION || '',
};
}
function onAppReady(cb: Function) {
if (app.isReady()) {
cb();
} else {
app.on('ready', () => cb());
}
}
function appReady(): Promise<void> {
return new Promise((resolve) => {
onAppReady(() => resolve());
});
}
const UPDATE_URL =
process.platform === 'darwin'
? `https://update-server-mac.com/updates/latest?v=${getVersion().packageVersion}`
: 'https://update-server-windows.com/desktop/windows/';
function createWindow() {
const webPreferences = {
contextIsolation: true,
enableRemoteModule: true,
nodeIntegration: false,
plugins: true,
webSecurity: true,
worldSafeExecuteJavaScript: true,
};
const mainWindow = new BrowserWindow({
backgroundColor: '#ff0000',
enableLargerThanScreen: true,
frame: false,
icon: path.resolve(`${__dirname}/../app/assets/icons/icon.png`),
show: false,
title: 'My app',
titleBarStyle: 'hiddenInset',
webPreferences,
width: 640,
height: 480,
});
// Prevents title from being set to <title> of web
mainWindow.on('page-title-updated', (e) => e.preventDefault());
const webContents = mainWindow.webContents;
webContents.on(
'certificate-error',
(
_: Electron.Event,
url: string,
error: string,
certificate: Electron.Certificate,
callback: (isTrusted: boolean) => void,
) => {
console.error(
new Error(
`Certificate error (${error}) on "${url}" with certificate "${certificate.issuerName}"`,
),
);
callback(false); // reject everything
},
);
webContents.on('render-process-gone', (_, { reason }) => {
console.error('Renderer process crashed', reason);
});
webContents.on('responsive', () => {
console.log('Renderer process is responsive again');
});
webContents.on('unresponsive', () => {
console.warn('Renderer process is unresponsive');
});
webContents.once('destroyed', () => {
console.log('Web content was destroyed');
});
webContents.on('new-window', (event: Electron.Event) => {
event.preventDefault();
return false;
});
webContents.on(
'did-fail-load',
(
_: Electron.Event,
errorCode: number,
errorDescription: string,
validateURL: string,
) => {
if (validateURL === webContents.getURL()) {
console.error(
new Error(
`Web Content failed to load (${errorCode}: ${errorDescription}) on "${validateURL}"`,
),
);
}
},
);
mainWindow.loadURL(`file://${__dirname}/../app/assets/index.html`);
mainWindow.on('close', () => {
console.log('mainWindow on close');
});
// Must be called here, else it doesn't show up
mainWindow.once('ready-to-show', () => {
console.log('ready-to-show');
mainWindow.show();
});
}
function startAutoUpdater() {
autoUpdater.on('checking-for-update', () =>
console.log('Checking for updates'),
);
autoUpdater.on('error', (error: Error) => {
console.error(error);
const notification = {
title: 'Auto update error',
body: error.message,
};
new Notification(notification).show();
});
autoUpdater.on('update-available', () => {
console.log('Update available');
const notification = {
title: 'Auto update',
body: 'Update available',
};
new Notification(notification).show();
});
autoUpdater.on('update-downloaded', (_, releaseNotes, releaseName) => {
console.log('Update downloaded');
const dialogOpts = {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Application Update',
message: process.platform === 'win32' ? releaseNotes : releaseName,
detail:
'A new version has been downloaded. Restart the application to apply the updates.',
};
dialog.showMessageBox(dialogOpts).then((returnValue: any) => {
if (returnValue.response === 0) autoUpdater.quitAndInstall();
});
});
autoUpdater.on('update-not-available', () => {
console.log('No update found');
const notification = {
title: 'Auto update',
body: 'No updates found',
};
new Notification(notification).show();
});
autoUpdater.setFeedURL({
url: UPDATE_URL,
});
}
const main = async () => {
// Prevent multiple app instances
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.exit();
return;
}
app.allowRendererProcessReuse = true;
// Allow playback to be started from electron (without DOM interaction)
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');
await appReady();
const notification = {
title: 'App version',
body: getVersion().appVersion,
};
new Notification(notification).show();
startAutoUpdater();
globalShortcut.register('CommandOrControl+U', () => {
console.log('Shortcut triggered to check for updates');
autoUpdater.checkForUpdates();
});
createWindow();
};
try {
main();
} catch (error) {
console.error('Failed to execute main:', error);
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:29
Top Results From Across the Web
autoUpdater.quitAndInstall fails to relaunch on Mac OS 11 Big ...
quitAndInstall fails to relaunch on Mac OS 11 Big Sur #25626 ... When restarting an upgraded electron application with autoUpdater.
Read more >Electron auto-updater not relaunching the app - Stack Overflow
I am trying to set auto update in my electron mac app. I am using the following code: const autoUpdater = electron. autoUpdater;...
Read more >Update to 11.6 Big Sur fails - Apple Community
My IMac fails to update to the new 11.6 Big Sur. The update down loads and then goes through "preparing to install" but...
Read more >2021 PhotoStructure release notes
File paths in the Asset Info panel could have rendering issues. / macOS Big Sur versions are now rendered properly on m1 machines....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for the slow reply! as far as I know this has been working fine for us lately 😃
Ok, thanks for letting me know @koenoe. Since I’ve heard nothing new I’ll consider this resolved and close the issue. Please reopen if it turns out this is still an issue.