From 8c071b2f11cd690a31caf5dcc503e640b63f03fe Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 5 Mar 2020 12:49:26 +1100 Subject: [PATCH] Fix auto updating on all platforms. Added instructions for release. --- RELEASING.md | 24 ++++++++++++++++++++++++ package.json | 5 +++-- ts/updater/updater.ts | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 RELEASING.md diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 000000000..e8aed4bc6 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,24 @@ +# Releasing + +Creating a new Session Desktop release is very simple. + +1. Bump up the version in `package.json`. +2. Merge all changes required into the `master` branch. + * This will trigger github actions to start building a draft release +3. After github actions has finished building. Go to Release page in the repository. +4. Click on the draft release and change the tag target to `master`. +5. Add in release notes. +6. Generate gpg signatures. +7. Click publish release. + +## Notes + +Artifacts attached in the release shouldn't be deleted! These include the yml files (latest, latest-mac, latest-linux). These are all necessary to get auto updating to work correctly. + +### Mac + +Mac currently uses 2 formats `dmg` and `zip`. +We need the `zip` format for auto updating to work correctly. +We also need the `dmg` because on MacOS Catalina, there is a system bug where extracting the artifact `zip` using the default _Archive Utility_ will make it so the extracted application is invalid and it will fail to open. A work around for this is to extract the `zip` using an alternate program such as _The Unarchiver_. + +Once this bug is fixed we can go back to using the `zip` format by itself. diff --git a/package.json b/package.json index 2cbbd2f3a..e727cc465 100644 --- a/package.json +++ b/package.json @@ -213,12 +213,12 @@ "appId": "com.loki-project.messenger-desktop", "afterSign": "build/notarize.js", "artifactName": "${name}-${os}-${arch}-${version}.${ext}", - "publish": "github", "mac": { "category": "public.app-category.social-networking", "icon": "build/icons/mac/icon.icns", "target": [ - "dmg" + "dmg", + "zip" ], "bundleVersion": "1", "hardenedRuntime": true, @@ -232,6 +232,7 @@ "win": { "asarUnpack": "node_modules/spellchecker/vendor/hunspell_dictionaries", "publisherName": "Loki Project", + "verifyUpdateCodeSignature": false, "icon": "build/icons/win/icon.ico", "target": [ "nsis" diff --git a/ts/updater/updater.ts b/ts/updater/updater.ts index 408ce2f1a..cd2547d31 100644 --- a/ts/updater/updater.ts +++ b/ts/updater/updater.ts @@ -1,5 +1,7 @@ +import * as path from 'path'; +import * as fs from 'fs-extra'; import { autoUpdater } from 'electron-updater'; -import { BrowserWindow } from 'electron'; +import { app, BrowserWindow } from 'electron'; import { markShouldQuit } from '../../app/window_state'; import { getPrintableError, @@ -44,6 +46,13 @@ async function checkForUpdates( return; } + const canUpdate = await canAutoUpdate(); + if (!canUpdate) { + return; + } + + isUpdating = true; + logger.info('auto-update: checking for update...'); try { @@ -75,3 +84,34 @@ async function checkForUpdates( isUpdating = false; } } + +/* + Check if we have the required files to auto update. + These files won't exist inside certain formats such as a linux deb file. +*/ +async function canAutoUpdate(): Promise { + const isPackaged = app.isPackaged; + + // On a production app, we need to use resources path to check for the file + if (isPackaged && !process.resourcesPath) { + return false; + } + + // Taken from: https://github.com/electron-userland/electron-builder/blob/d4feb6d3c8b008f8b455c761d654c8088f90d8fa/packages/electron-updater/src/ElectronAppAdapter.ts#L25 + const updateFile = isPackaged ? 'app-update.yml' : 'dev-app-update.yml'; + const basePath = + isPackaged && process.resourcesPath + ? process.resourcesPath + : app.getAppPath(); + const appUpdateConfigPath = path.join(basePath, updateFile); + + return new Promise(resolve => { + try { + // tslint:disable-next-line: non-literal-fs-path + const exists = fs.existsSync(appUpdateConfigPath); + resolve(exists); + } catch (e) { + resolve(false); + } + }); +}