- session file format modifier : json or self-invoking function

- session history handling modified, session opening function moved to utils
This commit is contained in:
jean-emmanuel 2015-09-17 18:06:50 +02:00 • committed by bordun
parent 60967e0e89
commit 84e7303bb7
10 changed files with 143 additions and 131 deletions

View file

@ -28,31 +28,23 @@ ipc.on('listSessions',function(data){
</div>')
for (i in data) {
$('#lobby .list').append('<li><a class="btn" data-session="'+i+'">'+data[i]+'<span>'+icon('remove')+'</span></a></li>')
$('#lobby .list').append('<li><a class="btn load" data-session="'+data[i]+'">'+data[i]+'<span>'+icon('remove')+'</span></a></li>')
}
$('#lobby .list').append('<a class="btn" data-session="browse">...</a>')
$('#lobby a').click(function(){
ipc.send('loadSession',$(this).data('session'))
$('#lobby .list').append('<a class="btn browse">...</a>')
$('#lobby .load').click(function(e){
e.stopPropagation()
openSession($(this).data('session'))
})
$('#lobby a span').click(function(e){
e.stopPropagation()
ipc.send('removeSessionFromHistory',$(this).parent().data('session'))
$(this).parents('li').hide()
})
$('#lobby .browse').click(function(e){
e.stopPropagation()
ipc.send('browseSessions')
})
})
ipc.on('openSession',function(data){
TABS=false
require(data)
if (TABS!=false) {
$('#lobby').hide()
$('#container').append('<div id="loading"><div class="spinner"></div></div>')
setTimeout(function(){
init(function(){$('#loading').hide()});
},1)
} else {
console.log('ERROR: invalid session file (TABS must be defined)')
}
openSession(data)
})

View file

@ -1,8 +1,8 @@
init = function(callback) {
init = function(session,callback) {
parsetabs(TABS,false,false)
parsetabs(session,false,false)

View file

@ -39,6 +39,38 @@ setState = function(preset){
}
openSession = function(path){
var fs = require('fs'),
data = fs.readFileSync(path,'utf8'),
session,
error
try {
session = eval(data)
} catch(err) {
error = err
}
if (!error) {
ipc.send('addSessionToHistory',path)
$('#lobby').hide()
$('#container').append('<div id="loading"><div class="spinner"></div></div>')
setTimeout(function(){
init(session,function(){$('#loading').hide()});
},1)
} else {
createPopup(icon('warning')+'&nbsp;Error: invalid session file',error)
}
}
icon = function(i) {
return '<i class="fa fa-fw fa-'+i+'"></i>'
}

View file

@ -14,19 +14,6 @@ var app = require('app')
compileScss = function(){
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 content = fs.readFileSync(file,'utf8')
sass.compile(content,{style: sass.style.compact,linefeed: ''}, function(result) {
fs.writeFileSync(__dirname + '/../browser/css/'+filenames[i].replace('.scss','.css'),result.text,'utf8')
});
}
}
dialog.showErrorBox = function(title,err) {
console.log(title + ': ' + err)
@ -85,40 +72,44 @@ restartApp = function(){
}
compileScss = function(){
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 content = fs.readFileSync(file,'utf8')
sass.compile(content,{style: sass.style.compact,linefeed: ''}, function(result) {
fs.writeFileSync(__dirname + '/../browser/css/'+filenames[i].replace('.scss','.css'),result.text,'utf8')
});
}
}
var window = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform != 'darwin') {
app.quit();
}
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
if (args.indexOf('-c')!=-1) {
compileScss()
}
// Create the browser window.
window = new BrowserWindow({
width: 810,
width: 800,
height: 600,
'auto-hide-menu-bar':true
});
// and load the index.html of the app.
window.loadUrl('file://' + __dirname + '/../browser/index.html');
// Emitted when the window is closed.
window.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
window = null;
});
@ -171,48 +162,24 @@ renderProcess = {
}
}
ipc.on('loadSession',function(event, data){
ipc.on('browseSessions',function(event, data){
var sessionlist = readConfig('recentSessions')
if (data == 'browse') {
dialog.showOpenDialog(window,{title:'Load session file',defaultPath:readConfig('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
if (file==undefined) {return}
// save path to configfile
writeConfig({sessionPath:file[0].replace(file[0].split('/').pop(),'')})
// open session
renderProcess.send('openSession',file[0]);
// add session to history
sessionlist.unshift(file[0])
// remove doubles from history
sessionlist = sessionlist.filter(function(elem, index, self) {
return index == self.indexOf(elem);
})
// save history
writeConfig({recentSessions:sessionlist})
renderProcess.send('openSession',file[0])
})
})
} else {
// open session
renderProcess.send('openSession',sessionlist[data]);
// add session to history
sessionlist.unshift(sessionlist[data])
// remove doubles from history
sessionlist = sessionlist.filter(function(elem, index, self) {
return index == self.indexOf(elem);
})
// save history
writeConfig({recentSessions:sessionlist})
}
ipc.on('addSessionToHistory',function(event, data){
var sessionlist = readConfig('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
writeConfig({recentSessions:sessionlist})
})
ipc.on('removeSessionFromHistory',function(event, data){
@ -254,15 +221,6 @@ ipc.on('sendOsc', function (event,data) {
});
}
// try {
// udpPort.send({
// address: data.path,
// args: data.args
// }, host, port);
// } catch(err) {
// console.log(err)
// }
}
@ -299,5 +257,4 @@ ipc.on('load', function(event, data){
ipc.on('fullscreen', function(event){
window.setFullScreen(!window.isFullScreen())
})