Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ts/mains/main_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const appInstance = config.util.getEnv('NODE_APP_INSTANCE') || 0;
import { initAttachmentsChannel } from '../node/attachment_channel';

import * as updater from '../updater/index';
import { autoUpdateDisabled } from '../updater/auto_update_disabled';

import { ephemeralConfig } from '../node/config/ephemeral_config';
import { createTemplate } from '../node/menu';
Expand Down Expand Up @@ -554,6 +555,11 @@ async function readyForUpdates() {
return;
}

if (autoUpdateDisabled(userConfig.get('autoUpdate'))) {
console.log('[updater] updates disabled');
return;
}

isReadyForUpdates = true;

// Second, start checking for app updates
Expand Down
28 changes: 28 additions & 0 deletions ts/test/session/unit/updater/updater_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { expect } from 'chai';
import { enableLogRedirect } from '../../../test-utils/utils';
import { DURATION } from '../../../../session/constants';
import { fetchLatestRelease } from '../../../../session/fetch_latest_release';
import {
autoUpdateDisabled,
DISABLE_UPDATE_PROMPT_ARG,
} from '../../../../updater/auto_update_disabled';

describe('Updater', () => {
it('package.json target is correct', () => {
Expand All @@ -31,4 +35,28 @@ describe('Updater', () => {
it('checks the file server on the same cadence as the update throttle', () => {
expect(fetchLatestRelease.fetchReleaseFromFileServerInterval).to.equal(30 * DURATION.MINUTES);
});

describe('autoUpdateDisabled', () => {
it('defaults to enabled when the user setting is absent', () => {
expect(autoUpdateDisabled(undefined, [], false)).to.be.false;
});

it('respects the user setting', () => {
expect(autoUpdateDisabled(false, [], false)).to.be.true;
expect(autoUpdateDisabled(true, [], false)).to.be.false;
});

it('disables updates for Mac App Store builds', () => {
expect(autoUpdateDisabled(true, [], true)).to.be.true;
});

it(`disables updates when ${DISABLE_UPDATE_PROMPT_ARG} is present`, () => {
expect(autoUpdateDisabled(true, ['session-desktop', DISABLE_UPDATE_PROMPT_ARG], false)).to.be
.true;
});

it('ignores unrelated launch arguments', () => {
expect(autoUpdateDisabled(true, ['session-desktop', '--start-in-tray'], false)).to.be.false;
});
});
});
11 changes: 11 additions & 0 deletions ts/updater/auto_update_disabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const DISABLE_UPDATE_PROMPT_ARG = '--disable-update-prompt';

export function autoUpdateDisabled(
userSetting: unknown,
argv: ReadonlyArray<string> = process.argv,
isMacAppStore = process.mas
): boolean {
const autoUpdate = typeof userSetting !== 'boolean' || userSetting;

return isMacAppStore || argv.includes(DISABLE_UPDATE_PROMPT_ARG) || !autoUpdate;
}
15 changes: 2 additions & 13 deletions ts/updater/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { BrowserWindow } from 'electron';
import { start as startUpdater, stop as stopUpdater } from './updater';
import type { UserConfig } from '../node/config/user_config';
import type { LoggerType } from '../util/logger/Logging';
import { autoUpdateDisabled } from './auto_update_disabled';

let initialized = false;
let localUserConfig: UserConfig;

export async function start(
getMainWindow: () => BrowserWindow | null,
Expand All @@ -23,9 +23,8 @@ export async function start(
throw new Error('[updater] start: Must provide logger!');
}
initialized = true;
localUserConfig = userConfig; // reused below

if (autoUpdateDisabled()) {
if (autoUpdateDisabled(userConfig.get('autoUpdate'))) {
logger.info('[updater] start: Updates disabled - not starting new version checks');

return;
Expand All @@ -40,13 +39,3 @@ export function stop() {
initialized = false;
}
}

function autoUpdateDisabled() {
// We need to ensure that if auto update is not present in the user config then we assume it is on by default
const userSetting = localUserConfig.get('autoUpdate');
const autoUpdate = typeof userSetting !== 'boolean' || userSetting;

return (
process.mas || !autoUpdate // From Electron: Mac App Store build // User setting
);
}
Loading