Hide from Dock on macOS when the tray icon is enabled and the window is closed

This commit is contained in:
Botond Horvath 2018-07-21 18:37:39 +02:00 committed by Ken Powers
parent bc6d549f20
commit ffb0b5a27b
3 changed files with 29 additions and 0 deletions

17
app/dock_icon.js Normal file
View file

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

View file

@ -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);
}

View file

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