electron-releases: autoUpdater.quitAndInstall fails to relaunch on Mac OS 11 Big Sur
When 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);
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 29
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.
I can confirm it also works in
v11.2.0-wvvmp
. Thanks again!I’ve done some more debugging/logging and found some useful information.
Current code example (for my test with ECS, I return
success()
inonWidevineReady
for my test with Electron):This results in the following logs. ECS:
Electron:
Other than that you can see that we never get a
ready-to-show
after updating in ECS, there’s not much other useful information here. However, theShipIt_stderr.log
gives more useful information.ECS:
Electron:
The reason restarting fails in ECS, is because of this I think:
I also noticed someone commenting on the original Electron issue about this. But not sure whether that person is using Electron or a fork.