[Updater > Module] Minor source cleanup

This commit is contained in:
Ducko 2022-04-28 22:58:28 +01:00
parent 95fb31ffd6
commit 64a1b325fb
1 changed files with 10 additions and 10 deletions

View File

@ -16,7 +16,7 @@ let skipHost, skipModule,
installed = {}, installed = {},
downloading, installing, downloading, installing,
basePath, manifestPath, downloadPath, basePath, manifestPath, downloadPath,
hostUpdater, host,
baseUrl, qs, baseUrl, qs,
last; last;
@ -56,7 +56,7 @@ exports.init = (endpoint, { releaseChannel, version }) => {
} }
hostUpdater = process.platform === 'linux' ? new (class HostLinux extends require('events').EventEmitter { host = process.platform === 'linux' ? new (class HostLinux extends require('events').EventEmitter {
setFeedURL(url) { setFeedURL(url) {
this.url = url; this.url = url;
} }
@ -78,20 +78,20 @@ exports.init = (endpoint, { releaseChannel, version }) => {
})() : autoUpdater; })() : autoUpdater;
hostUpdater.on('update-progress', progress => events.emit('downloading-module', { name: 'host', progress })); host.on('update-progress', progress => events.emit('downloading-module', { name: 'host', progress }));
hostUpdater.on('update-manually', e => events.emit('manual', e)); host.on('update-manually', e => events.emit('manual', e));
hostUpdater.on('update-downloaded', hostUpdater.quitAndInstall); host.on('update-downloaded', host.quitAndInstall);
hostUpdater.on('error', () => { host.on('error', () => {
log('Modules', 'Host error'); log('Modules', 'Host error');
events.emit('checked', { failed: true }); events.emit('checked', { failed: true });
}); });
const platform = process.platform === 'darwin' ? 'osx' : 'linux'; const platform = process.platform === 'darwin' ? 'osx' : 'linux';
hostUpdater.setFeedURL(`${endpoint}/updates/${releaseChannel}?platform=${platform}&version=${version}`); host.setFeedURL(`${endpoint}/updates/${releaseChannel}?platform=${platform}&version=${version}`);
baseUrl = `${endpoint}/modules/${releaseChannel}`; baseUrl = `${endpoint}/modules/${releaseChannel}`;
qs = { qs = {
@ -250,8 +250,8 @@ exports.checkForUpdates = async () => {
let p = []; let p = [];
if (!skipHost) { if (!skipHost) {
p.push(new Promise((res) => hostUpdater.once('update-not-available', res))); p.push(new Promise((res) => host.once('update-not-available', res)));
hostUpdater.checkForUpdates(); host.checkForUpdates();
} }
if (!skipModule) p.push(checkModules()); if (!skipModule) p.push(checkModules());
@ -261,7 +261,7 @@ exports.checkForUpdates = async () => {
}); });
}; };
exports.quitAndInstallUpdates = () => hostUpdater.quitAndInstall(); exports.quitAndInstallUpdates = () => host.quitAndInstall();
exports.isInstalled = (n, v) => installed[n] && !(v && installed[n].installedVersion !== v); exports.isInstalled = (n, v) => installed[n] && !(v && installed[n].installedVersion !== v);
exports.getInstalled = () => ({ ...installed }); exports.getInstalled = () => ({ ...installed });