From ffb0b5a27bcc01d2599cae21a077459eec9f44ed Mon Sep 17 00:00:00 2001 From: Botond Horvath Date: Sat, 21 Jul 2018 18:37:39 +0200 Subject: [PATCH] Hide from Dock on macOS when the tray icon is enabled and the window is closed --- app/dock_icon.js | 17 +++++++++++++++++ app/tray_icon.js | 3 +++ main.js | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 app/dock_icon.js diff --git a/app/dock_icon.js b/app/dock_icon.js new file mode 100644 index 0000000000..eb133a64d5 --- /dev/null +++ b/app/dock_icon.js @@ -0,0 +1,17 @@ +const { app } = require('electron'); + +const dockIcon = {}; + +dockIcon.show = () => { + if (process.platform === 'darwin') { + app.dock.show(); + } +}; + +dockIcon.hide = () => { + if (process.platform === 'darwin') { + app.dock.hide(); + } +}; + +module.exports = dockIcon; diff --git a/app/tray_icon.js b/app/tray_icon.js index 93dad3644b..2f7801d7bb 100644 --- a/app/tray_icon.js +++ b/app/tray_icon.js @@ -2,6 +2,7 @@ const path = require('path'); const fs = require('fs'); const { app, Menu, Tray } = require('electron'); +const dockIcon = require('./dock_icon'); let trayContextMenu = null; let tray = null; @@ -34,8 +35,10 @@ function createTrayIcon(getMainWindow, messages) { if (mainWindow) { if (mainWindow.isVisible()) { mainWindow.hide(); + dockIcon.hide(); } else { mainWindow.show(); + dockIcon.show(); tray.forceOnTop(mainWindow); } diff --git a/main.js b/main.js index 146cb550cc..35395ab369 100644 --- a/main.js +++ b/main.js @@ -63,6 +63,7 @@ const attachments = require('./app/attachments'); const attachmentChannel = require('./app/attachment_channel'); const updater = require('./ts/updater/index'); const createTrayIcon = require('./app/tray_icon'); +const dockIcon = require('./app/dock_icon'); const ephemeralConfig = require('./app/ephemeral_config'); const logging = require('./app/logging'); const sql = require('./app/sql'); @@ -94,6 +95,9 @@ function showWindow() { if (tray) { tray.updateContextMenu(); } + + // show the app on the Dock in case it was hidden before + dockIcon.show(); } if (!process.mas) { @@ -366,6 +370,11 @@ function createWindow() { tray.updateContextMenu(); } + // hide the app from the Dock on macOS if the tray icon is enabled + if (usingTrayIcon) { + dockIcon.hide(); + } + return; }