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 @@