mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-27 10:32:58 +02:00
Electron: Fixes #292: Removed buggy electron-updater and implemented custom check
This commit is contained in:
parent
7937fab5ff
commit
0317171097
@ -1,31 +1,15 @@
|
||||
const { dialog } = require('electron')
|
||||
const { autoUpdater } = require('electron-updater')
|
||||
const { Logger } = require('lib/logger.js');
|
||||
const { _ } = require('lib/locale.js');
|
||||
const fetch = require('node-fetch');
|
||||
const packageInfo = require('./packageInfo.js');
|
||||
const compareVersions = require('compare-versions');
|
||||
|
||||
let autoUpdateLogger_ = new Logger();
|
||||
let checkInBackground_ = false;
|
||||
let isCheckingForUpdate_ = false;
|
||||
let parentWindow_ = null;
|
||||
|
||||
// Note: Electron Builder's autoUpdater is incredibly buggy so currently it's only used
|
||||
// to detect if a new version is present. If it is, the download link is simply opened
|
||||
// in a new browser window.
|
||||
autoUpdater.autoDownload = false;
|
||||
|
||||
function htmlToText_(html) {
|
||||
let output = html.replace(/\n/g, '');
|
||||
output = output.replace(/<li>/g, '- ');
|
||||
output = output.replace(/<p>/g, '');
|
||||
output = output.replace(/<\/p>/g, '\n');
|
||||
output = output.replace(/<\/li>/g, '\n');
|
||||
output = output.replace(/<ul>/g, '');
|
||||
output = output.replace(/<\/ul>/g, '');
|
||||
output = output.replace(/<.*?>/g, '');
|
||||
output = output.replace(/<\/.*?>/g, '');
|
||||
return output;
|
||||
}
|
||||
|
||||
function showErrorMessageBox(message) {
|
||||
return dialog.showMessageBox(parentWindow_, {
|
||||
type: 'error',
|
||||
@ -43,81 +27,45 @@ function onCheckEnded() {
|
||||
isCheckingForUpdate_ = false;
|
||||
}
|
||||
|
||||
autoUpdater.on('error', (error) => {
|
||||
autoUpdateLogger_.error(error);
|
||||
if (checkInBackground_) return onCheckEnded();
|
||||
async function fetchLatestRelease() {
|
||||
const response = await fetch('https://api.github.com/repos/laurent22/joplin/releases/latest');
|
||||
|
||||
let msg = error == null ? "unknown" : (error.stack || error).toString();
|
||||
// Error messages can be very long even without stack trace so shorten
|
||||
// then so that the dialog box doesn't take the whole screen.
|
||||
msg = msg.substr(0,512).replace(/\\n/g, '\n');
|
||||
showErrorMessageBox(msg)
|
||||
if (!response.ok) {
|
||||
const responseText = await response.text();
|
||||
throw new Error('Cannot get latest release info: ' + responseText.substr(0,500));
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
onCheckEnded();
|
||||
})
|
||||
const version = json.tag_name.substr(1);
|
||||
let downloadUrl = null;
|
||||
const platform = process.platform;
|
||||
for (let i = 0; i < json.assets.length; i++) {
|
||||
const asset = json.assets[i];
|
||||
let found = false;
|
||||
if (platform === 'win32' && asset.name.indexOf('.exe') >= 0) {
|
||||
found = true;
|
||||
} else if (platform === 'darwin' && asset.name.indexOf('.dmg') >= 0) {
|
||||
found = true;
|
||||
} else if (platform === 'linux' && asset.name.indexOf('.AppImage') >= 0) {
|
||||
found = true;
|
||||
}
|
||||
|
||||
function findDownloadFilename_(info) {
|
||||
// { version: '1.0.64',
|
||||
// files:
|
||||
// [ { url: 'Joplin-1.0.64-mac.zip',
|
||||
// sha512: 'OlemXqhq/fSifx7EutvMzfoCI/1kGNl10i8nkvACEDfVXwP8hankDBXEC0+GxSArsZuxOh3U1+C+4j72SfIUew==' },
|
||||
// { url: 'Joplin-1.0.64.dmg',
|
||||
// sha512: 'jAewQQoJ3nCaOj8hWDgf0sc3LBbAWQtiKqfTflK8Hc3Dh7fAy9jRHfFAZKFUZ9ll95Bun0DVsLq8wLSUrdsMXw==',
|
||||
// size: 77104485 } ],
|
||||
// path: 'Joplin-1.0.64-mac.zip',
|
||||
// sha512: 'OlemXqhq/fSifx7EutvMzfoCI/1kGNl10i8nkvACEDfVXwP8hankDBXEC0+GxSArsZuxOh3U1+C+4j72SfIUew==',
|
||||
// releaseDate: '2018-02-16T00:13:01.634Z',
|
||||
// releaseName: 'v1.0.64',
|
||||
// releaseNotes: '<p>Still more fixes and im...' }
|
||||
|
||||
if (!info) return null;
|
||||
|
||||
if (!info.files) {
|
||||
// info.path seems to contain a default, though not a good one,
|
||||
// so the loop below if preferable to find the right file.
|
||||
return info.path;
|
||||
if (found) {
|
||||
downloadUrl = asset.browser_download_url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < info.files.length; i++) {
|
||||
const f = info.files[i].url; // Annoyingly this is called "url" but it's obviously not a url, so hopefully it won't change later on and become one.
|
||||
if (f.indexOf('.exe') >= 0) return f;
|
||||
if (f.indexOf('.dmg') >= 0) return f;
|
||||
}
|
||||
if (!downloadUrl) throw new Error('Cannot find download Url: ' + JSON.stringify(json).substr(0,500));
|
||||
|
||||
return info.path;
|
||||
return {
|
||||
version: version,
|
||||
downloadUrl: downloadUrl,
|
||||
notes: json.body,
|
||||
};
|
||||
}
|
||||
|
||||
autoUpdater.on('update-available', (info) => {
|
||||
const filename = findDownloadFilename_(info);
|
||||
|
||||
if (!info.version || !filename) {
|
||||
if (checkInBackground_) return onCheckEnded();
|
||||
showErrorMessageBox(('Could not get version info: ' + JSON.stringify(info)));
|
||||
return onCheckEnded();
|
||||
}
|
||||
|
||||
const downloadUrl = 'https://github.com/laurent22/joplin/releases/download/v' + info.version + '/' + filename;
|
||||
|
||||
let releaseNotes = info.releaseNotes + '';
|
||||
if (releaseNotes) releaseNotes = '\n\n' + _('Release notes:\n\n%s', htmlToText_(releaseNotes));
|
||||
|
||||
const buttonIndex = dialog.showMessageBox(parentWindow_, {
|
||||
type: 'info',
|
||||
message: _('An update is available, do you want to download it now?' + releaseNotes),
|
||||
buttons: [_('Yes'), _('No')]
|
||||
});
|
||||
|
||||
onCheckEnded();
|
||||
|
||||
if (buttonIndex === 0) require('electron').shell.openExternal(downloadUrl);
|
||||
})
|
||||
|
||||
autoUpdater.on('update-not-available', () => {
|
||||
if (checkInBackground_) return onCheckEnded();
|
||||
dialog.showMessageBox({ message: _('Current version is up-to-date.') })
|
||||
onCheckEnded();
|
||||
})
|
||||
|
||||
function checkForUpdates(inBackground, window, logFilePath) {
|
||||
if (isCheckingForUpdate_) {
|
||||
autoUpdateLogger_.info('checkForUpdates: Skipping check because it is already running');
|
||||
@ -133,18 +81,30 @@ function checkForUpdates(inBackground, window, logFilePath) {
|
||||
autoUpdateLogger_.addTarget('file', { path: logFilePath });
|
||||
autoUpdateLogger_.setLevel(Logger.LEVEL_DEBUG);
|
||||
autoUpdateLogger_.info('checkForUpdates: Initializing...');
|
||||
autoUpdater.logger = autoUpdateLogger_;
|
||||
}
|
||||
|
||||
checkInBackground_ = inBackground;
|
||||
|
||||
try {
|
||||
autoUpdater.checkForUpdates()
|
||||
} catch (error) {
|
||||
fetchLatestRelease().then(release => {
|
||||
if (compareVersions(release.version, packageInfo.version) <= 0) {
|
||||
if (!checkInBackground_) dialog.showMessageBox({ message: _('Current version is up-to-date.') })
|
||||
} else {
|
||||
const releaseNotes = release.notes.trim() ? "\n\n" + release.notes.trim() : '';
|
||||
|
||||
const buttonIndex = dialog.showMessageBox(parentWindow_, {
|
||||
type: 'info',
|
||||
message: _('An update is available, do you want to download it now?' + releaseNotes),
|
||||
buttons: [_('Yes'), _('No')]
|
||||
});
|
||||
|
||||
if (buttonIndex === 0) require('electron').shell.openExternal(release.downloadUrl);
|
||||
}
|
||||
}).catch(error => {
|
||||
autoUpdateLogger_.error(error);
|
||||
if (!checkInBackground_) showErrorMessageBox(error.message);
|
||||
}).then(() => {
|
||||
onCheckEnded();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.checkForUpdates = checkForUpdates
|
81
ElectronClient/app/package-lock.json
generated
81
ElectronClient/app/package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Joplin",
|
||||
"version": "1.0.72",
|
||||
"version": "1.0.70",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -614,12 +614,14 @@
|
||||
"bluebird": {
|
||||
"version": "3.5.1",
|
||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
|
||||
"integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA=="
|
||||
"integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==",
|
||||
"dev": true
|
||||
},
|
||||
"bluebird-lst": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/bluebird-lst/-/bluebird-lst-1.0.5.tgz",
|
||||
"integrity": "sha512-Ey0bDNys5qpYPhZ/oQ9vOEvD0TYQDTILMXWP2iGfvMg7rSDde+oV4aQQgqRH+CvBFNz2BSDQnPGMUl6LKBUUQA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"bluebird": "3.5.1"
|
||||
}
|
||||
@ -848,6 +850,7 @@
|
||||
"version": "4.0.5",
|
||||
"resolved": "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-4.0.5.tgz",
|
||||
"integrity": "sha512-NT8AxWH6miZQHnZzaTVjVp1uc6C/mWlxi6GQXKpd4CwyTQd3rT7+poOGrcOhtIiHYCL9VEbRsVfxUAPPsgqJdg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"bluebird-lst": "1.0.5",
|
||||
"debug": "3.1.0",
|
||||
@ -859,6 +862,7 @@
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
@ -867,6 +871,7 @@
|
||||
"version": "4.5.2",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra-p/-/fs-extra-p-4.5.2.tgz",
|
||||
"integrity": "sha512-ZYqFpBdy9w7PsK+vB30j+TnHOyWHm/CJbUq1qqoE8tb71m6qgk5Wa7gp3MYQdlGFxb9vfznF+yD4jcl8l+y91A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"bluebird-lst": "1.0.5",
|
||||
"fs-extra": "5.0.0"
|
||||
@ -1084,6 +1089,11 @@
|
||||
"integrity": "sha1-AWLsLZNR9d3VmpICy6k1NmpyUIA=",
|
||||
"dev": true
|
||||
},
|
||||
"compare-versions": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-3.1.0.tgz",
|
||||
"integrity": "sha512-4hAxDSBypT/yp2ySFD346So6Ragw5xmBn/e/agIGl3bZr6DLUqnoRZPusxKrXdYRZpgexO9daejmIenlq/wrIQ=="
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
@ -1642,11 +1652,6 @@
|
||||
"resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-0.1.2.tgz",
|
||||
"integrity": "sha1-ihBD4ys6HaHD9VPc4oznZCRhZ+M="
|
||||
},
|
||||
"electron-log": {
|
||||
"version": "2.2.11",
|
||||
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-2.2.11.tgz",
|
||||
"integrity": "sha512-e+DHJkLJoaawDxyy9i2SMIViG/GV12DUE3T9a6yMdFp695c2u/kWYUZbUy31RzgX9uC/JuewXrO54tXdANgRRQ=="
|
||||
},
|
||||
"electron-osx-sign": {
|
||||
"version": "0.4.8",
|
||||
"resolved": "https://registry.npmjs.org/electron-osx-sign/-/electron-osx-sign-0.4.8.tgz",
|
||||
@ -1737,47 +1742,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"electron-updater": {
|
||||
"version": "2.20.1",
|
||||
"resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-2.20.1.tgz",
|
||||
"integrity": "sha512-7LJBcHY0T8So5Q/NZqYlU43DPXfyVssGq9ObamXbSL01mRt/gdpcJlXPU1w3vA/L6tC1IMVI9cAulAjI2oSYAw==",
|
||||
"requires": {
|
||||
"bluebird-lst": "1.0.5",
|
||||
"builder-util-runtime": "4.0.5",
|
||||
"electron-is-dev": "0.3.0",
|
||||
"fs-extra-p": "4.5.2",
|
||||
"js-yaml": "3.10.0",
|
||||
"lazy-val": "1.0.3",
|
||||
"lodash.isequal": "4.5.0",
|
||||
"semver": "5.5.0",
|
||||
"source-map-support": "0.5.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"electron-is-dev": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-0.3.0.tgz",
|
||||
"integrity": "sha1-FOb9pcaOnk7L7/nM8DfL18BcWv4="
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
|
||||
"integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA=="
|
||||
},
|
||||
"source-map": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
|
||||
},
|
||||
"source-map-support": {
|
||||
"version": "0.5.3",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.3.tgz",
|
||||
"integrity": "sha512-eKkTgWYeBOQqFGXRfKabMFdnWepo51vWqEdoeikaEPFiJC7MCU5j2h4+6Q8npkZTeLGbSyecZvRxiSoWl3rh+w==",
|
||||
"requires": {
|
||||
"source-map": "0.6.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"electron-window-state": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/electron-window-state/-/electron-window-state-4.1.1.tgz",
|
||||
@ -1848,7 +1812,8 @@
|
||||
"esprima": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz",
|
||||
"integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw=="
|
||||
"integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==",
|
||||
"dev": true
|
||||
},
|
||||
"esutils": {
|
||||
"version": "2.0.2",
|
||||
@ -2091,15 +2056,6 @@
|
||||
"universalify": "0.1.1"
|
||||
}
|
||||
},
|
||||
"fs-extra-p": {
|
||||
"version": "4.5.2",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra-p/-/fs-extra-p-4.5.2.tgz",
|
||||
"integrity": "sha512-ZYqFpBdy9w7PsK+vB30j+TnHOyWHm/CJbUq1qqoE8tb71m6qgk5Wa7gp3MYQdlGFxb9vfznF+yD4jcl8l+y91A==",
|
||||
"requires": {
|
||||
"bluebird-lst": "1.0.5",
|
||||
"fs-extra": "5.0.0"
|
||||
}
|
||||
},
|
||||
"fs-minipass": {
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.5.tgz",
|
||||
@ -2559,8 +2515,7 @@
|
||||
"jsbn": {
|
||||
"version": "0.1.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"json-schema": {
|
||||
"version": "0.2.3",
|
||||
@ -3593,6 +3548,7 @@
|
||||
"version": "3.10.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz",
|
||||
"integrity": "sha512-O2v52ffjLa9VeM43J4XocZE//WT9N0IiwDa3KSHH7Tu8CtH+1qM8SIZvnsTh6v+4yFy5KUY3BHUVwjpfAWsjIA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"argparse": "1.0.9",
|
||||
"esprima": "4.0.0"
|
||||
@ -3695,11 +3651,6 @@
|
||||
"package-json": "4.0.1"
|
||||
}
|
||||
},
|
||||
"lazy-val": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.3.tgz",
|
||||
"integrity": "sha512-pjCf3BYk+uv3ZcPzEVM0BFvO9Uw58TmlrU0oG5tTrr9Kcid3+kdKxapH8CjdYmVa2nO5wOoZn2rdvZx2PKj/xg=="
|
||||
},
|
||||
"lcid": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz",
|
||||
|
@ -59,9 +59,8 @@
|
||||
"app-module-path": "^2.2.0",
|
||||
"async-mutex": "^0.1.3",
|
||||
"base-64": "^0.1.0",
|
||||
"compare-versions": "^3.1.0",
|
||||
"electron-context-menu": "^0.9.1",
|
||||
"electron-log": "^2.2.11",
|
||||
"electron-updater": "^2.18.2",
|
||||
"electron-window-state": "^4.1.1",
|
||||
"follow-redirects": "^1.2.5",
|
||||
"form-data": "^2.3.1",
|
||||
|
Loading…
Reference in New Issue
Block a user