1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-07-20 15:07:00 +00:00

Added check for updates on startup

This commit is contained in:
Michael Hollister 2024-11-17 23:36:16 -06:00
parent e5232c1358
commit 3a9aedae31
2 changed files with 62 additions and 51 deletions

View file

@ -61,6 +61,24 @@ export class Updater {
public static updateError: boolean = false;
public static updateDownloaded: boolean = false;
public static updateProgress: number = 0;
public static checkForUpdatesOnStart: boolean = true;
static {
Updater.localPackageJson = JSON.parse(fs.readFileSync(path.join(Updater.appPath, './package.json'), 'utf8'));
let updaterSettings = Store.get('updater');
if (updaterSettings !== null) {
Updater.localPackageJson.channel = updaterSettings.channel === undefined ? 'stable' : updaterSettings.channel;
Updater.checkForUpdatesOnStart = updaterSettings.checkForUpdatesOnStart === undefined ? true : updaterSettings.checkForUpdatesOnStart;
}
updaterSettings = {
'channel': Updater.localPackageJson.channel,
'checkForUpdatesOnStart': Updater.checkForUpdatesOnStart,
}
Store.set('updater', updaterSettings);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private static async fetchJSON(url: string): Promise<any> {
@ -210,11 +228,7 @@ export class Updater {
}
public static getChannelVersion(): string {
if (Updater.localPackageJson === null) {
Updater.localPackageJson = JSON.parse(fs.readFileSync(path.join(Updater.appPath, './package.json'), 'utf8'));
Updater.localPackageJson.channelVersion = Updater.localPackageJson.channelVersion ? Updater.localPackageJson.channelVersion : 0
}
Updater.localPackageJson.channelVersion = Updater.localPackageJson.channelVersion ? Updater.localPackageJson.channelVersion : 0
return Updater.localPackageJson.channelVersion;
}
@ -290,23 +304,10 @@ export class Updater {
public static async checkForUpdates(): Promise<boolean> {
logger.info('Checking for updates...');
Updater.localPackageJson = JSON.parse(fs.readFileSync(path.join(Updater.appPath, './package.json'), 'utf8'));
try {
Updater.releasesJson = await Updater.fetchJSON(`${Updater.baseUrl}/releases_v${Updater.supportedReleasesJsonVersion}.json`.toString()) as ReleaseInfo;
let updaterSettings = Store.get('updater');
if (updaterSettings === null) {
updaterSettings = {
'channel': Updater.localPackageJson.channel,
}
Store.set('updater', updaterSettings);
}
else {
Updater.localPackageJson.channel = updaterSettings.channel;
}
const localChannelVersion: number = Updater.localPackageJson.channelVersion ? Updater.localPackageJson.channelVersion : 0;
const currentChannelVersion: number = Updater.releasesJson.channelCurrentVersions[Updater.localPackageJson.channel] ? Updater.releasesJson.channelCurrentVersions[Updater.localPackageJson.channel] : 0;
logger.info('Update check', { channel: Updater.localPackageJson.channel, channel_version: localChannelVersion, localVersion: Updater.localPackageJson.version,