-
Notifications
You must be signed in to change notification settings - Fork 30
/
UpdateChecker.mjs
35 lines (30 loc) · 946 Bytes
/
UpdateChecker.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPLICER:NO_UPDATE_CHECKER:REMOVE_FILE
import {RequestUtils} from './RequestUtils.mjs';
const PACKAGE_JSON_URL = 'https://raw.githubusercontent.com/Andrews54757/FastStream/main/package.json';
export class UpdateChecker {
static async getLatestVersion() {
const xhr = await RequestUtils.requestSimple(PACKAGE_JSON_URL);
if (xhr.status !== 200) {
return null;
}
const body = xhr.responseText;
const json = JSON.parse(body);
return json.version;
}
static compareVersions(currentVersion, latestVersion) {
const current = currentVersion.split('.');
const latest = latestVersion.split('.');
for (let i = 0; i < latest.length; i++) {
const c = parseInt(current[i]);
const l = parseInt(latest[i]);
if (isNaN(l) || isNaN(c)) {
return false;
} else if (c < l) {
return true;
} else if (c > l) {
return false;
}
}
return false;
}
}