mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-07-13 01:18:45 +00:00
Added check for updates on startup
This commit is contained in:
parent
e5232c1358
commit
3a9aedae31
2 changed files with 62 additions and 51 deletions
|
@ -41,18 +41,7 @@ export default class Main {
|
|||
}
|
||||
}
|
||||
|
||||
private static createTray() {
|
||||
const icon = (process.platform === 'win32') ? path.join(__dirname, 'icon.ico') : path.join(__dirname, 'icon.png');
|
||||
const trayicon = nativeImage.createFromPath(icon)
|
||||
const tray = new Tray(trayicon.resize({ width: 16 }));
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'Toggle window',
|
||||
click: () => { Main.toggleMainWindow(); }
|
||||
},
|
||||
{
|
||||
label: 'Check for updates',
|
||||
click: async () => {
|
||||
private static async checkForUpdates(silent: boolean) {
|
||||
if (Updater.updateDownloaded) {
|
||||
Main.mainWindow.webContents.send("download-complete");
|
||||
return;
|
||||
|
@ -65,6 +54,7 @@ export default class Main {
|
|||
Main.mainWindow.webContents.send("update-available");
|
||||
}
|
||||
else {
|
||||
if (!silent) {
|
||||
await dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: 'Already up-to-date',
|
||||
|
@ -73,7 +63,9 @@ export default class Main {
|
|||
defaultId: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (!silent) {
|
||||
await dialog.showMessageBox({
|
||||
type: 'error',
|
||||
title: 'Failed to check for updates',
|
||||
|
@ -81,10 +73,24 @@ export default class Main {
|
|||
buttons: ['OK'],
|
||||
defaultId: 0
|
||||
});
|
||||
}
|
||||
|
||||
Main.logger.error('Failed to check for updates:', err);
|
||||
}
|
||||
}
|
||||
|
||||
private static createTray() {
|
||||
const icon = (process.platform === 'win32') ? path.join(__dirname, 'icon.ico') : path.join(__dirname, 'icon.png');
|
||||
const trayicon = nativeImage.createFromPath(icon)
|
||||
const tray = new Tray(trayicon.resize({ width: 16 }));
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'Toggle window',
|
||||
click: () => { Main.toggleMainWindow(); }
|
||||
},
|
||||
{
|
||||
label: 'Check for updates',
|
||||
click: async () => { await Main.checkForUpdates(false); },
|
||||
},
|
||||
{
|
||||
type: 'separator',
|
||||
|
@ -245,6 +251,10 @@ export default class Main {
|
|||
defaultId: 0
|
||||
});
|
||||
}
|
||||
|
||||
if (Updater.checkForUpdatesOnStart) {
|
||||
Main.checkForUpdates(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue