diff --git a/resources/images/logo_16x16.png b/resources/images/logo_tray.png similarity index 100% rename from resources/images/logo_16x16.png rename to resources/images/logo_tray.png diff --git a/resources/images/logo_tray@x2.png b/resources/images/logo_tray@x2.png new file mode 100644 index 00000000..c3c4f0c6 Binary files /dev/null and b/resources/images/logo_tray@x2.png differ diff --git a/scripts/copy-assets.js b/scripts/copy-assets.js index 65c2df23..ec752afe 100644 --- a/scripts/copy-assets.js +++ b/scripts/copy-assets.js @@ -4,6 +4,8 @@ var cpr = require('cpr'), files = [ ['../resources/images/logo_nobadge.png', '../app/assets/favicon.png'], ['../resources/images/logo.png', '../app/assets/logo.png'], + ['../resources/images/logo_tray.png', '../app/assets/logo_tray.png'], + ['../resources/images/logo_tray@x2.png', '../app/assets/logo_tray@x2.png'], ['../LICENSE', '../app/LICENSE'], ['../src/python/', '../app/server/python/'], ['../resources/fonts/', '../app/assets/fonts/'], diff --git a/src/server/index.js b/src/server/index.js index 50e47f7b..7c74cca6 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -217,11 +217,6 @@ function startLauncher() { app.on('ready',function(){ launcher = require('./electron-window')({address:address, shortcuts:dev, width:680, height:(40 + 200 + 20 + 24 * Object.keys(settings.options).filter(x=>settings.options[x].launcher !== false).length / 2), node:true, color:'#151a24', id: 'launcher'}) require('@electron/remote/main').enable(launcher.webContents) - launcher.on('close', ()=>{ - process.stdout.write = stdoutWrite - process.stderr.write = stderrWrite - if (process.log) process.log = processLog - }) tray = require('./tray')({ window: launcher, @@ -231,6 +226,25 @@ function startLauncher() { stopServer: stopServerProcess }) + launcher.on('will-close', ()=>{ + if (clientWindows.length) { + launcher.hide() + e.preventDefault() + } + }) + + launcher.on('close', (e)=>{ + if (clientWindows.length) { + launcher.hide() + e.preventDefault() + return + } + process.stdout.write = stdoutWrite + process.stderr.write = stderrWrite + if (process.log) process.log = processLog + tray.destroy() + }) + }) let processLog = process.log, diff --git a/src/server/tray.js b/src/server/tray.js index 79e63542..bb49d4a6 100644 --- a/src/server/tray.js +++ b/src/server/tray.js @@ -1,72 +1,89 @@ -var { Menu, Tray, ipcMain } = require('electron') - -var tray = null, +var {Menu, Tray, ipcMain} = require('electron'), + settings = require('./settings'), + tray = null, contextMenu = null, - hideInTray = false, isServerRunning = false -module.exports = function (options = {}) { - - ipcMain.on('start', function (e, options) { - isServerRunning = true - resetMenu(isServerRunning) - }) - - ipcMain.on('stop', function (e, options) { - isServerRunning = false - resetMenu(isServerRunning) - }) +module.exports = function(options = {}) { var icon = __dirname + '/../assets/logo.png' if (process.platform === 'darwin') { - var icon = __dirname + '/../assets/logo_16x16.png' + icon = __dirname + '/../assets/logo_tray.png' } + tray = new Tray(icon) contextMenu = Menu.buildFromTemplate([ { - label: 'Open/Hide', click: () => { - if (hideInTray) { - options.window.show() - hideInTray = false - } else { - options.window.hide() - hideInTray = true - } + label: 'Show launcher', + id: 'show', + click: ()=>{ + options.window.show() } }, { - label: 'Start/Stop', - click: () => { - if (isServerRunning) { - ipcMain.emit('stop'); - } else { - ipcMain.emit('start'); - } + label: 'Hide launcher', + id: 'hide', + click: ()=>{ + options.window.hide() } }, { - label: 'New Window', click: () => { + label: 'Start server', + id: 'start', + click: ()=>{ + ipcMain.emit('start') + } + }, + { + label: 'Stop server', + id: 'stop', + click: ()=>{ + ipcMain.emit('stop') + } + }, + { + label: 'New client window', + id: 'new', + click: ()=> { if (isServerRunning) { options.openClient() } - }, - enabled: isServerRunning + } }, - { type: 'separator' }, - { label: 'Quit', click: () => { void options.app.quit(); } }, - ]); + { + type: 'separator' + }, + { + label: 'Quit', + role: 'Quit' + }, + ]) + tray.setContextMenu(contextMenu) - tray.setToolTip('Open Stage Control') + tray.setToolTip(settings.infos.productName) + + function updateMenu(){ + contextMenu.getMenuItemById('start').visible = !isServerRunning + contextMenu.getMenuItemById('stop').visible = isServerRunning + contextMenu.getMenuItemById('show').visible = !options.window.isVisible() + contextMenu.getMenuItemById('hide').visible = options.window.isVisible() + contextMenu.getMenuItemById('new').visible = isServerRunning + tray.setContextMenu(contextMenu) + } + + ipcMain.on('start', function(e, options) { + isServerRunning = true + updateMenu() + }) + + ipcMain.on('stop', function(e, options) { + isServerRunning = false + updateMenu() + }) + + options.window.on('show', updateMenu) + options.window.on('hide', updateMenu) return tray } - -function resetMenu(isServerRunning) { - contextMenu.items.forEach(item => { - if (item.label === 'New Window') { - item.enabled = isServerRunning - } - }) - tray.setContextMenu(contextMenu) -} \ No newline at end of file