diff --git a/desktop/main.cjs b/desktop/main.cjs --- a/desktop/main.cjs +++ b/desktop/main.cjs @@ -1,4 +1,11 @@ -const { app, BrowserWindow, shell, Menu, ipcMain } = require('electron'); +const { + app, + BrowserWindow, + shell, + Menu, + ipcMain, + systemPreferences, +} = require('electron'); const fs = require('fs'); const path = require('path'); @@ -96,6 +103,31 @@ updateNavigationState(); }); + ipcMain.on('double-click-top-bar', () => { + if (isMac) { + // Possible values for AppleActionOnDoubleClick are Maximize, + // Minimize or None. We handle the last two inside this if. + // Maximize (which is the only behaviour for other platforms) + // is handled in the later block. + const action = systemPreferences.getUserDefault( + 'AppleActionOnDoubleClick', + 'string', + ); + if (action === 'None') { + return; + } else if (action === 'Minimize') { + win.minimize(); + return; + } + } + + if (win.isMaximized()) { + win.unmaximize(); + } else { + win.maximize(); + } + }); + win.webContents.setWindowOpenHandler(({ url: openURL }) => { shell.openExternal(openURL); // Returning 'deny' prevents a new electron window from being created diff --git a/desktop/preload.cjs b/desktop/preload.cjs --- a/desktop/preload.cjs +++ b/desktop/preload.cjs @@ -7,6 +7,7 @@ return () => ipcRenderer.removeListener('on-navigate', withEvent); }, clearHistory: () => ipcRenderer.send('clear-history'), + doubleClickTopBar: () => ipcRenderer.send('double-click-top-bar'), }; contextBridge.exposeInMainWorld('electronContextBridge', bridge); diff --git a/web/app.react.js b/web/app.react.js --- a/web/app.react.js +++ b/web/app.react.js @@ -162,6 +162,9 @@ ); } + onHeaderDoubleClick = () => electron?.doubleClickTopBar(); + stopDoubleClickPropagation = electron ? e => e.stopPropagation() : null; + renderMainContent() { let mainContent; const { tab, settingsSection } = this.props.navInfo; @@ -188,13 +191,14 @@
-
+

Comm diff --git a/web/components/navigation-arrows.react.js b/web/components/navigation-arrows.react.js --- a/web/components/navigation-arrows.react.js +++ b/web/components/navigation-arrows.react.js @@ -8,6 +8,8 @@ import SWMansionIcon from '../SWMansionIcon.react.js'; import css from './navigation-arrows.css'; +const stopDoubleClickPropagation = e => e.stopPropagation(); + function NavigationArrows(): React.Node { const goBack = React.useCallback( () => history.getHistoryObject().goBack(), @@ -37,10 +39,18 @@ return ( diff --git a/web/electron.js b/web/electron.js --- a/web/electron.js +++ b/web/electron.js @@ -11,6 +11,7 @@ // Returns a callback that you can call to remove the listener +onNavigate: OnNavigateListener => () => void, +clearHistory: () => void, + +doubleClickTopBar: () => void, } = typeof electronContextBridge === 'undefined' ? null : electronContextBridge; export default electron;