$Merge branch 'wicast-TrayIcon'
This commit is contained in:
commit
b06b2b8643
5 changed files with 120 additions and 1 deletions
BIN
resources/images/logo_tray.png
Normal file
BIN
resources/images/logo_tray.png
Normal file
Binary file not shown.
|
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/'],
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
89
src/server/tray.js
Normal file
89
src/server/tray.js
Normal file
|
|
@ -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
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue