electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.6k stars 1.73k forks source link

Mac downloads the update, but does not install it #6058

Open alfredsgenkins opened 3 years ago

alfredsgenkins commented 3 years ago

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:

Screenshot 2021-07-14 at 16 23 34

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:

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:

Screenshot 2021-07-14 at 16 32 21

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:

Screenshot 2021-07-14 at 16 36 28

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?

mmaietta commented 3 years ago

That may have been resolved through https://github.com/electron-userland/electron-builder/pull/5802 Please try latest electron-builder at 22.11.9

cuantmac commented 3 years ago

That may have been resolved through #5802 Please try latest electron-builder at 22.11.9

nothing happend

stale[bot] commented 2 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

vraravam commented 2 years ago

I'm on v22.12.1 - same case (nothing fixed)

Nokel81 commented 2 years ago

We are using electron@13.6.0 and electron-updater@4.6.1 and on macos we get the following logs:

Found version 5.3.0-alpha.6.20211026.3
Downloading update from ...
sysctl shell command to check for macOS Rosetta environment failed: Error: Command failed: sysctl sysctl.proc_translated
Update has already been downloaded to

And then I have a log line:

[UPDATE-CHECKER]: User chose to update now

from the following code

logger.info(`${AutoUpdateLogPrefix}: User chose to update now`);
setImmediate(() => {
      app.removeAllListeners("window-all-closed");
      WindowManager.getInstance().destroy();
      autoUpdater.quitAndInstall(true, true);
});

And the windows close (because we are destroying them due to testing) but the quitAndInstall() call doesn't do anything.

I am on macOS 10.15.7

jmeinke commented 2 years ago

We can confirm this issue. It might have something to do with missing administration privileges for being able to update the application. After entering user credentials for allowing the update of the app, then executing the update again it works.

nicograef commented 2 years ago

@Nokel81 Is this a connected (or the same) bug that you fixed with #6390 ? Thanks!

Nokel81 commented 2 years ago

@nicograef It might be. I have not had this problem since using that fix I provided.

theolivenbaum commented 2 years ago

We're seeing the same issue on our app. Update is downloaded, but never installed. Used to work before until recently.

Nokel81 commented 2 years ago

@theolivenbaum Are you using electron-updater@4.6.2?

theolivenbaum commented 2 years ago

Seems like 4.6.1 https://github.com/theolivenbaum/Electron.NET/blob/21427f0b449ba8e4d37e02b037685bb5e9a4d323/ElectronNET.Host/package-lock.json#L411

Was this fixed on 4.6.2? If so I'll give it a try tomorrow!

Nokel81 commented 2 years ago

Yes, my PR was included in 4.6.2 according to the comment posted onto it

helious commented 2 years ago

@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:

"mac": {
    ...
    "target": [
      "default"
    ],

as the the auto updater relies on the .zip, just having "dmg" there won't sign the .zip; but "default" signs the .dmg and .zip.

the logs were able to point me in the right direction:


[2022-02-27 13:55:15.447] [info] Found version 0.0.1 (url: app-0.0.1.dmg)
[2022-02-27 13:55:15.448] [info] Downloading update from app-0.0.1.dmg
[2022-02-27 13:55:15.637] [info] Update has already been downloaded to /Users/user/Library/Application Support/Caches/app-updater/pending/update.zip).
[2022-02-27 13:55:15.657] [info] / requested
[2022-02-27 13:55:15.661] [info] /1645988115637-3819.zip requested
[2022-02-27 13:55:15.661] [info] /1645988115637-3819.zip requested by Squirrel.Mac, pipe /Users/user/Library/Application Support/Caches/app-updater/pending/update.zip
[2022-02-27 13:55:15.945] [warn] Error: ditto: Couldn't read PKZip signature
[2022-02-27 13:55:15.946] [error] Error: Error: ditto: Couldn't read PKZip signature
stale[bot] commented 2 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

amin-wan-kenobi commented 2 years ago

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.

liangskyli commented 12 months ago

I also have the same problem