signal-desktop/ts/updater/index.ts

57 lines
1.4 KiB
TypeScript
Raw Normal View History

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