clean and move files around
This commit is contained in:
parent
8e9b328662
commit
a97a5d818c
54 changed files with 1612 additions and 1063 deletions
|
|
@ -1,125 +0,0 @@
|
|||
var vm = require('vm')
|
||||
|
||||
module.exports = function(settings,fs,ipc,osc,dialog) {
|
||||
|
||||
return {
|
||||
|
||||
ready: function(data,clientId) {
|
||||
if (settings.read('sessionFile')) this.sessionOpen({path:settings.read('sessionFile')},clientId)
|
||||
var recentSessions = settings.read('recentSessions')
|
||||
ipc.send('sessionList',recentSessions,clientId)
|
||||
},
|
||||
|
||||
sessionBrowse: function(data) {
|
||||
var sessionlist = settings.read('recentSessions'),
|
||||
self = this
|
||||
dialog.showOpenDialog(window,{title:'Load session file',defaultPath:settings.read('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
|
||||
if (file==undefined) {return}
|
||||
settings.write('sessionPath',file[0].replace(file[0].split('/').pop(),''))
|
||||
self.sessionOpen({path:file[0]})
|
||||
})
|
||||
},
|
||||
|
||||
sessionSave: function(data) {
|
||||
dialog.showSaveDialog(window,{title:'Save current session',defaultPath:settings.read('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
|
||||
|
||||
if (file==undefined) {return}
|
||||
settings.write('sessionPath',file.replace(file.split('/').pop(),''))
|
||||
|
||||
if (file.indexOf('.js')==-1){file+='.js'}
|
||||
fs.writeFile(file,data, function (err, data) {
|
||||
if (err) throw err
|
||||
console.log('The session was saved in '+file)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
sessionAddToHistory: function(data) {
|
||||
var sessionlist = settings.read('recentSessions')
|
||||
// add session to history
|
||||
sessionlist.unshift(data)
|
||||
// remove doubles from history
|
||||
sessionlist = sessionlist.filter(function(elem, index, self) {
|
||||
return index == self.indexOf(elem)
|
||||
})
|
||||
// save history
|
||||
settings.write('recentSessions',sessionlist)
|
||||
},
|
||||
|
||||
sessionRemoveFromHistory: function(data) {
|
||||
var sessionlist = settings.read('recentSessions')
|
||||
sessionlist.splice(data,1)
|
||||
settings.write('recentSessions',sessionlist)
|
||||
},
|
||||
|
||||
sessionOpen: function(data,clientId) {
|
||||
var file = data.file || (function(){try {return fs.readFileSync(data.path,'utf8')} catch(err) {return false}})(),
|
||||
error = file===false&&data.path?'Session file "' + data.path + '" not found.':false,
|
||||
session
|
||||
|
||||
try {
|
||||
session = vm.runInNewContext(file)
|
||||
} catch(err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
if (data.path) this.sessionAddToHistory(data.path)
|
||||
ipc.send('sessionOpen',JSON.stringify(session),clientId)
|
||||
} else {
|
||||
ipc.send('error',{title:'Error: invalid session file',text:error})
|
||||
}
|
||||
},
|
||||
|
||||
sendOsc: function(data) {
|
||||
|
||||
var targets = []
|
||||
|
||||
if (settings.read('syncTargets') && data.sync!==false) Array.prototype.push.apply(targets, settings.read('syncTargets'))
|
||||
if (data.target) Array.prototype.push.apply(targets, data.target)
|
||||
|
||||
|
||||
for (i in targets) {
|
||||
|
||||
var host = targets[i].split(':')[0],
|
||||
port = targets[i].split(':')[1]
|
||||
|
||||
if (port) osc.send(host,port,data.path,data.args,data.precision)
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
stateSave: function(data) {
|
||||
dialog.showSaveDialog(window,{title:'Save current state to preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
|
||||
|
||||
if (file==undefined) {return}
|
||||
settings.write('presetPath',file)
|
||||
|
||||
if (file.indexOf('.preset')==-1){file+='.preset'}
|
||||
fs.writeFile(file,data, function (err, data) {
|
||||
if (err) throw err
|
||||
console.log('The current state was saved in '+file)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
stateLoad: function(data,clientId) {
|
||||
dialog.showOpenDialog(window,{title:'Load preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
|
||||
|
||||
if (file==undefined) {return}
|
||||
settings.write('presetPath',file[0])
|
||||
|
||||
fs.readFile(file[0],'utf-8', function read(err, data) {
|
||||
if (err) throw err
|
||||
ipc.send('stateLoad',data,clientId)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
fullscreen: function(data) {
|
||||
window.setFullScreen(!window.isFullScreen())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
var fs = require('fs'),
|
||||
settings = require('./settings')(fs)
|
||||
|
||||
|
||||
if (settings.compileScss) {
|
||||
var sass = require(__dirname + '/../browser/js/sass/sass.sync.js')
|
||||
var filenames = fs.readdirSync(__dirname + '/../browser/scss/')
|
||||
for (i in filenames) {
|
||||
if (filenames[i].indexOf('.scss')!=-1)
|
||||
var file = __dirname + '/../browser/scss/' + filenames[i]
|
||||
var light = settings.lightTheme?'$theme:\'light\';':'$theme:\'dark\';'
|
||||
var content = fs.readFileSync(file,'utf8')
|
||||
sass.compile(light+content,{style: sass.style.compact,linefeed: ''}, function(result) {
|
||||
fs.writeFileSync(__dirname + '/../browser/css/'+filenames[i].replace('.scss','.css'),result.text,'utf8')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!settings.noGui) {
|
||||
|
||||
var app = require('app'),
|
||||
browserWindow = require('browser-window'),
|
||||
dialog = require('dialog'),
|
||||
ipc = require('ipc-main')
|
||||
|
||||
dialog.showErrorBox = function(title,err) {
|
||||
console.log(title + ': ' + err)
|
||||
}
|
||||
|
||||
app.commandLine.appendSwitch('--touch-events')
|
||||
|
||||
app.on('window-all-closed', function() {
|
||||
if (process.platform != 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('ready',function(){
|
||||
var server = require('./server-electron')(settings,app,ipc,browserWindow),
|
||||
osc = require('./osc')(ipc,settings),
|
||||
callbacks = require('./callbacks')(settings,fs,ipc,osc,dialog)
|
||||
|
||||
|
||||
server.bindCallbacks(callbacks)
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
var server = require('./server-express')(settings),
|
||||
ipc = server.ipc,
|
||||
osc = require('./osc')(ipc,settings),
|
||||
callbacks = require('./callbacks')(settings,fs,ipc,osc,dialog)
|
||||
|
||||
server.bindCallbacks(callbacks)
|
||||
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
var osc = require('node-osc')
|
||||
|
||||
module.exports = function(ipc, settings) {
|
||||
|
||||
if (settings.read('oscInPort')) {
|
||||
var oscServer = new osc.Server(settings.read('oscInPort'), '127.0.0.1')
|
||||
|
||||
oscServer.on('message', function (msg, rinfo) {
|
||||
var data = {path:msg.shift(),args:msg}
|
||||
if (data.args.length==1) data.args = data.args[0]
|
||||
ipc.send('receiveOsc',data)
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
send: function(host,port,path,args,precision) {
|
||||
|
||||
var client = new osc.Client(host, port)
|
||||
|
||||
var message = new osc.Message(path)
|
||||
|
||||
var numberType = precision==0?'integer':'float'
|
||||
|
||||
if (typeof args=='object') {
|
||||
for (i in args) {
|
||||
var arg = args[i]
|
||||
if (typeof arg == 'number') {
|
||||
message.append({type:numberType,value:arg})
|
||||
} else {
|
||||
message.append({type:'string',value:arg})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (typeof args == 'number') {
|
||||
message.append({type:numberType,value:args})
|
||||
} else {
|
||||
message.append({type:'string',value:args})
|
||||
}
|
||||
}
|
||||
|
||||
client.send(message, function () {
|
||||
client.kill()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
module.exports = function(settings,app,ipc,browserWindow) {
|
||||
|
||||
window = new browserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
title:settings.read('appName'),
|
||||
autoHideMenuBar:true,
|
||||
backgroundColor:'#1a1d22',
|
||||
// show:false
|
||||
})
|
||||
|
||||
window.loadURL('file://' + __dirname + '/../browser/index.html')
|
||||
|
||||
window.on('closed', function() {
|
||||
window = null
|
||||
})
|
||||
|
||||
|
||||
var Menu = require('menu')
|
||||
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate(
|
||||
[
|
||||
{
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Restart',
|
||||
accelerator: 'CmdOrCtrl+R',
|
||||
click: function(){
|
||||
var exec = require('child_process').exec
|
||||
exec(process.argv.join(' '))
|
||||
app.quit()
|
||||
}// function() { window.reload(); }//restartApp
|
||||
},
|
||||
{
|
||||
label: 'Toggle DevTools',
|
||||
accelerator: 'F12',
|
||||
click: function() { window.toggleDevTools(); }
|
||||
},
|
||||
{
|
||||
label: 'Toggle Fullscreen',
|
||||
accelerator: 'F11',
|
||||
click: function() { window.setFullScreen(!window.isFullScreen()); }
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
))
|
||||
|
||||
// mainProcess > renderProcess ipc shorthand
|
||||
|
||||
ipc.send = function(name,data) {
|
||||
window.webContents.send(name,data)
|
||||
}
|
||||
|
||||
|
||||
// ipc bindings
|
||||
|
||||
var bindCallbacks = function(callbacks) {
|
||||
|
||||
var bindCallback = function(i) {
|
||||
ipc.on(i,function(event,data){
|
||||
callbacks[i](data)
|
||||
})
|
||||
}
|
||||
|
||||
for (i in callbacks) {
|
||||
bindCallback(i)
|
||||
}
|
||||
|
||||
ipc.on('ready',function(){
|
||||
window.show()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
ipc:ipc,
|
||||
bindCallbacks:bindCallbacks
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
module.exports = function(settings) {
|
||||
|
||||
// Headless (noGui) mode
|
||||
|
||||
var express = require('express')(),
|
||||
path = require('path'),
|
||||
http = require('http'),
|
||||
server = http.createServer(express),
|
||||
io = require('socket.io')(),
|
||||
ioWildcard = require('socketio-wildcard')(),
|
||||
browserify = require('browserify'),
|
||||
ipc = {}
|
||||
|
||||
express.get('/', function(req, res){
|
||||
res.sendFile(path.resolve(__dirname + '/../browser/index-headless.html'))
|
||||
})
|
||||
express.get('*browser-headless.js', function(req, res){
|
||||
browserify().add(path.resolve(__dirname + '/../browser' + req.path)).bundle().pipe(res);
|
||||
})
|
||||
express.get('*', function(req, res){
|
||||
res.sendFile(path.resolve(__dirname + '/../browser' + req.path))
|
||||
})
|
||||
|
||||
|
||||
io.use(ioWildcard)
|
||||
|
||||
|
||||
io.listen(server);
|
||||
|
||||
server.listen(settings.noGui)
|
||||
|
||||
ipc.send = function(name,data,clientId) {
|
||||
if (clientId) {
|
||||
io.to(clientId).emit(name,data)
|
||||
} else {
|
||||
io.emit(name,data)
|
||||
}
|
||||
}
|
||||
|
||||
var bindCallbacks = function(callbacks) {
|
||||
io.on('connection', function(socket) {
|
||||
socket.on('*', function(e){
|
||||
var name = e.data[0],
|
||||
data = e.data[1]
|
||||
if (callbacks[name]) callbacks[name](data,socket.id)
|
||||
if (name=='sendOsc' && data.sync!==false) {
|
||||
// synchronize all other connected clients
|
||||
socket.broadcast.emit('receiveOsc',data)
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
console.log('Headless mode: app available at http://127.0.0.1:'+settings.noGui)
|
||||
|
||||
return {
|
||||
ipc:ipc,
|
||||
bindCallbacks:bindCallbacks
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
// This prevents argv parsing to be breaked when the app is packaged (executed without 'electron' prefix)
|
||||
if (process.argv[1]&&process.argv[1].indexOf('-')==0) process.argv.unshift('')
|
||||
|
||||
var argv = require('yargs')
|
||||
.help('help').usage(`\nUsage:\n $0 [options]`).alias('h', 'help')
|
||||
.options({
|
||||
's':{alias:'sync',type:'array',describe:'synchronized hosts (ip:port pairs)'},
|
||||
'c':{alias:'compile',type:'string',describe:'recompile stylesheets (increases startup time)'},
|
||||
'l':{alias:'load',type:'string',describe:'session file to load'},
|
||||
'p':{alias:'port',describe:'osc input port (for synchronization)'},
|
||||
'n':{alias:'nogui',describe:'disable default gui and makes the app availabe through http on specified port'},
|
||||
})
|
||||
.check(function(a,x){if(a.port==undefined || !isNaN(a.p)&&a.p>1023&&parseInt(a.p)===a.p){return true}else{throw 'Error: Port must be an integer >= 1024'}})
|
||||
.check(function(a,x){if(a.n==undefined || !isNaN(a.n)&&a.n>1023&&parseInt(a.n)===a.n){return true}else{throw 'Error: Port must be an integer >= 1024'}})
|
||||
.check(function(a,x){if(a.sync==undefined || a.s.join(' ').match('^([^:\s]*:[0-9]{4,5}[\s]*)*$')!=null){return true}else{throw 'Error: Sync hosts must be ip:port pairs & port must be >= 1024'}})
|
||||
.strict()
|
||||
.argv
|
||||
|
||||
module.exports = function(fs) {
|
||||
return {
|
||||
presetPath : process.cwd(),
|
||||
sessionPath: process.cwd(),
|
||||
recentSessions: [],
|
||||
|
||||
appName: 'OSC Controller',
|
||||
syncTargets: argv.s || false,
|
||||
oscInPort: argv.p || false,
|
||||
compileScss: argv.c!==undefined || false,
|
||||
lightTheme: argv.c && argv.c.match(/light/),
|
||||
sessionFile: argv.l || false,
|
||||
noGui: argv.n || false,
|
||||
|
||||
|
||||
persistent: function(){var c = {};try {c=require( __dirname + '/config.json')} finally {return c}}(),
|
||||
|
||||
read:function(key){
|
||||
var x = this.persistent[key] || this[key]
|
||||
return x
|
||||
},
|
||||
write:function(key,value) {
|
||||
this.persistent[key] = value
|
||||
fs.writeFile(__dirname + '/config.json',JSON.stringify(this.persistent,null,4), function (err, data) {
|
||||
if (err) throw err
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue