diff --git a/resources/images/logo_tray.png b/resources/images/logo_tray.png new file mode 100644 index 00000000..d6670a2a Binary files /dev/null and b/resources/images/logo_tray.png differ 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 73ad3e70..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/'], @@ -14,6 +16,10 @@ var cpr = require('cpr'), ['../node_modules/ace-builds/src-min/worker-javascript.js', '../app/client/workers/worker-javascript.js'], ] +if (process.platform === 'darwin') { + files.push(['../resources/images/logo_16x16.png', '../app/assets/logo_16x16.png']) +} + for (var i in files) { cpr(...files[i].map(f => path.resolve(__dirname + '/' + f)), { overwrite: true diff --git a/src/server/index.js b/src/server/index.js index ed1ef705..7c74cca6 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -5,6 +5,7 @@ var dev = process.argv[0].includes('node_modules'), docsServer, app = null, launcher = null, + tray = null, clientWindows = [], serverProcess = null, node = false @@ -216,11 +217,34 @@ 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', ()=>{ + + tray = require('./tray')({ + window: launcher, + openClient: openClient, + app: app, + startServer: startServerProcess, + 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 new file mode 100644 index 00000000..bb49d4a6 --- /dev/null +++ b/src/server/tray.js @@ -0,0 +1,89 @@ +var {Menu, Tray, ipcMain} = require('electron'), + settings = require('./settings'), + tray = null, + contextMenu = null, + isServerRunning = false + +module.exports = function(options = {}) { + + var icon = __dirname + '/../assets/logo.png' + if (process.platform === 'darwin') { + icon = __dirname + '/../assets/logo_tray.png' + } + + tray = new Tray(icon) + contextMenu = Menu.buildFromTemplate([ + { + label: 'Show launcher', + id: 'show', + click: ()=>{ + options.window.show() + } + }, + { + label: 'Hide launcher', + id: 'hide', + click: ()=>{ + options.window.hide() + } + }, + { + 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() + } + } + }, + { + type: 'separator' + }, + { + label: 'Quit', + role: 'Quit' + }, + ]) + + tray.setContextMenu(contextMenu) + 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 + +}