mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-25 08:35:16 +08:00
Enable very minimal update checking on Linux
This commit is contained in:
parent
efcf5162d0
commit
7319404ef4
2 changed files with 53 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
import {EventEmitter} from 'events';
|
||||
// import request from 'request';
|
||||
import _ from 'underscore';
|
||||
import https from 'https';
|
||||
import shell from 'electron';
|
||||
import url from 'url';
|
||||
|
||||
/*
|
||||
Currently, this class doesn't do much. We don't display update notices within
|
||||
|
@ -8,26 +9,61 @@ the app because we can't provide a consistent upgrade path for linux users.
|
|||
However, we still want the app to report to our autoupdate service so we know
|
||||
how many Linux users exist.
|
||||
*/
|
||||
class LinuxUpdaterAdapter {
|
||||
|
||||
class LinuxUpdaterAdapter extends EventEmitter {
|
||||
setFeedURL(feedURL) {
|
||||
this.feedURL = feedURL;
|
||||
this.downloadURL = null;
|
||||
}
|
||||
|
||||
onError = (err) => {
|
||||
this.emit('error', err.toString());
|
||||
}
|
||||
|
||||
checkForUpdates() {
|
||||
if (!this.feedURL) {
|
||||
return;
|
||||
}
|
||||
// TODO BG I removed request!
|
||||
request(this.feedURL, () => {
|
||||
|
||||
this.emit('checking-for-update');
|
||||
|
||||
const feedHost = url.parse(this.feedURL).hostname;
|
||||
const feedPath = this.feedURL.split(feedHost).pop();
|
||||
|
||||
// Hit the feed URL ourselves and see if an update is available.
|
||||
// On linux we can't autoupdate, but we can still show the "update available" bar.
|
||||
https.get({ host: feedHost, path: feedPath }, (res) => {
|
||||
console.log(`Manual update check returned ${res.statusCode}`);
|
||||
|
||||
if (res.statusCode === 204) {
|
||||
this.emit('update-not-available');
|
||||
return;
|
||||
}
|
||||
|
||||
let data = '';
|
||||
res.on('error', this.onError);
|
||||
res.on('data', (chunk) => { data += chunk; });
|
||||
res.on('end', () => {
|
||||
try {
|
||||
const json = JSON.parse(data);
|
||||
console.log(JSON.stringify(json, null, 2));
|
||||
if (!json.url) {
|
||||
this.onError(new Error(`Autoupdater response did not include URL: ${data}`));
|
||||
return;
|
||||
}
|
||||
this.downloadURL = url;
|
||||
this.emit('update-downloaded', 'Click to download.', null);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
quitAndInstall() {
|
||||
|
||||
if (this.downloadURL) {
|
||||
shell.openExternal(this.downloadURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(LinuxUpdaterAdapter.prototype, EventEmitter.prototype);
|
||||
const adapter = new LinuxUpdaterAdapter();
|
||||
export default adapter
|
||||
export default new LinuxUpdaterAdapter()
|
||||
|
|
|
@ -13,7 +13,7 @@ import path from 'path';
|
|||
// * <config-dir>/packages
|
||||
// * RESOURCE_PATH/node_modules
|
||||
//
|
||||
export default class NylasProtocolHandler {
|
||||
export default class MailspringProtocolHandler {
|
||||
constructor({configDirPath, resourcePath, safeMode}) {
|
||||
this.loadPaths = [];
|
||||
|
||||
|
@ -23,13 +23,14 @@ export default class NylasProtocolHandler {
|
|||
this.loadPaths.push(path.join(configDirPath, 'packages'));
|
||||
this.loadPaths.push(path.join(resourcePath, 'internal_packages'));
|
||||
|
||||
this.registerNylasProtocol();
|
||||
this.registerProtocol();
|
||||
}
|
||||
|
||||
// Creates the 'Nylas' custom protocol handler.
|
||||
registerNylasProtocol() {
|
||||
protocol.registerFileProtocol('mailspring', (request, callback) => {
|
||||
const relativePath = path.normalize(request.url.substr(7));
|
||||
// Creates the 'Mailspring' custom protocol handler.
|
||||
registerProtocol() {
|
||||
const scheme = 'mailspring'
|
||||
protocol.registerFileProtocol(scheme, (request, callback) => {
|
||||
const relativePath = path.normalize(request.url.substr(scheme.length + 1));
|
||||
|
||||
let filePath = null;
|
||||
for (const loadPath of this.loadPaths) {
|
Loading…
Reference in a new issue