diff --git a/addons/api/mirage/scenarios/ipc.js b/addons/api/mirage/scenarios/ipc.js index 04ff375d4..6e44988e4 100644 --- a/addons/api/mirage/scenarios/ipc.js +++ b/addons/api/mirage/scenarios/ipc.js @@ -120,17 +120,17 @@ export default function initializeMockIPC(server) { } /** - * Check for browsers running on mac OS + * Check for window chrome on MacOS */ - isMacOS() { - return Boolean(window.navigator.userAgent.match(/(macintosh)/i)); + hasMacOSChrome() { + return false; } /** - * Check for browsers running on windows OS + * Check for OS chrome state */ - isWindowsOS() { - return Boolean(window.navigator.userAgent.match(/(windows)/i)); + showWindowActions() { + return true; } /** diff --git a/package.json b/package.json index 6db6c4f30..cef044455 100755 --- a/package.json +++ b/package.json @@ -80,7 +80,8 @@ "path-parse": "^1.0.7", "nth-check": "^2.0.1", "tmpl": "^1.0.5", - "set-value": "^4.0.1" + "set-value": "^4.0.1", + "ansi-regex": "^5.0.1" }, "config": { "commitizen": { diff --git a/ui/desktop/README.md b/ui/desktop/README.md index 34634f60c..ba9ca6e88 100644 --- a/ui/desktop/README.md +++ b/ui/desktop/README.md @@ -89,6 +89,7 @@ These environment variables may be used to customized the build. | `APP_UPDATER_LATEST_VERSION_LOCATION` | Location of app release to use for updating client. Can be a filepath or url. | | `BYPASS_CLI_SETUP` | Disable download and extraction of cli. For development use only. | | `BYPASS_APP_UPDATER` | Disable app updater feature. For development use only. | +| `DISABLE_WINDOW_CHROME` | Disable window chrome. For internal use only. | ### Building for Production diff --git a/ui/desktop/app/controllers/application.js b/ui/desktop/app/controllers/application.js index 10cf5fcc7..0eb5226e0 100644 --- a/ui/desktop/app/controllers/application.js +++ b/ui/desktop/app/controllers/application.js @@ -1,7 +1,6 @@ import Controller from '@ember/controller'; import { inject as service } from '@ember/service'; import config from '../config/environment'; -import { computed } from '@ember/object'; export default class ApplicationController extends Controller { // =services @@ -11,17 +10,4 @@ export default class ApplicationController extends Controller { // =attributes notifyTimeout = config.notifyTimeout; - - // =attributes - - /** - * Display OS window actions (minimize, fullscreen, close) for - * Windows and Linux as OS frame/shell is disable. - * Does not apply to MacOS. - * @type {boolean} - */ - @computed('isMacOS') - get isFrameless() { - return !this.isMacOS; - } } diff --git a/ui/desktop/app/routes/application.js b/ui/desktop/app/routes/application.js index 4acb8a175..a52baa954 100644 --- a/ui/desktop/app/routes/application.js +++ b/ui/desktop/app/routes/application.js @@ -31,10 +31,14 @@ export default class ApplicationRoute extends Route { } /** - * Add OS config on controller. + * Add window frame config on controller. */ async setupController(controller) { - controller.set('isMacOS', await this.ipc.invoke('isMacOS')); + controller.set('hasMacOSChrome', await this.ipc.invoke('hasMacOSChrome')); + controller.set( + 'showWindowActions', + await this.ipc.invoke('showWindowActions') + ); } // =actions diff --git a/ui/desktop/app/templates/application.hbs b/ui/desktop/app/templates/application.hbs index 1687c0e53..959fb2b05 100644 --- a/ui/desktop/app/templates/application.hbs +++ b/ui/desktop/app/templates/application.hbs @@ -1,14 +1,14 @@ {{page-title (app-name)}} @@ -19,7 +19,7 @@ {{/if}} - {{#if this.isFrameless}} + {{#if this.showWindowActions}} { } Menu.setApplicationMenu(menuTemplate); + /** + * Enable electron OS window frame/chrome for MacOS only. + * Disable frame/chrome regardless of OS when + * `DISABLE_WINDOW_CHROME=true`. + */ + let showWindowChrome = isMac(); + if (process.env.DISABLE_WINDOW_CHROME) showWindowChrome = false; + const browserWindowOptions = { width: 1280, height: 760, - titleBarStyle: 'hiddenInset', - frame: isMac(), + frame: showWindowChrome, + titleBarStyle: showWindowChrome ? 'hiddenInset' : 'none', webPreferences: { partition, sandbox: true, diff --git a/ui/desktop/electron-app/src/ipc/handlers.js b/ui/desktop/electron-app/src/ipc/handlers.js index d66182f4c..599e9c765 100644 --- a/ui/desktop/electron-app/src/ipc/handlers.js +++ b/ui/desktop/electron-app/src/ipc/handlers.js @@ -69,9 +69,22 @@ handle('connect', ({ target_id, token, host_id }) => handle('stop', ({ session_id }) => sessionManager.stopById(session_id)); /** - * Check for MacOS OS + * Check for OS window chrome. Enabled on MacOS only. + * Window chrome is disabled regardless of platform for + * `DISABLE_WINDOW_CHROME=true`. */ -handle('isMacOS', () => isMac()); +handle('hasMacOSChrome', () => + process.env.DISABLE_WINDOW_CHROME ? false : isMac() +); + +/** + * Show window actions for non-MacOS platforms. + * Window actions are disabled regardless of platform for + * `DISABLE_WINDOW_CHROME=true`. + */ +handle('showWindowActions', () => + process.env.DISABLE_WINDOW_CHROME ? false : !isMac() +); /** * Minimize window diff --git a/ui/desktop/electron-app/yarn.lock b/ui/desktop/electron-app/yarn.lock index c19191736..bc3413833 100644 --- a/ui/desktop/electron-app/yarn.lock +++ b/ui/desktop/electron-app/yarn.lock @@ -416,20 +416,10 @@ ansi-escapes@^4.2.1: dependencies: type-fest "^0.21.3" -ansi-regex@^2.0.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" - integrity sha1-w7M6te42DYbg5ijwRorn7yfWVN8= - -ansi-regex@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" - integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg= - -ansi-regex@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" - integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== +ansi-regex@^2.0.0, ansi-regex@^3.0.0, ansi-regex@^5.0.0, ansi-regex@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" + integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== ansi-styles@^4.0.0, ansi-styles@^4.1.0: version "4.3.0" diff --git a/ui/desktop/tests/acceptance/application-test.js b/ui/desktop/tests/acceptance/application-test.js index 23a254e0e..0cf4c0837 100644 --- a/ui/desktop/tests/acceptance/application-test.js +++ b/ui/desktop/tests/acceptance/application-test.js @@ -47,21 +47,41 @@ module('Acceptance | origin', function (hooks) { sinon.restore(); }); - test('visiting index on MacOS hides custom window actions', async function (assert) { + test('visiting index with chrome disabled hides custom window actions', async function (assert) { assert.expect(3); - stubs.ipcService.withArgs('isMacOS').returns(true); + stubs.ipcService.withArgs('showWindowActions').returns(false); await visit(urls.origin); - assert.notOk(find('.button-window-close')); - assert.notOk(find('.button-window-minimize')); - assert.notOk(find('.button-window-fullscreen')); + assert.notOk(find('.button-window-close'), 'Window close button'); + assert.notOk(find('.button-window-minimize'), 'Window minimize button'); + assert.notOk(find('.button-window-fullscreen'), 'Window fullscreen button'); }); - test('visiting index on non-MacOS shows custom window actions', async function (assert) { + test('visiting index with chrome enabled shows custom window actions', async function (assert) { assert.expect(3); - stubs.ipcService.withArgs('isMacOS').returns(false); + stubs.ipcService.withArgs('showWindowActions').returns(true); await visit(urls.origin); - assert.ok(find('.button-window-close')); - assert.ok(find('.button-window-minimize')); - assert.ok(find('.button-window-fullscreen')); + assert.ok(find('.button-window-close'), 'Window close button'); + assert.ok(find('.button-window-minimize'), 'Window minimize button'); + assert.ok(find('.button-window-fullscreen'), 'Window fullscreen button'); + }); + + test('visiting index with MacOS chrome enabled', async function (assert) { + assert.expect(1); + stubs.ipcService.withArgs('hasMacOSChrome').returns(true); + await visit(urls.origin); + assert.ok( + find('.rose-header.header-cushion'), + 'Adds header padding around native window actions' + ); + }); + + test('visiting index with MacOS chrome disabled', async function (assert) { + assert.expect(1); + stubs.ipcService.withArgs('hasMacOSChrome').returns(false); + await visit(urls.origin); + assert.notOk( + find('.rose-header.header-cushion'), + 'Does not add header padding around native window actions' + ); }); }); diff --git a/ui/desktop/tests/helpers/window-mock-ipc.js b/ui/desktop/tests/helpers/window-mock-ipc.js index 8151c8cbc..ac05e8a78 100644 --- a/ui/desktop/tests/helpers/window-mock-ipc.js +++ b/ui/desktop/tests/helpers/window-mock-ipc.js @@ -17,7 +17,8 @@ class MockIPC { } resetOrigin() {} - isMacOS() {} + hasMacOSChrome() {} + showWindowActions() {} } /** diff --git a/yarn.lock b/yarn.lock index e1af5f636..d41364d00 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4179,25 +4179,10 @@ ansi-html@0.0.7, ansi-html@^0.0.7: resolved "https://registry.yarnpkg.com/ansi-html/-/ansi-html-0.0.7.tgz#813584021962a9e9e6fd039f940d12f56ca7859e" integrity sha1-gTWEAhliqenm/QOflA0S9WynhZ4= -ansi-regex@^2.0.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" - integrity sha1-w7M6te42DYbg5ijwRorn7yfWVN8= - -ansi-regex@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" - integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg= - -ansi-regex@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997" - integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg== - -ansi-regex@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" - integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== +ansi-regex@^2.0.0, ansi-regex@^3.0.0, ansi-regex@^4.1.0, ansi-regex@^5.0.0, ansi-regex@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" + integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== ansi-styles@^2.2.1: version "2.2.1"