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