From 6178a237f06c7bcd1ccdd62e8b18fdc1ed73b3a6 Mon Sep 17 00:00:00 2001 From: Fabian Thielen Date: Sat, 6 Jan 2018 19:13:29 +0100 Subject: [PATCH] Minimize to tray, open Links in Browser --- index.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index cfa8ae5..7347f3b 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const {app, BrowserWindow} = require('electron'); +const {app, BrowserWindow, shell, Tray, Menu} = require('electron'); const path = require('path'); let mainWindow; @@ -23,11 +23,49 @@ app.on('ready', function () { mainWindow.setMenu(null); mainWindow.loadURL('https://www.meistertask.com/app/dashboard'); + + const appIcon = new Tray(path.join(__dirname, '/assets/icons/icon.png')); + const contextMenu = Menu.buildFromTemplate([ + { + label: 'Show App', click: function () { + mainWindow.show(); + } + }, + { + label: 'Quit', click: function () { + app.isQuitting = true; + app.quit(); + } + } + ]); + + appIcon.setContextMenu(contextMenu); + appIcon.setToolTip("MeisterTask Unofficial"); + mainWindow.on('ready-to-show', () => { mainWindow.show(); }); + mainWindow.focus(); + mainWindow.on('closed', function () { mainWindow = null; }); + + mainWindow.on('minimize',function(event){ + event.preventDefault(); + mainWindow.hide(); + }); + + mainWindow.webContents.on('new-window', function (e, url) { + e.preventDefault(); + const protocol = require('url').parse(url).protocol; + if (protocol === "http:" || protocol === 'https:') { + shell.openExternal(url) + } + }); + + appIcon.on('click', function () { + mainWindow.show(); + }); }); \ No newline at end of file