2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2019-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-08-27 20:21:42 +00:00
|
|
|
import config from 'config';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { BrowserWindow } from 'electron';
|
2019-03-28 17:09:26 +00:00
|
|
|
|
2021-11-10 00:56:56 +00:00
|
|
|
import type { Updater } from './common';
|
|
|
|
import { MacOSUpdater } from './macos';
|
|
|
|
import { WindowsUpdater } from './windows';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LoggerType } from '../types/Logging';
|
2021-11-10 00:56:56 +00:00
|
|
|
import type { SettingsChannel } from '../main/settingsChannel';
|
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
|
|
|
|
2019-03-28 17:09:26 +00:00
|
|
|
export async function start(
|
2021-11-10 00:56:56 +00:00
|
|
|
settingsChannel: SettingsChannel,
|
|
|
|
logger: LoggerType,
|
|
|
|
getMainWindow: () => BrowserWindow | undefined
|
2020-09-16 19:31:05 +00:00
|
|
|
): Promise<void> {
|
2019-03-28 17:09:26 +00:00
|
|
|
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!');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (autoUpdateDisabled()) {
|
|
|
|
logger.info(
|
|
|
|
'updater/start: Updates disabled - not starting new version checks'
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (platform === 'win32') {
|
2021-11-10 00:56:56 +00:00
|
|
|
updater = new WindowsUpdater(logger, settingsChannel, getMainWindow);
|
2019-03-28 17:09:26 +00:00
|
|
|
} else if (platform === 'darwin') {
|
2021-11-10 00:56:56 +00:00
|
|
|
updater = new MacOSUpdater(logger, settingsChannel, getMainWindow);
|
2019-03-28 17:09:26 +00:00
|
|
|
} else {
|
|
|
|
throw new Error('updater/start: Unsupported platform');
|
|
|
|
}
|
2021-11-10 00:56:56 +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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|