error handling, launcher ui, read-only mode, rm plot/smooth

This commit is contained in:
bordun 2020-03-09 19:12:43 +01:00
parent cee4cb81b7
commit 4f31985930
59 changed files with 1299 additions and 781 deletions

View file

@ -17,7 +17,7 @@ module.exports = {
ipc.send('connected')
var recentSessions = settings.read('recentSessions')
ipc.send('sessionList', recentSessions, clientId)
ipc.send('clipboard', clipboard, clientId)
@ -183,7 +183,7 @@ module.exports = {
var root = settings.read('remoteRoot')
if (root && !data.path.includes(root)) {
console.error('Could not save: path outside of remote-root')
console.error('(ERROR) Could not save: path outside of remote-root')
return ipc.send('notify', {
class: 'error',
locale: 'remotesave_fail',
@ -194,7 +194,7 @@ module.exports = {
try {
JSON.parse(data.session)
} catch(e) {
return console.error('Could not save: invalid file')
return console.error('(ERROR) Could not save: invalid file')
}
fs.writeFile(data.path, data.session, function(err, fdata) {
@ -236,11 +236,11 @@ module.exports = {
if (Array.isArray(data.path)) data.path = path.resolve(...data.path)
if (!path.basename(data.path).match(/.*\.json$/)) return console.error('Sessions must be saved as .json files')
if (!path.basename(data.path).match(/.*\.json$/)) return console.error('(ERROR) Sessions must be saved as .json files')
module.exports.fileSave(data, clientId, true, ()=>{
console.log('Session file saved in '+ data.path)
console.log('(INFO) Session file saved in '+ data.path)
ipc.send('sessionSaved', clientId)
@ -261,11 +261,11 @@ module.exports = {
if (Array.isArray(data.path)) data.path = path.resolve(...data.path)
if (!path.basename(data.path).match(/.*\.state/)) return console.error('Statesaves must be saved as .state files')
if (!path.basename(data.path).match(/.*\.state/)) return console.error('(ERROR) Statesaves must be saved as .state files')
module.exports.fileSave(data, clientId, true, ()=>{
console.log('State file saved in '+ data.path)
console.log('(INFO) State file saved in '+ data.path)
})

View file

@ -20,17 +20,22 @@ module.exports = function(options={}) {
useContentSize: true,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: !!options.node
nodeIntegration: !!options.node,
},
show: false,
})
window.once('ready-to-show', ()=>{
if (options.fullscreen) {
window.setFullScreen(true)
}
window.show()
})
window.webContents.once('page-title-updated', ()=>{
if (options.fullscreen) {
window.webContents.sendInputEvent({keyCode: 'F11', type: 'keyDown'})
}
})
window.webContents.on('will-prevent-unload', (event)=>{
var choice = dialog.showMessageBoxSync(window, {
@ -79,10 +84,6 @@ module.exports = function(options={}) {
window.reload()
})
if (options.fullscreen) shortcut.register(window,'F11',function(){
window.setFullScreen(!window.isFullScreen())
})
shortcut.register(window,'F12',function(){
window.toggleDevTools()
})

View file

@ -12,11 +12,11 @@ function nodeMode() {
if (!settings.read('noGui')) {
settings.cli = true
settings.write('noGui', true, true)
console.warn('Headless mode (--no-gui) enabled automatically')
console.warn('(INFO) Headless mode (--no-gui) enabled automatically')
}
process.on('uncaughtException', (err)=>{
console.error('A JavaScript error occurred in the main process:')
console.error('(ERROR) A JavaScript error occurred in the main process:')
console.error(err.stack)
})
@ -42,9 +42,9 @@ if (process.title === 'node' || process.title === 'node.exe') {
}
var start = function(readyApp) {
function start() {
if (!settings.read('guiOnly') && !serverStarted) {
if (!serverStarted) {
var server = require('./server'),
osc = require('./osc'),
@ -61,32 +61,34 @@ var start = function(readyApp) {
}
if (!settings.read('noGui')) {
}
var app = require('./electron-app')
var address = typeof settings.read('guiOnly')=='string'? 'http://' + settings.read('guiOnly') : settings.read('appAddresses')[0]
address += settings.read('urlOptions')
function openClient() {
var launch = ()=>{
var win = require('./electron-window')({address:address, shortcuts:true, zoom:false, fullscreen: settings.read('fullScreen')})
return win
}
if (app.isReady()) {
return launch()
} else {
app.on('ready',function(){
launch()
})
}
var app = require('./electron-app')
var address = settings.read('appAddresses')[0]
address += settings.read('urlOptions')
var launch = ()=>{
var win = require('./electron-window')({address:address, shortcuts:true, zoom:false, fullscreen: settings.read('fullScreen')})
return win
}
if (app.isReady()) {
return launch()
} else {
app.on('ready',function(){
launch()
})
}
}
if (settings.cli) {
start()
if (!settings.read('noGui')) openClient()
} else {
@ -99,7 +101,7 @@ if (settings.cli) {
app.on('ready',function(){
global.settings = settings
global.midilist = require('./midi').list
launcher = require('./electron-window')({address:address, shortcuts:dev, width:680, height:(100 + 8*3 + 29 * Object.keys(settings.options).filter(x=>settings.options[x].launcher !== false).length), node:true, color:'#151a24'})
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'})
launcher.on('close', ()=>{
process.stdout.write = stdoutWrite
process.stderr.write = stderrWrite
@ -130,18 +132,16 @@ if (settings.cli) {
ipcMain.on('start',function(e, options){
var gui = start()
start()
if (!settings.read('noGui')) openClient()
if (settings.read('guiOnly')) {
launcher.hide()
gui.on('close',()=>{
launcher.close()
})
} else {
launcher.webContents.send('started')
}
})
ipcMain.on('openClient',function(e, options){
openClient()
})

View file

@ -66,7 +66,7 @@ class MidiConverter {
} else if (name == 'osc') {
instance.receiveOsc(data)
} else if (name == 'error') {
console.error('ERROR: MIDI: ' + data)
console.error('(ERROR, MIDI) ' + data)
if (instance) instance.stop()
}

View file

@ -7,7 +7,7 @@ module.exports = {
},
'l':{alias:'load',type:'string',file:{name:'OSC Session (.json)', extensions: ['json', 'js']},describe:'session file to load'},
'state':{type:'string',file:{name:'OSC State (.state)', extensions: ['state']},describe:'state file to load'},
'b':{alias:'blank',type:'boolean',describe:'load a blank session and start the editor'},
// 'b':{alias:'blank',type:'boolean',describe:'load a blank session and start the editor'},
'c':{alias:'custom-module',type:'array',file:{name:'OSC Custom module (.js)', extensions: ['js']},describe:'custom module file to load (custom options can be passed after the filename)'},
'p':{alias:'port',type:'number',describe:'http port of the server (default to 8080)',
check: (p)=>{
@ -21,15 +21,15 @@ module.exports = {
true : 'Port must be an integer >= 1024'
}
},
'tcp-port':{type:'number', describe:'TCP server input port',
'tcp-port':{type:'number', describe:'tcp server input port',
check: (t, argv)=>{
var h = argv['port'] || 8080
if (t===h) return 'TCP input port must different from --port'
if (t===h) return 'tcp input port must different from --port'
return (!isNaN(t) && t > 1023 && parseInt(t)===t) ?
true : 'Port must be an integer >= 1024'
}
},
'tcp-targets':{type:'array',describe:'TCP servers to connect to (ip:port pairs), does not susbtitute for --send',
'tcp-targets':{type:'array',describe:'tcp servers to connect to (ip:port pairs), does not susbtitute for --send',
check: (s, argv)=>{
if (!argv['tcp-port']) return '--tcp-port must be set'
return s.some(item=>!item.match('^[^:\s\"\']*:[0-9]{4,5}[\s\"\']*$')) ?
@ -44,19 +44,19 @@ module.exports = {
true : 'no-gui and gui-only can\'s be enabled simultaneously'
}
},
'g':{alias:'gui-only',type:'string',describe:'app server\'s url. If true, local port (--port) is used',
check: (g,argv)=>{
return (!g || !argv.n) ?
true : 'no-gui and gui-only can\'s be enabled simultaneously'
}
},
// 'g':{alias:'gui-only',type:'string',describe:'app server\'s url. If true, local port (--port) is used',
// check: (g,argv)=>{
// return (!g || !argv.n) ?
// true : 'no-gui and gui-only can\'s be enabled simultaneously'
// }
// },
't':{alias:'theme',type:'array',describe:'theme name or path (mutliple values allowed)'},
'e':{alias:'examples',type:'boolean',describe:'list examples instead of recent sessions',
check: (e,argv)=>{
return (!e || !argv.l) ?
true : 'examples can\'t be listed if --load is set'
}
},
// 'e':{alias:'examples',type:'boolean',describe:'list examples instead of recent sessions',
// check: (e,argv)=>{
// return (!e || !argv.l) ?
// true : 'examples can\'t be listed if --load is set'
// }
// },
'url-options':{type:'array',describe:'url options (opt=value pairs)',
check: (u, argv)=>{
return (!u || !argv.n) ?
@ -64,7 +64,7 @@ module.exports = {
}
},
'disable-vsync':{type:'boolean',describe:'disable gui\'s vertical synchronization', restart: true},
'disable-gpu':{type:'boolean',describe:'disable hardware acceleration', restart: true},
// 'disable-gpu':{type:'boolean',describe:'disable hardware acceleration', restart: true},
'force-gpu':{type:'boolean',describe:'ignore chrome\'s gpu blacklist', restart: true},
'read-only':{type:'boolean',describe:'disable session editing and session history changes',
check: (r, argv)=>{

View file

@ -36,7 +36,7 @@ class OscServer {
try {
return fs.readFileSync(customModule[0], 'utf8')
} catch(err) {
console.log('CustomModule Error: File not found: ' + customModule[0])
console.log('(ERROR) Custom module not found: ' + customModule[0])
return false
}
})(),
@ -64,11 +64,11 @@ class OscServer {
url = path.resolve(path.dirname(customModule[0]), url)
return JSON.parse(fs.readFileSync(url, 'utf8'))
} catch(e) {
console.error('ERROR: could not load json file from ' + url)
console.error('(ERROR) could not load json file from ' + url)
console.error(e.message)
}
} else {
console.error('ERROR: unauthorized file type for loadJSON')
console.error('(ERROR) unauthorized file type for loadJSON')
}
},
saveJSON: (url, data)=>{
@ -77,11 +77,11 @@ class OscServer {
try {
return fs.writeFileSync(url, JSON.stringify(data, null, ' '))
} catch(e) {
console.error('ERROR: could not save json file to ' + url)
console.error('(ERROR) could not save json file to ' + url)
console.error(e.message)
}
} else {
console.error('ERROR: unauthorized file type for saveJSON')
console.error('(ERROR) unauthorized file type for saveJSON')
}
},
app: this.customModuleEventEmitter,
@ -164,7 +164,7 @@ class OscServer {
} else {
if (typeof data.address !== 'string' || data.address[0] !== '/') {
console.error('OSC error: malformed address: "' + data.address + '')
console.error('(ERROR, OSC) Malformed address: ' + data.address)
return
}
@ -184,7 +184,7 @@ class OscServer {
}
if (debug) console.log('OSC sent: ',{address:data.address, args: data.args}, 'To: ' + data.host + ':' + data.port)
if (debug) console.log('(OSC) Out: ',{address:data.address, args: data.args}, 'To: ' + data.host + ':' + data.port)
}
@ -203,7 +203,7 @@ class OscServer {
ipc.send('receiveOsc',data)
if (debug) console.log('OSC received: ', {address:data.address, args: data.args}, 'From: ' + data.host + ':' + data.port)
if (debug) console.log('(OSC) In: ', {address:data.address, args: data.args}, 'From: ' + data.host + ':' + data.port)
}

View file

@ -25,13 +25,13 @@ class OscTCPClient extends EventEmitter {
this.port = new osc.TCPSocketPort(this.options)
this.port.on('error', (err)=>{
console.error(`TCP: Error: ${err.message}`)
console.error(`(ERROR, TCP) ${err.message}`)
})
this.port.on('close', (hadErr)=>{
console.log(`TCP: connection closed (${this.remoteAddress}:${this.remotePort})`)
console.log(`(TCP) Connection closed (${this.remoteAddress}:${this.remotePort})`)
if (!this.options.socket) {
console.log(`TCP: attempting reconnection in 5s (${this.remoteAddress}:${this.remotePort})`)
console.log(`(TCP) Attempting reconnection in 5s (${this.remoteAddress}:${this.remotePort})`)
this.reconnect()
} else {
this.emit('die')
@ -43,7 +43,7 @@ class OscTCPClient extends EventEmitter {
})
this.port.on('ready', ()=>{
console.log(`TCP: connection established (${this.remoteAddress}:${this.remotePort})`)
console.log(`(TCP) Connection established (${this.remoteAddress}:${this.remotePort})`)
})
if (!this.options.socket) {

View file

@ -10,8 +10,12 @@ var oscUDPServer = new osc.UDPPort({
broadcast: true
})
oscUDPServer.on('error', function(error) {
console.error(error)
oscUDPServer.on('error', function(e) {
if (e.code === 'EADDRINUSE') {
console.error(`(ERROR, UDP) could not open port ${oscInPort} (already in use) `)
} else {
console.error(`(ERROR, UDP) ${e.message}`)
}
})
zeroconf.publish({
@ -19,8 +23,6 @@ zeroconf.publish({
protocol: 'udp',
type: 'osc',
port: oscInPort
}).on('error', (e)=>{
console.error(`Error: Zeroconf: ${e.message}`)
})
module.exports = oscUDPServer

View file

@ -75,6 +75,14 @@ function httpRoute(req, res) {
}
}
server.on('error', (e)=>{
if (e.code === 'EADDRINUSE') {
console.error(`(ERROR, HTTP) Could not open port ${oscInPort} (already in use) `)
} else {
console.error(`(ERROR, HTTP) ${e.message}`)
}
})
server.listen(settings.read('httpPort'))
http.get(settings.read('appAddresses')[0] + '/osc-ping', ()=>{}).on('error', ()=>{httpCheck(false)})
@ -84,9 +92,9 @@ function httpCheck(ok){
clearTimeout(httpCheckTimeout)
httpCheckTimeout = null
if (ok) {
console.log('App available at ' + appAddresses.join(' & '))
console.log('(INFO) App available at ' + appAddresses.join(' & '))
} else {
console.error('Error: could not setup http server, maybe try a different port ?')
console.error('(ERROR, HTTP) Could not setup http server, maybe try a different port ?')
}
}
@ -95,7 +103,7 @@ zeroconf.publish({
type: 'http',
port: settings.read('httpPort')
}).on('error', (e)=>{
console.error(`Error: Zeroconf: ${e.message}`)
console.error(`(ERROR, ZEROCONF) ${e.message}`)
})
var bindCallbacks = function(callbacks) {

View file

@ -37,6 +37,8 @@ argv.getUsageInstance().help = ()=>{
}
argv = argv.argv
delete argv._
delete argv.$0
// are we in a terminal ?
var cli = false,

View file

@ -27,7 +27,7 @@ class Theme {
} else if (!theme.includes('.css') && fs.existsSync(path.resolve(__dirname + '/../assets/themes/' + theme + '.css'))) {
this.files.push(path.resolve(__dirname + '/../assets/themes/' + theme + '.css'))
} else {
console.error('Theme error: "' + theme + '" not found.')
console.error('(ERROR) Theme not found: "' + theme)
}
}
@ -46,7 +46,7 @@ class Theme {
try {
this.css.push(fs.readFileSync(this.files[i],'utf-8'))
} catch(err) {
console.error('Theme error: could not load "' + this.files[i] + '".')
console.error('(ERROR) Could not load theme "' + this.files[i])
}
}