signal-desktop/ts/updater/index.ts

78 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2019 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2021-08-27 20:21:42 +00:00
import config from 'config';
import type { BrowserWindow } from 'electron';
import type { Updater } from './common';
import { MacOSUpdater } from './macos';
import { WindowsUpdater } from './windows';
2023-01-18 23:31:10 +00:00
import { isLinuxVersionSupported } from './linux';
import type { LoggerType } from '../types/Logging';
2023-01-18 23:31:10 +00:00
import { DialogType } from '../types/Dialogs';
import type { SettingsChannel } from '../main/settingsChannel';
let initialized = false;
let updater: Updater | undefined;
2021-06-30 21:27:18 +00:00
export async function start(
settingsChannel: SettingsChannel,
logger: LoggerType,
getMainWindow: () => BrowserWindow | undefined
2020-09-16 19:31:05 +00:00
): Promise<void> {
const { platform } = process;
if (initialized) {
throw new Error('updater/start: Updates have already been initialized!');
}
initialized = true;
if (!logger) {
throw new Error('updater/start: Must provide logger!');
}
2023-01-18 23:31:10 +00:00
if (platform === 'linux') {
if (!isLinuxVersionSupported(logger)) {
getMainWindow()?.webContents.send(
'show-update-dialog',
DialogType.UnsupportedOS
);
}
}
if (autoUpdateDisabled()) {
logger.info(
'updater/start: Updates disabled - not starting new version checks'
);
return;
}
if (platform === 'win32') {
updater = new WindowsUpdater(logger, settingsChannel, getMainWindow);
} else if (platform === 'darwin') {
updater = new MacOSUpdater(logger, settingsChannel, getMainWindow);
} else {
throw new Error('updater/start: Unsupported platform');
}
2023-01-18 23:31:10 +00:00
await updater?.start();
}
2021-06-30 21:27:18 +00:00
export async function force(): Promise<void> {
if (!initialized) {
throw new Error("updater/force: Updates haven't been initialized!");
}
if (updater) {
await updater.force();
}
}
function autoUpdateDisabled() {
return (
2021-08-27 20:21:42 +00:00
process.platform === 'linux' || process.mas || !config.get('updatesEnabled')
);
}