signal-desktop/ts/updater/index.ts

68 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-01-03 11:55:46 -08:00
// Copyright 2019 Signal Messenger, LLC
2020-10-30 15:34:04 -05:00
// SPDX-License-Identifier: AGPL-3.0-only
2021-08-27 13:21:42 -07:00
import config from 'config';
import { app } from 'electron';
import type { Updater, UpdaterOptionsType } from './common';
import { MacOSUpdater } from './macos';
import { WindowsUpdater } from './windows';
import { initLinux } from './linux';
let initialized = false;
let updater: Updater | undefined;
2021-06-30 14:27:18 -07:00
export async function start(options: UpdaterOptionsType): Promise<void> {
const { platform } = process;
const { logger } = options;
if (initialized) {
throw new Error('updater/start: Updates have already been initialized!');
}
initialized = true;
if (!logger) {
throw new Error('updater/start: Must provide logger!');
}
if (autoUpdateDisabled()) {
logger.info(
'updater/start: Updates disabled - not starting new version checks'
);
return;
}
if (platform === 'win32') {
updater = new WindowsUpdater(options);
} else if (platform === 'darwin') {
updater = new MacOSUpdater(options);
} else if (platform === 'linux') {
initLinux(options);
} else {
throw new Error(`updater/start: Unsupported platform ${platform}`);
}
2023-01-18 15:31:10 -08:00
await updater?.start();
}
2021-06-30 14:27:18 -07:00
export async function force(): Promise<void> {
if (!initialized) {
throw new Error("updater/force: Updates haven't been initialized!");
}
if (updater) {
await updater.force();
}
}
export function onRestartCancelled(): void {
if (updater) {
updater.onRestartCancelled();
}
}
function autoUpdateDisabled() {
return !app.isPackaged || process.mas || !config.get('updatesEnabled');
}