2015-10-26 10:08:01 +01:00
|
|
|
var menubar = require('menubar'),
|
2015-11-18 10:37:46 +01:00
|
|
|
menu = require("menu"),
|
2015-10-26 10:08:01 +01:00
|
|
|
tray = require('tray'),
|
|
|
|
ipc = require('ipc'),
|
2015-11-18 10:37:46 +01:00
|
|
|
exec = require('child_process').exec,
|
|
|
|
loadUrl = null;
|
2015-10-26 10:08:01 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The main process listens for events from the web renderer.
|
|
|
|
*/
|
|
|
|
|
2015-11-03 10:38:53 +01:00
|
|
|
// When photos are dragged onto the toolbar and photos are requested to be updated it will fire an 'update-photos' ipc event.
|
|
|
|
// The web renderer will send the list of photos, type of update and new value to apply
|
|
|
|
// Once this main process completes the update it will send a 'update-photos-completed' event back to the renderer with information
|
|
|
|
// so a proper response can be displayed.
|
|
|
|
ipc.on('import-photos', function(event, args) {
|
|
|
|
var params = args,
|
|
|
|
normalize;
|
|
|
|
|
|
|
|
console.log('import-photos');
|
|
|
|
console.log(args);
|
|
|
|
if(typeof(args['source']) === 'undefined' || args['source'].length === 0 || typeof(args['destination']) === 'undefined' || args['destination'].length === 0) {
|
|
|
|
console.log('no source or destination passed in to import-photos');
|
2015-11-18 10:37:46 +01:00
|
|
|
event.sender.send('update-import-no-photos', null);
|
2015-11-03 10:38:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
args['source'] = args['source'].normalize();
|
|
|
|
args['destination'] = args['destination'].normalize();
|
|
|
|
|
|
|
|
update_command = __dirname + '/../dist/elodie/elodie import --source="' + args['source'] + '" --destination="' + args['destination'] + '"';
|
|
|
|
//update_command = __dirname + '/../elodie.py import --source="' + args['source'] + '" --destination="' + args['destination'] + '"';
|
|
|
|
|
|
|
|
console.log(update_command)
|
|
|
|
exec(update_command, function(error, stdout, stderr) {
|
|
|
|
console.log('out ' + stdout)
|
|
|
|
console.log('err ' + stderr)
|
|
|
|
/*params['error'] = error
|
|
|
|
params['stdout'] = '[' + stdout.replace(/\n/g,',').replace(/\,+$/g, '').replace(/\n/g,'') + ']'
|
|
|
|
params['stderr'] = stderr
|
|
|
|
console.log('parsed')
|
|
|
|
console.log(params['stdout'])*/
|
|
|
|
event.sender.send('update-import-success', args);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-10-26 10:08:01 +01:00
|
|
|
// When photos are dragged onto the toolbar and photos are requested to be updated it will fire an 'update-photos' ipc event.
|
|
|
|
// The web renderer will send the list of photos, type of update and new value to apply
|
|
|
|
// Once this main process completes the update it will send a 'update-photos-completed' event back to the renderer with information
|
|
|
|
// so a proper response can be displayed.
|
|
|
|
ipc.on('update-photos', function(event, args) {
|
2015-10-28 09:38:45 +01:00
|
|
|
var params = args,
|
2015-11-03 10:38:53 +01:00
|
|
|
normalize;
|
2015-10-28 09:38:45 +01:00
|
|
|
|
2015-11-03 10:38:53 +01:00
|
|
|
console.log('update-photos');
|
|
|
|
console.log(args);
|
2015-10-26 10:08:01 +01:00
|
|
|
if(typeof(args['files']) === 'undefined' || args['files'].length === 0) {
|
|
|
|
console.log('no files passed in to update-photos');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-28 09:38:45 +01:00
|
|
|
normalize = function(files) {
|
|
|
|
for(var i=0; i<files.length; i++) {
|
|
|
|
files[i] = files[i].normalize()
|
|
|
|
}
|
|
|
|
return files
|
|
|
|
}
|
|
|
|
files = normalize(args['files'])
|
|
|
|
|
2015-11-02 11:11:53 +01:00
|
|
|
update_command = __dirname + '/../dist/elodie/elodie update'
|
|
|
|
//update_command = __dirname + '/../elodie.py update'
|
2015-11-03 10:38:53 +01:00
|
|
|
if(args['location'].length > 0) {
|
|
|
|
update_command += ' --location="' + args['location'] + '"';
|
|
|
|
}
|
|
|
|
if(args['album'].length > 0) {
|
|
|
|
update_command += ' --album="' + args['album'] + '"';
|
2015-10-26 10:08:01 +01:00
|
|
|
}
|
2015-11-03 10:38:53 +01:00
|
|
|
if(args['datetime'].length > 0) {
|
|
|
|
update_command += ' --time="' + args['datetime'] + '"';
|
|
|
|
}
|
|
|
|
if(args['title'].length > 0) {
|
|
|
|
update_command += ' --title="' + args['title'] + '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
update_command += ' "' + files.join('" "') + '"'
|
2015-10-26 10:08:01 +01:00
|
|
|
|
2015-10-28 09:38:45 +01:00
|
|
|
console.log(update_command)
|
|
|
|
exec(update_command, function(error, stdout, stderr) {
|
|
|
|
console.log('out ' + stdout)
|
|
|
|
console.log('err ' + stderr)
|
|
|
|
params['error'] = error
|
2015-11-03 10:38:53 +01:00
|
|
|
params['stdout'] = '[' + stdout.replace(/\n/g,',').replace(/\,+$/g, '').replace(/\n/g,'') + ']'
|
2015-10-28 09:38:45 +01:00
|
|
|
params['stderr'] = stderr
|
|
|
|
console.log('parsed')
|
|
|
|
console.log(params['stdout'])
|
|
|
|
event.sender.send('update-photos-success', params);
|
|
|
|
});
|
2015-11-03 10:38:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('launch-finder', function(event, path) {
|
|
|
|
console.log(path);
|
|
|
|
var shell = require('shell');
|
|
|
|
shell.showItemInFolder(path);
|
|
|
|
});
|
2015-10-26 10:08:01 +01:00
|
|
|
|
2015-11-18 10:37:46 +01:00
|
|
|
ipc.on('program-quit', function(event, path) {
|
|
|
|
console.log('program-quit');
|
|
|
|
//mb.tray.destroy();
|
|
|
|
mb.quit();
|
|
|
|
});
|
|
|
|
|
2015-10-26 10:08:01 +01:00
|
|
|
var mb = menubar(
|
|
|
|
{
|
|
|
|
preloadWindow: true,
|
2015-11-02 11:11:53 +01:00
|
|
|
dir: __dirname + '/html',
|
2015-11-03 10:38:53 +01:00
|
|
|
index: 'index.html',
|
2015-10-26 10:08:01 +01:00
|
|
|
pages: {
|
2015-11-18 10:37:46 +01:00
|
|
|
'blank': 'blank.html',
|
2015-10-26 10:08:01 +01:00
|
|
|
'location': 'location.html'
|
|
|
|
},
|
|
|
|
width: 400,
|
2015-11-18 10:37:46 +01:00
|
|
|
height: 500,
|
|
|
|
'window-position': 'trayCenter'
|
2015-10-26 10:08:01 +01:00
|
|
|
}
|
2015-11-18 10:37:46 +01:00
|
|
|
);
|
2015-10-26 10:08:01 +01:00
|
|
|
|
|
|
|
mb.on('ready', function ready () {
|
|
|
|
console.log('app is ready')
|
2015-11-18 10:37:46 +01:00
|
|
|
var template = [{
|
|
|
|
label: "Application",
|
|
|
|
submenu: [
|
|
|
|
{ label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }}
|
|
|
|
]}, {
|
|
|
|
label: "Edit",
|
|
|
|
submenu: [
|
|
|
|
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
|
|
|
|
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
|
|
|
|
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
|
|
|
|
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
|
|
|
|
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
|
|
|
|
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
|
|
|
|
]}
|
|
|
|
];
|
|
|
|
menu.setApplicationMenu(menu.buildFromTemplate(template));
|
|
|
|
|
2015-10-26 10:08:01 +01:00
|
|
|
this.tray.setToolTip('Drag and drop files here')
|
2015-11-18 10:37:46 +01:00
|
|
|
this.tray.setImage(mb.getOption('dir') + '/img/logo@18x22xbw.png')
|
2015-10-26 10:08:01 +01:00
|
|
|
this.tray.on('clicked', function clicked () {
|
|
|
|
console.log('tray-clicked')
|
|
|
|
})
|
|
|
|
this.tray.on('drop-files', function dropFiles (ev, files) {
|
2015-11-18 10:37:46 +01:00
|
|
|
loadUrl = mb.getOption('pages')['location'];
|
|
|
|
mb.showWindow();
|
2015-10-26 10:08:01 +01:00
|
|
|
//mb.window.openDevTools();
|
|
|
|
mb.window.webContents.on('did-finish-load', function() {
|
|
|
|
mb.window.webContents.send('files', files);
|
|
|
|
mb.window.webContents.send('preview', files);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
mb.on('create-window', function createWindow () {
|
|
|
|
console.log('create-window')
|
|
|
|
})
|
|
|
|
|
|
|
|
mb.on('after-create-window', function afterCreateWindow () {
|
|
|
|
})
|
|
|
|
|
2015-11-18 10:37:46 +01:00
|
|
|
var loaded = false;
|
2015-10-26 10:08:01 +01:00
|
|
|
mb.on('show', function show () {
|
2015-11-18 10:37:46 +01:00
|
|
|
if(loadUrl === null) {
|
|
|
|
loadUrl = this.getOption('index');
|
|
|
|
}
|
|
|
|
this.window.loadUrl('file://' + this.getOption('dir') + '/' + loadUrl);
|
|
|
|
loadUrl = null;
|
|
|
|
//mb.window.openDevTools();
|
2015-10-26 10:08:01 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
mb.on('after-show', function afterShow () {
|
|
|
|
console.log('after-show')
|
|
|
|
})
|
|
|
|
|
|
|
|
mb.on('hide', function hide () {
|
|
|
|
console.log('hide')
|
|
|
|
})
|
|
|
|
|
|
|
|
mb.on('after-hide', function afterHide () {
|
|
|
|
console.log('after-hide')
|
2015-11-18 10:37:46 +01:00
|
|
|
this.window.loadUrl('file://' + this.getOption('dir') + '/' + this.getOption('pages')['blank']);
|
2015-10-26 10:08:01 +01:00
|
|
|
})
|