diff --git a/app/SystemTraySettingCache.ts b/app/SystemTraySettingCache.ts index 272e79d57b..7fb2314c0c 100644 --- a/app/SystemTraySettingCache.ts +++ b/app/SystemTraySettingCache.ts @@ -20,7 +20,8 @@ export class SystemTraySettingCache { constructor( private readonly sql: Pick, - private readonly argv: Array + private readonly argv: Array, + private readonly appVersion: string ) {} async get(): Promise { @@ -51,7 +52,7 @@ export class SystemTraySettingCache { log.info( `getSystemTraySetting saw --use-tray-icon flag. Returning ${result}` ); - } else if (isSystemTraySupported()) { + } else if (isSystemTraySupported(this.appVersion)) { const { value } = (await this.sql.sqlCall('getItemById', [ 'system-tray-setting', ])) || { value: undefined }; diff --git a/js/views/settings_view.js b/js/views/settings_view.js index 9a8b4dc87f..65e583fbc7 100644 --- a/js/views/settings_view.js +++ b/js/views/settings_view.js @@ -280,7 +280,9 @@ props: { i18n, initialValue: window.initialData.systemTray, - isSystemTraySupported: Settings.isSystemTraySupported(), + isSystemTraySupported: Settings.isSystemTraySupported( + window.getVersion() + ), onChange: window.setSystemTraySetting, }, }); diff --git a/main.js b/main.js index 0dd710e65f..de4184a7de 100644 --- a/main.js +++ b/main.js @@ -128,7 +128,11 @@ const { maybeParseUrl, setUrlSearchParams } = require('./ts/util/url'); const sql = new MainSQL(); let systemTrayService; -const systemTraySettingCache = new SystemTraySettingCache(sql, process.argv); +const systemTraySettingCache = new SystemTraySettingCache( + sql, + process.argv, + app.getVersion() +); const challengeHandler = new ChallengeMainHandler(); diff --git a/ts/test-node/app/SystemTraySettingCache_test.ts b/ts/test-node/app/SystemTraySettingCache_test.ts index 5d28d9e264..8d16c6d245 100644 --- a/ts/test-node/app/SystemTraySettingCache_test.ts +++ b/ts/test-node/app/SystemTraySettingCache_test.ts @@ -26,16 +26,21 @@ describe('SystemTraySettingCache', () => { }); it('returns MinimizeToAndStartInSystemTray if passed the --start-in-tray argument', async () => { - const justOneArg = new SystemTraySettingCache(sql, ['--start-in-tray']); + const justOneArg = new SystemTraySettingCache( + sql, + ['--start-in-tray'], + '1.2.3' + ); assert.strictEqual( await justOneArg.get(), SystemTraySetting.MinimizeToAndStartInSystemTray ); - const bothArgs = new SystemTraySettingCache(sql, [ - '--start-in-tray', - '--use-tray-icon', - ]); + const bothArgs = new SystemTraySettingCache( + sql, + ['--start-in-tray', '--use-tray-icon'], + '1.2.3' + ); assert.strictEqual( await bothArgs.get(), SystemTraySetting.MinimizeToAndStartInSystemTray @@ -45,7 +50,7 @@ describe('SystemTraySettingCache', () => { }); it('returns MinimizeToSystemTray if passed the --use-tray-icon argument', async () => { - const cache = new SystemTraySettingCache(sql, ['--use-tray-icon']); + const cache = new SystemTraySettingCache(sql, ['--use-tray-icon'], '1.2.3'); assert.strictEqual( await cache.get(), SystemTraySetting.MinimizeToSystemTray @@ -57,7 +62,7 @@ describe('SystemTraySettingCache', () => { it('returns DoNotUseSystemTray if system tray is supported but no preference is stored', async () => { sandbox.stub(process, 'platform').value('win32'); - const cache = new SystemTraySettingCache(sql, []); + const cache = new SystemTraySettingCache(sql, [], '1.2.3'); assert.strictEqual(await cache.get(), SystemTraySetting.DoNotUseSystemTray); }); @@ -66,7 +71,7 @@ describe('SystemTraySettingCache', () => { sqlCallStub.resolves({ value: 'garbage' }); - const cache = new SystemTraySettingCache(sql, []); + const cache = new SystemTraySettingCache(sql, [], '1.2.3'); assert.strictEqual(await cache.get(), SystemTraySetting.DoNotUseSystemTray); }); @@ -75,7 +80,7 @@ describe('SystemTraySettingCache', () => { sqlCallStub.resolves({ value: 'MinimizeToSystemTray' }); - const cache = new SystemTraySettingCache(sql, []); + const cache = new SystemTraySettingCache(sql, [], '1.2.3'); assert.strictEqual( await cache.get(), SystemTraySetting.MinimizeToSystemTray @@ -85,7 +90,7 @@ describe('SystemTraySettingCache', () => { it('only kicks off one request to the database if multiple sources ask at once', async () => { sandbox.stub(process, 'platform').value('win32'); - const cache = new SystemTraySettingCache(sql, []); + const cache = new SystemTraySettingCache(sql, [], '1.2.3'); await Promise.all([cache.get(), cache.get(), cache.get()]); @@ -95,7 +100,7 @@ describe('SystemTraySettingCache', () => { it('returns DoNotUseSystemTray if system tray is unsupported and there are no CLI flags', async () => { sandbox.stub(process, 'platform').value('darwin'); - const cache = new SystemTraySettingCache(sql, []); + const cache = new SystemTraySettingCache(sql, [], '1.2.3'); assert.strictEqual(await cache.get(), SystemTraySetting.DoNotUseSystemTray); sinon.assert.notCalled(sqlCallStub); diff --git a/ts/test-node/types/Settings_test.ts b/ts/test-node/types/Settings_test.ts index d1e6cfc3be..050d4b3e04 100644 --- a/ts/test-node/types/Settings_test.ts +++ b/ts/test-node/types/Settings_test.ts @@ -171,18 +171,23 @@ describe('Settings', () => { describe('isSystemTraySupported', () => { it('returns false on macOS', () => { sandbox.stub(process, 'platform').value('darwin'); - assert.isFalse(Settings.isSystemTraySupported()); + assert.isFalse(Settings.isSystemTraySupported('1.2.3')); }); it('returns true on Windows 8', () => { sandbox.stub(process, 'platform').value('win32'); sandbox.stub(os, 'release').returns('8.0.0'); - assert.isTrue(Settings.isSystemTraySupported()); + assert.isTrue(Settings.isSystemTraySupported('1.2.3')); }); - it('returns false on Linux', () => { + it('returns false on Linux production', () => { sandbox.stub(process, 'platform').value('linux'); - assert.isFalse(Settings.isSystemTraySupported()); + assert.isFalse(Settings.isSystemTraySupported('1.2.3')); + }); + + it('returns true on Linux beta', () => { + sandbox.stub(process, 'platform').value('linux'); + assert.isTrue(Settings.isSystemTraySupported('1.2.3-beta.4')); }); }); }); diff --git a/ts/types/Settings.ts b/ts/types/Settings.ts index 2e59adade2..02e15c38e7 100644 --- a/ts/types/Settings.ts +++ b/ts/types/Settings.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-only import * as OS from '../OS'; +import { isBeta } from '../util/version'; const MIN_WINDOWS_VERSION = '8.0.0'; @@ -53,7 +54,7 @@ export const getTitleBarVisibility = (): TitleBarVisibility => /** * Returns `true` if you can minimize the app to the system tray. Users can override this * option with a command line flag, but that is not officially supported. - * - * We may add support for Linux in the future. */ -export const isSystemTraySupported = OS.isWindows; +export const isSystemTraySupported = (appVersion: string): boolean => + // We eventually want to support Linux in production. + OS.isWindows() || (OS.isLinux() && isBeta(appVersion));