Fix auto updating on all platforms.

Added instructions for release.
This commit is contained in:
Mikunj 2020-03-05 12:49:26 +11:00
parent 178d788dca
commit 8c071b2f11
3 changed files with 68 additions and 3 deletions

24
RELEASING.md Normal file
View file

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

View file

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

View file

@ -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<boolean> {
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);
}
});
}