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';
|
2019-03-28 17:09:26 +00:00
|
|
|
|
2023-12-12 02:15:36 +00:00
|
|
|
import type { Updater, UpdaterOptionsType } from './common';
|
2021-11-10 00:56:56 +00:00
|
|
|
import { MacOSUpdater } from './macos';
|
|
|
|
import { WindowsUpdater } from './windows';
|
2023-01-18 23:31:10 +00:00
|
|
|
import { isLinuxVersionSupported } from './linux';
|
|
|
|
import { DialogType } from '../types/Dialogs';
|
2019-03-28 17:09:26 +00:00
|
|
|
|
|
|
|
let initialized = false;
|
|
|
|
|
2021-11-10 00:56:56 +00:00
|
|
|
let updater: Updater | undefined;
|
2021-06-30 21:27:18 +00:00
|
|
|
|
2023-12-12 02:15:36 +00:00
|
|
|
export async function start(options: UpdaterOptionsType): Promise<void> {
|
2019-03-28 17:09:26 +00:00
|
|
|
const { platform } = process;
|
2023-12-12 02:15:36 +00:00
|
|
|
const { logger, getMainWindow } = options;
|
2019-03-28 17:09:26 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 17:09:26 +00:00
|
|
|
if (autoUpdateDisabled()) {
|
|
|
|
logger.info(
|
|
|
|
'updater/start: Updates disabled - not starting new version checks'
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (platform === 'win32') {
|
2023-12-12 02:15:36 +00:00
|
|
|
updater = new WindowsUpdater(options);
|
2019-03-28 17:09:26 +00:00
|
|
|
} else if (platform === 'darwin') {
|
2023-12-12 02:15:36 +00:00
|
|
|
updater = new MacOSUpdater(options);
|
2019-03-28 17:09:26 +00:00
|
|
|
} else {
|
|
|
|
throw new Error('updater/start: Unsupported platform');
|
|
|
|
}
|
2021-11-10 00:56:56 +00:00
|
|
|
|
2023-01-18 23:31:10 +00:00
|
|
|
await updater?.start();
|
2019-03-28 17:09:26 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-27 00:18:50 +00:00
|
|
|
export function onRestartCancelled(): void {
|
|
|
|
if (updater) {
|
|
|
|
updater.onRestartCancelled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 17:09:26 +00:00
|
|
|
function autoUpdateDisabled() {
|
|
|
|
return (
|
2021-08-27 20:21:42 +00:00
|
|
|
process.platform === 'linux' || process.mas || !config.get('updatesEnabled')
|
2019-03-28 17:09:26 +00:00
|
|
|
);
|
|
|
|
}
|