electron-builder: Mac downloads the update, but does not install it
- Electron-Builder Version:
^22.10.5
- Node Version:
v14.17.0
- Electron Version:
^11.0.1 - Electron Type (current, beta, nightly):
current
- Target:
dmg
Hey!
This issue is similar by description to https://github.com/electron-userland/electron-builder/issues/2317, but I have not found any answers there. I decided to open new issue and provide more background.
My application on Mac shows the following notification:
But once I close and reopen the app back nothing happens. The old version is still displayed. I also want my application use the quitAndInstall pattern. For me the fact the the notification is displayed in the first place is strange.
The background:
- I have configured automatic updates for my application
- I have made my application notarized by apple
- I want to use
quitAndInstall, I have ensure the safe exit - I am using Private GitHub repository to store releases
- Autoupdate on Linux AppImage works
How my application handles an update:
import { app, BrowserWindow, shell } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
function ensureSafeQuitAndInstall() {
app.removeAllListeners('window-all-closed');
const browserWindows = BrowserWindow.getAllWindows();
browserWindows.forEach((browserWindow) => {
browserWindow.removeAllListeners('close');
});
autoUpdater.quitAndInstall(false);
}
export default class AppUpdater {
constructor() {
log.transports.file.level = 'info';
autoUpdater.logger = log;
autoUpdater.checkForUpdatesAndNotify();
autoUpdater.on('update-downloaded', () => {
setImmediate(ensureSafeQuitAndInstall);
});
}
}
I took the code sample from this issue and built my implementation on top if it: https://github.com/electron-userland/electron-builder/issues/1604
Why I think the signature is fine:
Despite me expecting the signature with the Developer ID, the app only shows notarization and hardening. Not sure why. The app however, only promts the this on first install, thus I assume it is OK:
How I sign my app:
I used following configuration in package.json:
...
"afterSign": ".erb/scripts/Notarize.js",
"mac": {
...
"target": [
"dmg"
],
"asarUnpack": "**/*.node",
"type": "distribution",
"hardenedRuntime" : true,
"gatekeeperAssess": false,
"entitlements": "assets/entitlements.mac.plist",
"entitlementsInherit": "assets/entitlements.mac.plist",
"icon": "assets/icons/mac/icon.icns",
"provisioningProfile": "assets/preflight_provision_profile.provisionprofile"
},
...
My notarization script is using electron-notarize and I sign it with following code:
const { notarize } = require('electron-notarize');
const { build } = require('../../package.json');
exports.default = async function notarizeMacos(context) {
const { electronPlatformName, appOutDir } = context;
const appName = context.packager.appInfo.productFilename;
await notarize({
appBundleId: build.appId,
appPath: `${appOutDir}/${appName}.app`,
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_ID_PASS,
ascProvider: process.env.APPLE_PROVIDER_ID,
});
};
I build my app using following command:
CSC_LINK="XXX" \
CSC_KEY_PASSWORD=XXX \
APPLE_ID="XXX" \
APPLE_ID_PASS="XXX" \
APPLE_PROVIDER_ID="XXX" \
yarn electron-builder build -mwl --publish always
What I also suspect:
The react boilerplate I use, contained the following code:
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
I heared that this could prevent app from closing. But I call app.removeAllListeners('window-all-closed') thus this should not be the case.
In logs, I see following message (relating me to https://github.com/electron-userland/electron-builder/issues/486, but again, this appears to not break anything):
[XXX] [warn] Error: ditto: Couldn't read PKZip signature
[XXX] [error] Error: Error: ditto: Couldn't read PKZip signature
Any ideas, suggestions?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 2
- Comments: 16 (5 by maintainers)
@alfredsgenkins I think I’ve figured this out… after stumbling around the myriad threads on this issue, it’s a simple configuration setting 😆 (https://www.electron.build/configuration/mac#MacConfiguration-target)
so just doing this:
as the the auto updater relies on the
.zip, just having"dmg"there won’t sign the.zip; but"default"signs the.dmgand.zip.the logs were able to point me in the right direction:
Hi Everyone, I had the same issue in MacOS and I managed to solve it. Below is the code which was not working.
autoUpdater.on("update-downloaded", updateInfo => { autoUpdater.quitAndInstall(); })It closed the app but it never relaunched it. So I checked both log files of the electron app as well as the ShipIt and I realized that the moment the download is done, it would send a request to install the new application (even if you don’t call the quitAndInstall method). So to fix the issue, I just exited the app with a bit of a delay as it seems there is some sort of race issue here.autoUpdater.on("update-downloaded", updateInfo => { setTimeout(() => { autoUpdater.quitAndInstall(); app.exit(); }, 10000); })I checked the logs in ShipIt at the same time and I saw that it began the installation process and right after it relaunched the app. So if you’re on mac, try to exit (not quit) after the download is done. Mine works now. I hope it helps.