Hide title bar on macOS

This commit is contained in:
Evan Hahn 2021-02-01 14:01:25 -06:00 committed by GitHub
parent b672d33f25
commit ddebbf8121
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 297 additions and 24 deletions

View file

@ -70,6 +70,17 @@ type WhatIsThis = import('./window.d').WhatIsThis;
},
});
window.addEventListener('dblclick', (event: Event) => {
const target = event.target as HTMLElement;
const isDoubleClickOnTitleBar = Boolean(
target.classList.contains('module-title-bar-drag-area') ||
target.closest('module-title-bar-drag-area')
);
if (isDoubleClickOnTitleBar) {
window.titleBarDoubleClick();
}
});
// Globally disable drag and drop
document.body.addEventListener(
'dragover',

View file

@ -0,0 +1,10 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
$(document).ready(() => {
const updateFullScreenClass = (isFullScreen: boolean) => {
$(document.body).toggleClass('full-screen', isFullScreen);
};
updateFullScreenClass(window.isFullScreen());
window.onFullScreenChange = updateFullScreenClass;
});

17
ts/set_os_class.ts Normal file
View file

@ -0,0 +1,17 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
$(document).ready(() => {
let className: string;
if (window.Signal.OS.isWindows()) {
className = 'os-windows';
} else if (window.Signal.OS.isMacOS()) {
className = 'os-macos';
} else if (window.Signal.OS.isLinux()) {
className = 'os-linux';
} else {
throw new Error('Unexpected operating system; not applying ');
}
$(document.body).addClass(className);
});

View file

@ -0,0 +1,37 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as sinon from 'sinon';
import { BrowserWindow } from 'electron';
import { toggleMaximizedBrowserWindow } from '../../util/toggleMaximizedBrowserWindow';
describe('toggleMaximizedBrowserWindow', () => {
const createFakeWindow = () => ({
isMaximized: sinon.stub(),
unmaximize: sinon.spy(),
maximize: sinon.spy(),
});
it('maximizes an unmaximized window', () => {
const browserWindow = createFakeWindow();
browserWindow.isMaximized.returns(false);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
toggleMaximizedBrowserWindow((browserWindow as any) as BrowserWindow);
sinon.assert.calledOnce(browserWindow.maximize);
sinon.assert.notCalled(browserWindow.unmaximize);
});
it('unmaximizes a maximized window', () => {
const browserWindow = createFakeWindow();
browserWindow.isMaximized.returns(true);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
toggleMaximizedBrowserWindow((browserWindow as any) as BrowserWindow);
sinon.assert.notCalled(browserWindow.maximize);
sinon.assert.calledOnce(browserWindow.unmaximize);
});
});

View file

@ -1,4 +1,4 @@
// Copyright 2018-2020 Signal Messenger, LLC
// Copyright 2018-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as OS from '../OS';
@ -34,3 +34,12 @@ export const isHideMenuBarSupported = (): boolean => !OS.isMacOS();
// the "draw attention on notification" option is specific to Windows and Linux
export const isDrawAttentionSupported = (): boolean => !OS.isMacOS();
export enum TitleBarVisibility {
Visible,
Hidden,
}
// This should match the "logic" in `stylesheets/_global.scss`.
export const getTitleBarVisibility = (): TitleBarVisibility =>
OS.isMacOS() ? TitleBarVisibility.Hidden : TitleBarVisibility.Visible;

View file

@ -15033,6 +15033,42 @@
"reasonCategory": "falseMatch",
"updated": "2020-12-17T18:08:07.752Z"
},
{
"rule": "jQuery-$(",
"path": "ts/manage_full_screen_class.js",
"line": "$(document).ready(() => {",
"lineNumber": 4,
"reasonCategory": "usageTrusted",
"updated": "2021-01-21T23:06:13.270Z",
"reasonDetail": "Doesn't manipulate the DOM."
},
{
"rule": "jQuery-$(",
"path": "ts/manage_full_screen_class.js",
"line": " $(document.body).toggleClass('full-screen', isFullScreen);",
"lineNumber": 6,
"reasonCategory": "usageTrusted",
"updated": "2021-01-21T23:06:13.270Z",
"reasonDetail": "Manipulates a trusted class."
},
{
"rule": "jQuery-$(",
"path": "ts/manage_full_screen_class.ts",
"line": "$(document).ready(() => {",
"lineNumber": 4,
"reasonCategory": "usageTrusted",
"updated": "2021-01-21T23:06:13.270Z",
"reasonDetail": "Doesn't manipulate the DOM."
},
{
"rule": "jQuery-$(",
"path": "ts/manage_full_screen_class.ts",
"line": " $(document.body).toggleClass('full-screen', isFullScreen);",
"lineNumber": 6,
"reasonCategory": "usageTrusted",
"updated": "2021-01-21T23:06:13.270Z",
"reasonDetail": "Manipulates a trusted class."
},
{
"rule": "React-createRef",
"path": "ts/quill/mentions/completion.js",
@ -15059,6 +15095,42 @@
"updated": "2020-11-06T17:43:07.381Z",
"reasonDetail": "used for figuring out clipboard contents"
},
{
"rule": "jQuery-$(",
"path": "ts/set_os_class.js",
"line": "$(document).ready(() => {",
"lineNumber": 4,
"reasonCategory": "usageTrusted",
"updated": "2021-01-21T23:06:13.270Z",
"reasonDetail": "Doesn't manipulate the DOM."
},
{
"rule": "jQuery-$(",
"path": "ts/set_os_class.js",
"line": " $(document.body).addClass(className);",
"lineNumber": 18,
"reasonCategory": "usageTrusted",
"updated": "2021-01-21T23:06:13.270Z",
"reasonDetail": "Adds a trusted CSS class."
},
{
"rule": "jQuery-$(",
"path": "ts/set_os_class.ts",
"line": "$(document).ready(() => {",
"lineNumber": 4,
"reasonCategory": "usageTrusted",
"updated": "2021-01-21T23:06:13.270Z",
"reasonDetail": "Doesn't manipulate the DOM."
},
{
"rule": "jQuery-$(",
"path": "ts/set_os_class.ts",
"line": " $(document.body).addClass(className);",
"lineNumber": 16,
"reasonCategory": "usageTrusted",
"updated": "2021-01-21T23:06:13.270Z",
"reasonDetail": "Adds a trusted CSS class."
},
{
"rule": "jQuery-wrap(",
"path": "ts/shims/textsecure.js",

View file

@ -0,0 +1,14 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { BrowserWindow } from 'electron';
export function toggleMaximizedBrowserWindow(
browserWindow: BrowserWindow
): void {
if (browserWindow.isMaximized()) {
browserWindow.unmaximize();
} else {
browserWindow.maximize();
}
}

3
ts/window.d.ts vendored
View file

@ -162,6 +162,7 @@ declare global {
isActive: () => boolean;
isAfterVersion: (version: WhatIsThis, anotherVersion: string) => boolean;
isBeforeVersion: (version: WhatIsThis, anotherVersion: string) => boolean;
isFullScreen: () => boolean;
isValidGuid: (maybeGuid: string | null) => boolean;
isValidE164: (maybeE164: unknown) => boolean;
libphonenumber: {
@ -189,6 +190,7 @@ declare global {
};
nodeSetImmediate: typeof setImmediate;
normalizeUuids: (obj: any, paths: Array<string>, context: string) => void;
onFullScreenChange: (fullScreen: boolean) => void;
owsDesktopApp: WhatIsThis;
platform: string;
preloadedImages: Array<WhatIsThis>;
@ -230,6 +232,7 @@ declare global {
};
systemTheme: WhatIsThis;
textsecure: TextSecureType;
titleBarDoubleClick: () => void;
unregisterForActive: (handler: () => void) => void;
updateTrayIcon: (count: number) => void;