Send updates to client
This commit is contained in:
parent
377c4fd104
commit
dc7247a12d
|
@ -28,6 +28,14 @@ export default new class extends Module {
|
||||||
ipc.on('updater-checkForUpdates', () => {
|
ipc.on('updater-checkForUpdates', () => {
|
||||||
Events.emit('update-check-start');
|
Events.emit('update-check-start');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipc.on('updater-noUpdates', () => {
|
||||||
|
Events.emit('update-check-end');
|
||||||
|
});
|
||||||
|
|
||||||
|
ipc.on('updater-updatesAvailable', (_, updates) => {
|
||||||
|
console.log('UPDATES', updates);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,32 +35,23 @@ class ReleaseInfo {
|
||||||
|
|
||||||
get core() {
|
get core() {
|
||||||
const f = this.files.find(f => f.id === 'core');
|
const f = this.files.find(f => f.id === 'core');
|
||||||
return {
|
f.upToDate = semver.satisfies(this.versions.core, `>=${f.version}`, { includePrerelease: true });
|
||||||
id: 'core',
|
f.currentVersion = this.versions.core;
|
||||||
currentVersion: this.versions.core,
|
return f;
|
||||||
version: f.version,
|
|
||||||
upToDate: semver.satisfies(this.versions.core, `>=${f.version}`, { includePrerelease: true })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get client() {
|
get client() {
|
||||||
const f = this.files.find(f => f.id === 'client');
|
const f = this.files.find(f => f.id === 'client');
|
||||||
return {
|
f.upToDate = semver.satisfies(this.versions.client, `>=${f.version}`, { includePrerelease: true });
|
||||||
id: 'client',
|
f.currentVersion = this.versions.client;
|
||||||
currentVersion: this.versions.core,
|
return f;
|
||||||
version: f.version,
|
|
||||||
upToDate: semver.satisfies(this.versions.client, `>=${f.version}`, { includePrerelease: true })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get editor() {
|
get editor() {
|
||||||
const f = this.files.find(f => f.id === 'editor');
|
const f = this.files.find(f => f.id === 'editor');
|
||||||
return {
|
f.upToDate = semver.satisfies(this.versions.editor, `>=${f.version}`, { includePrerelease: true });
|
||||||
id: 'editor',
|
f.currentVersion = this.versions.editor;
|
||||||
currentVersion: this.versions.editor,
|
return f;
|
||||||
version: f.version,
|
|
||||||
upToDate: semver.satisfies(this.versions.editor, `>=${f.version}`, { includePrerelease: true })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test() {
|
test() {
|
||||||
|
@ -78,6 +69,7 @@ export default class Updater extends Module {
|
||||||
|
|
||||||
bindings() {
|
bindings() {
|
||||||
this.checkForUpdates = this.checkForUpdates.bind(this);
|
this.checkForUpdates = this.checkForUpdates.bind(this);
|
||||||
|
this.checkForBdUpdates = this.checkForBdUpdates.bind(this);
|
||||||
this.start = this.start.bind(this);
|
this.start = this.start.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,27 +103,49 @@ export default class Updater extends Module {
|
||||||
console.log('fallback');
|
console.log('fallback');
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkForUpdates() {
|
async checkForBdUpdates() {
|
||||||
console.log('[BetterDiscord:Updater] Checking for updates');
|
|
||||||
this.bd.sendToDiscord('updater-checkForUpdates', '');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { coreVersion, clientVersion, editorVersion } = this.bd.config;
|
const { coreVersion, clientVersion, editorVersion } = this.bd.config;
|
||||||
const releaseInfo = new ReleaseInfo({ core: coreVersion, client: clientVersion, editor: editorVersion });
|
const releaseInfo = new ReleaseInfo({ core: coreVersion, client: clientVersion, editor: editorVersion });
|
||||||
|
|
||||||
const latestRelease = await this.latestRelease();
|
const latestRelease = await this.latestRelease();
|
||||||
console.log(latestRelease);
|
|
||||||
|
|
||||||
releaseInfo.files = latestRelease.files;
|
releaseInfo.files = latestRelease.files;
|
||||||
|
|
||||||
if (!releaseInfo.core.upToDate || !releaseInfo.client.upToDate || !ReleaseInfo.editor.upToDate) {
|
const updates = [];
|
||||||
this.bd.sendToDiscord('updater-updatesAvailable', releaseInfo);
|
|
||||||
|
const { core, client, editor } = releaseInfo;
|
||||||
|
if (!core.upToDate) updates.push(core);
|
||||||
|
if (!client.upToDate) updates.push(client);
|
||||||
|
if (!editor.upToDate) updates.push(editor);
|
||||||
|
|
||||||
|
return updates;
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.log('[BetterDiscord:Updater]', err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkForUpdates() {
|
||||||
|
console.log('[BetterDiscord:Updater] Checking for updates');
|
||||||
|
this.bd.sendToDiscord('updater-checkForUpdates', '');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const bd = await this.checkForBdUpdates();
|
||||||
|
const updates = { bd, haveUpdates: false };
|
||||||
|
|
||||||
|
if (bd.length) updates.haveUpdates = true;
|
||||||
|
|
||||||
|
if (!updates.haveUpdates) {
|
||||||
|
this.bd.sendToDiscord('updater-noUpdates', '');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.bd.sendToDiscord('updater-noUpdates', '');
|
this.bd.sendToDiscord('updater-updatesAvailable', updates);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('[BetterDiscord:Updater]', err);
|
console.log('[BetterDiscord:Updater]', err);
|
||||||
this.bd.sendToDiscord('updater-error', err);
|
this.bd.sendToDiscord('updater-error', err);
|
||||||
|
|
Loading…
Reference in New Issue