chore: Refactor DISABLE_WINDOW_CHROME var
This commit is contained in:
9 files changed
+53
-50
No files matched your search
@@ -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 OS frame
|
||||
* Check for OS chrome state
|
||||
*/
|
||||
isFrameless() {
|
||||
return true;
|
||||
isWindowChromeless() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,7 +78,7 @@ These environment variables may be used to customized the build.
|
||||
| `APP_UPDATER_LATEST_VERSION_TAG` | Next version for comparison with current version. |
|
||||
| `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_OS_SHELL` | Disable OS shell with window actions. For internal use only. |
|
||||
| `DISABLE_WINDOW_CHROME` | Disable window chrome. For internal use only. |
|
||||
|
||||
### Building for Production
|
||||
|
||||
|
||||
@@ -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,15 +10,4 @@ export default class ApplicationController extends Controller {
|
||||
// =attributes
|
||||
|
||||
notifyTimeout = config.notifyTimeout;
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Check for MacOS frame
|
||||
* @type {boolean}
|
||||
*/
|
||||
@computed('isMacOS', 'isFrameless')
|
||||
get isFrameMacOS() {
|
||||
return this.isMacOS && !this.isFrameless;
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,11 @@ export default class ApplicationRoute extends Route {
|
||||
* Add window frame config on controller.
|
||||
*/
|
||||
async setupController(controller) {
|
||||
controller.set('isMacOS', await this.ipc.invoke('isMacOS'));
|
||||
controller.set('isFrameless', await this.ipc.invoke('isFrameless'));
|
||||
controller.set('hasMacOSChrome', await this.ipc.invoke('hasMacOSChrome'));
|
||||
controller.set(
|
||||
'isWindowChromeless',
|
||||
await this.ipc.invoke('isWindowChromeless')
|
||||
);
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{{page-title (app-name)}}
|
||||
|
||||
<Rose::Layout::Global
|
||||
class='{{if this.isFrameless ' layout-scroll'}}'
|
||||
class='{{if this.isWindowChromeless ' layout-scroll'}}'
|
||||
as |layout|
|
||||
>
|
||||
|
||||
<layout.header>
|
||||
<Rose::Header
|
||||
class='{{if (is-loading) ' loading'}}
|
||||
{{if this.isFrameMacOS ' header-cushion'}}'
|
||||
{{if this.hasMacOSChrome ' header-cushion'}}'
|
||||
as |header|
|
||||
>
|
||||
<header.brand @logo='logo-app' @text={{app-name}} />
|
||||
@@ -19,7 +19,7 @@
|
||||
{{/if}}
|
||||
|
||||
<header.utilities as |utilities|>
|
||||
{{#if this.isFrameless}}
|
||||
{{#if this.isWindowChromeless}}
|
||||
<Rose::Button
|
||||
@iconOnly='flight-icons/x-16'
|
||||
@style='warning'
|
||||
|
||||
@@ -114,17 +114,17 @@ app.on('ready', async () => {
|
||||
Menu.setApplicationMenu(menuTemplate);
|
||||
|
||||
/**
|
||||
* Enable electron OS frame for MacOS only.
|
||||
* Disable frame regardless of OS using `BYPASS_OS_SHELL`
|
||||
* Enable electron OS window frame/chrome for MacOS only.
|
||||
* Disable frame/chrome regardless of OS when `DISABLE_WINDOW_CHROME` is set.
|
||||
*/
|
||||
let showFrame = isMac();
|
||||
if (process.env.BYPASS_OS_SHELL) showFrame = false;
|
||||
let showWindowChrome = isMac();
|
||||
if (process.env.DISABLE_WINDOW_CHROME) showWindowChrome = false;
|
||||
|
||||
const browserWindowOptions = {
|
||||
width: 1280,
|
||||
height: 760,
|
||||
frame: showFrame,
|
||||
titleBarStyle: showFrame ? 'hiddenInset' : 'none',
|
||||
frame: showWindowChrome,
|
||||
titleBarStyle: showWindowChrome ? 'hiddenInset' : 'none',
|
||||
webPreferences: {
|
||||
partition,
|
||||
sandbox: true,
|
||||
|
||||
@@ -69,16 +69,18 @@ handle('connect', ({ target_id, token, host_id }) =>
|
||||
handle('stop', ({ session_id }) => sessionManager.stopById(session_id));
|
||||
|
||||
/**
|
||||
* Check for frameless window state. Only MacOS uses default OS frame.
|
||||
* Frameless window disables OS window actions (minimize, fullscreen, close).
|
||||
* Enable `BYPASS_OS_SHELL` to bypass OS verification for frame.
|
||||
* Check frame/chrome state. Only enabled on non-MacOS.
|
||||
*/
|
||||
handle('isFrameless', () => !isMac() || process.env.BYPASS_OS_SHELL);
|
||||
handle('isWindowChromeless', () =>
|
||||
process.env.DISABLE_WINDOW_CHROME ? false : !isMac()
|
||||
);
|
||||
|
||||
/**
|
||||
* Check for MacOS
|
||||
* Check for MacOS chrome
|
||||
*/
|
||||
handle('isMacOS', () => isMac());
|
||||
handle('hasMacOSChrome', () =>
|
||||
process.env.DISABLE_WINDOW_CHROME ? false : isMac()
|
||||
);
|
||||
|
||||
/**
|
||||
* Minimize window
|
||||
|
||||
@@ -47,31 +47,41 @@ module('Acceptance | origin', function (hooks) {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
test('visiting index on MacOS hides custom window actions', async function (assert) {
|
||||
assert.expect(4);
|
||||
stubs.ipcService.withArgs('isMacOS').returns(true);
|
||||
stubs.ipcService.withArgs('isFrameless').returns(false);
|
||||
test('visiting index with chrome disabled hides custom window actions', async function (assert) {
|
||||
assert.expect(3);
|
||||
stubs.ipcService.withArgs('isWindowChromeless').returns(false);
|
||||
await visit(urls.origin);
|
||||
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 with chrome enabled shows custom window actions', async function (assert) {
|
||||
assert.expect(3);
|
||||
stubs.ipcService.withArgs('isWindowChromeless').returns(true);
|
||||
await visit(urls.origin);
|
||||
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 on non-MacOS shows custom window actions', async function (assert) {
|
||||
assert.expect(4);
|
||||
stubs.ipcService.withArgs('isMacOS').returns(false);
|
||||
stubs.ipcService.withArgs('isFrameless').returns(true);
|
||||
test('visiting index with MacOS chrome disabled', async function (assert) {
|
||||
assert.expect(1);
|
||||
stubs.ipcService.withArgs('hasMacOSChrome').returns(false);
|
||||
await visit(urls.origin);
|
||||
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');
|
||||
assert.notOk(
|
||||
find('.rose-header.header-cushion'),
|
||||
'Disables header padding around native window actions'
|
||||
'Does not add header padding around native window actions'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -17,8 +17,8 @@ class MockIPC {
|
||||
}
|
||||
|
||||
resetOrigin() {}
|
||||
isMacOS() {}
|
||||
isFrameless() {}
|
||||
hasMacOSChrome() {}
|
||||
isWindowChromeless() {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user