tray: code lint, retina icon for mac, keep alive launcher and tray when closing if there's a client window
This commit is contained in:
parent
aa2d5029be
commit
a5d5586dc3
5 changed files with 85 additions and 52 deletions
|
Before Width: | Height: | Size: 931 B After Width: | Height: | Size: 931 B |
BIN
resources/images/logo_tray@x2.png
Normal file
BIN
resources/images/logo_tray@x2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
|
|
@ -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/'],
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue