2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2019-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-03-28 17:09:26 +00:00
|
|
|
import { get as getFromConfig } from 'config';
|
|
|
|
import { BrowserWindow } from 'electron';
|
|
|
|
|
|
|
|
import { start as startMacOS } from './macos';
|
|
|
|
import { start as startWindows } from './windows';
|
2020-04-01 18:59:11 +00:00
|
|
|
import { LocaleType } from '../types/I18N';
|
|
|
|
import { LoggerType } from '../types/Logging';
|
2019-03-28 17:09:26 +00:00
|
|
|
|
|
|
|
let initialized = false;
|
|
|
|
|
|
|
|
export async function start(
|
|
|
|
getMainWindow: () => BrowserWindow,
|
2020-02-13 18:14:08 +00:00
|
|
|
locale?: LocaleType,
|
2019-03-28 17:09:26 +00:00
|
|
|
logger?: LoggerType
|
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;
|
|
|
|
|
2020-02-13 18:14:08 +00:00
|
|
|
if (!locale) {
|
|
|
|
throw new Error('updater/start: Must provide locale!');
|
2019-03-28 17:09:26 +00:00
|
|
|
}
|
|
|
|
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') {
|
2020-02-13 18:14:08 +00:00
|
|
|
await startWindows(getMainWindow, locale, logger);
|
2019-03-28 17:09:26 +00:00
|
|
|
} else if (platform === 'darwin') {
|
2020-02-13 18:14:08 +00:00
|
|
|
await startMacOS(getMainWindow, locale, logger);
|
2019-03-28 17:09:26 +00:00
|
|
|
} else {
|
|
|
|
throw new Error('updater/start: Unsupported platform');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function autoUpdateDisabled() {
|
|
|
|
return (
|
|
|
|
process.platform === 'linux' ||
|
|
|
|
process.mas ||
|
|
|
|
!getFromConfig('updatesEnabled')
|
|
|
|
);
|
|
|
|
}
|