diff --git a/desktop/main.js b/desktop/main.js --- a/desktop/main.js +++ b/desktop/main.js @@ -1,4 +1,11 @@ -const { app, BrowserWindow, shell, Menu } = require('electron'); +const { + app, + BrowserWindow, + shell, + Menu, + ipcMain, + systemPreferences, +} = require('electron'); const path = require('path'); const isDev = process.env.ENV === 'dev'; @@ -42,6 +49,27 @@ }); }); + ipcMain.on('on-top-bar-double-click', () => { + if (isMac) { + 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 }) => { shell.openExternal(url); return { action: 'deny' }; diff --git a/desktop/preload.js b/desktop/preload.js --- a/desktop/preload.js +++ b/desktop/preload.js @@ -2,6 +2,7 @@ const bridge = { onNavigate: callback => ipcRenderer.on('on-navigate', callback), + onTopBarDoubleClick: () => ipcRenderer.send('on-top-bar-double-click'), }; 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 @@ -186,12 +186,16 @@
-
+
electron?.onTopBarDoubleClick()} + >

e.stopPropagation() : null} > 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 @@ -6,6 +6,7 @@ onNavigate: ( (event: any, { canGoBack: boolean, canGoForward: boolean }) => void, ) => void, + onTopBarDoubleClick: () => {}, } = typeof electronContextBridge === 'undefined' ? null : electronContextBridge; export default electron;