From e14df85e39a27944fdc4d5aecf084a68d7fd00c2 Mon Sep 17 00:00:00 2001 From: André Oliveira <37463445+SpecialAro@users.noreply.github.com> Date: Fri, 3 Jun 2022 19:56:48 -0500 Subject: Enable AutoUpdates from in-app with self-sign certificates on macOS (#213) Co-authored-by: Alphrag --- .github/workflows/builds.yml | 4 ++-- electron-builder.yml | 4 +++- src/electron/ipc-api/autoUpdate.ts | 13 ++++++++----- src/index.ts | 17 +++++++++++++++-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 610826872..033c7df73 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -170,7 +170,7 @@ jobs: shell: bash env: GH_TOKEN: ${{ secrets.FERDIUM_PUBLISH_TOKEN }} - CSC_IDENTITY_AUTO_DISCOVERY: false + CSC_IDENTITY_AUTO_DISCOVERY: true # TODO: Commented out the code signing process for now (so as to at least get unsigned nightlies available for testing) # APPLEID: ${{ secrets.APPLEID }} # APPLEID_PASSWORD: ${{ secrets.APPLEID_PASSWORD }} @@ -368,7 +368,7 @@ jobs: shell: bash env: GH_TOKEN: ${{ secrets.FERDIUM_PUBLISH_TOKEN }} - CSC_IDENTITY_AUTO_DISCOVERY: false + CSC_IDENTITY_AUTO_DISCOVERY: true # TODO: Commented out the code signing process for now (so as to at least get unsigned nightlies available for testing) # WIN_CSC_LINK: ${{ secrets.WIN_CSC_LINK }} # WIN_CSC_KEY_PASSWORD: ${{ secrets.WIN_CSC_KEY_PASSWORD }} diff --git a/electron-builder.yml b/electron-builder.yml index 822200234..64809a6da 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -26,7 +26,9 @@ dmg: { x: 122, y: 240, type: file }, ] -afterSign: ./build-helpers/notarize.js +# TODO: When we have a registered developer account we need to uncomment this line so that the signing process can occur but without the notarization. +# This is the notarization which would allow to have the DMG analysed so that it can be opened straight away after download. +# afterSign: ./build-helpers/notarize.js protocols: name: Ferdium diff --git a/src/electron/ipc-api/autoUpdate.ts b/src/electron/ipc-api/autoUpdate.ts index d20a413b3..fb91d3515 100644 --- a/src/electron/ipc-api/autoUpdate.ts +++ b/src/electron/ipc-api/autoUpdate.ts @@ -1,6 +1,7 @@ -import { app, ipcMain, BrowserWindow } from 'electron'; +import { ipcMain, BrowserWindow } from 'electron'; import { autoUpdater } from 'electron-updater'; import { isMac, isWindows } from '../../environment'; +import { appEvents } from '../..'; const debug = require('../../preload-safe-debug')('Ferdium:ipcApi:autoUpdate'); @@ -24,11 +25,13 @@ export default (params: { mainWindow: BrowserWindow; settings: any }) => { autoUpdater.checkForUpdates(); } else if (args.action === 'install') { debug('installing update'); - app.removeAllListeners('window-all-closed'); - params.mainWindow.removeAllListeners('close'); + + appEvents.emit('install-update'); + + const openedWindows = BrowserWindow.getAllWindows(); + for (const window of openedWindows) window.close(); + autoUpdater.quitAndInstall(); - // TODO: based on https://github.com/electron-userland/electron-builder/issues/6058#issuecomment-1130344017 (not yet tested since we don't have signed builds yet for macos) - app.exit(); } } catch (error) { event.sender.send('autoUpdate', { error }); diff --git a/src/index.ts b/src/index.ts index 59a90a3cb..fad6b9b69 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ import { join } from 'path'; import windowStateKeeper from 'electron-window-state'; import minimist from 'minimist'; import ms from 'ms'; +import { EventEmitter } from 'events'; import { enableWebContents, initializeRemote } from './electron-util'; import { enforceMacOSAppLocation } from './enforce-macos-app-location'; @@ -56,6 +57,9 @@ app.userAgentFallback = userAgent(); // be closed automatically when the JavaScript object is garbage collected. let mainWindow: BrowserWindow | undefined; let willQuitApp = false; +let overrideAppQuitForUpdate = false; + +export const appEvents = new EventEmitter(); // Register methods to be called once the window has been loaded. let onDidLoadFns: any[] | null = []; @@ -320,7 +324,8 @@ const createWindow = () => { debug('Window: hide'); mainWindow?.hide(); } - } else { + } else if (!overrideAppQuitForUpdate) { + debug('Quitting the app'); dbus.stop(); app.quit(); } @@ -653,12 +658,20 @@ app.on('window-all-closed', () => { ) ) { debug('Window: all windows closed, quit app'); - app.quit(); + if (!overrideAppQuitForUpdate) { + // TODO: based on https://github.com/electron-userland/electron-builder/issues/6058#issuecomment-1130344017 (not yet tested since we don't have signed builds yet for macos) + app.quit(); + } } else { debug("Window: don't quit app"); } }); +appEvents.on('install-update', () => { + willQuitApp = true; + overrideAppQuitForUpdate = true; +}); + app.on('before-quit', event => { const yesButtonIndex = 0; let selection = yesButtonIndex; -- cgit v1.2.3-70-g09d2