From 42b481ea60711c7750cdc50d402ba5229bdeb85c Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Wed, 18 Nov 2015 21:00:09 -0800 Subject: [PATCH] Clean up nodejs code to use modules --- app/html/css/fontello/font/elodie.eot | Bin 7028 -> 7248 bytes app/html/css/fontello/font/elodie.ttf | Bin 6868 -> 7088 bytes app/html/css/fontello/font/elodie.woff | Bin 4308 -> 4428 bytes app/index.js | 202 ++----------------------- app/modules/broadcast.js | 106 +++++++++++++ app/modules/toolbar-ui.js | 87 +++++++++++ 6 files changed, 207 insertions(+), 188 deletions(-) create mode 100644 app/modules/broadcast.js create mode 100644 app/modules/toolbar-ui.js diff --git a/app/html/css/fontello/font/elodie.eot b/app/html/css/fontello/font/elodie.eot index f0fd15cb804ab68633bc656df6dd00126b8c0dec..2139a8ae2c57b65a5ff5891211aac7edbd449ca7 100644 GIT binary patch delta 585 zcmY+8L1+_E5Qb;=rP)pQWp@oiYtz;giV>uxh$aQ4DhL)))PrIRD(kvULbK_b#HGbU zFB*C(Tehd1?6p`3gwP&5iFjUe62wa>OArqQYY#=MBQaneZ{ED`pEvWrgOooRzB>p| zi?4-KA!of=UAtOZz61c@C>|J=Zu>*0wgK=u#ZAL0CrGEI?$FUYXJ@Px*PS8$03h2L zy=0TF5!Wb7nf%h+>D{;kAh?8kSyO)|ol&3C+cMQtSrWug><#f-;?b;CUOYeln64oE zbWG+K3_Z50%>ra1va09e737|e*O1p^!kx&n0Ps7Q2>&gzmiJX2 z zYiSXwp`p1UL>d~ZAsQOmN@$4amoA)h?)U%qoO^F${LAzfdWjw)Rj=u3rOJtFJbyS! zL?4L7v}5T;Z}^Ic6NuULUZEd4R`3bQ$m*O^s#KQ2??eHev+^2xH~0b7pWE8cUWSSr zM4|$W*%@oY_j_TW^%lNqL-0MyGw?Tf$aV_Fk<&G7DG)`9ZSAD3U{nRcbKr<$6*Zl! z5ZDIyZ(C00?R8}sT*4)Fy^}8-PpsGRfH?fB-p%OeO?iaYCGY{UEV~t+V#96lG#j;$ znC~29ScpV9)k<|uwkRO+8=~gg%-w(OJ8{R=7%Nw+*g#vNRW^B>Z$v~S#kKg6wrqNO mptnb<+P(S|VFeN_*~1;|Wgq*wlMN1F%1hUR#JO6sTc|&o$5!S5 diff --git a/app/html/css/fontello/font/elodie.ttf b/app/html/css/fontello/font/elodie.ttf index 4a1f99d453d69a7d8221eef396714257ff23c609..ee28a12610c59e9fbd59cbdcf18203eb5cb2aa2a 100644 GIT binary patch delta 599 zcmca&y1~4jfsuiMfsdhqftew}KUm+$PSevGDDnn~!;*6o3ogh?Zf9U%bOBQ47|46!wfq`iPkozPf zH8F)ljXw#fwgf0|mXVQKpU8fLc>z#h4NyQOBe$f&C>zLP;JyGPEOPRb6NUN&q8J!> zIDmY)+{B6khE+U5K)wc$uaK9RoBHHYlsb^_0kmXmL4I*b>g}z+fDQmkGi)d*N-emX z&D_esAZ-HVS2Hj&&tjawz{IhDAF_WpCKd9WCKP=MxM<@jQ*VUObiVFGnrp7 z2Qu(5NHB1073Ae)X42JW6yal3&|?&^V^ol1WHeVdS7%pe7iSkYXMWN4?B9oHZEepO z1)jD2TkF1XAq+9bcEH4eY9_#hf$~6`k?j!x+QSdACj!MHRz*`qR15w*WAgpG8O7v7 zW#Bjj#^bC@Q_AA`ZN4&aGrs^@!EmYY*Ea}#;n?IST;_~?lV!LK*g%rZFD83&%kZ%H zuoMARfYZR{Jnqj-vV1@u6C*Pt3nMEd8zVa-2O}pV7b7<#4Q5&PN*Vj9v=Sw==`eIok}=6OJYA3y<>jNFn6t=T{p1Gfy2Fv!VIPUMr};REu0 zfPAUk#EJrj6+A*feg=@Qke8U7`s7iRI*{K1v}9{ResM{^b<$R#0~~000iC0000U0000U5{?jBZDDwD000ii z0000W0000W0ICcUZeeX@000i?0004i0008D-=ic3!o!Q;_ z@y?HbXJ>Z3GmbajwRdKBlR8=3apP9oIB`~yNW;c$lTyVX3Z+t95k&%3aT5VeRYZ$Y zOVs@lNL4{#p*{lT0h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'; - } - if(args['album'].length > 0) { - update_command += ' --album="' + args['album'] + '"'; - } - if(args['datetime'].length > 0) { - update_command += ' --time="' + args['datetime'] + '"'; - } - if(args['title'].length > 0) { - update_command += ' --title="' + args['title'] + '"'; - } - - update_command += ' "' + files.join('" "') + '"' - - 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-photos-success', params); - }); -}); - -ipc.on('launch-finder', function(event, path) { - console.log(path); - var shell = require('shell'); - shell.showItemInFolder(path); -}); - -ipc.on('program-quit', function(event, path) { - console.log('program-quit'); - //mb.tray.destroy(); - mb.quit(); -}); - -var mb = menubar( - { - preloadWindow: true, - dir: __dirname + '/html', - index: 'index.html', - pages: { - 'blank': 'blank.html', - 'location': 'location.html' - }, - width: 400, - height: 500, - 'window-position': 'trayCenter' - } - ); - -mb.on('ready', function ready () { - console.log('app is ready') - 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)); - - this.tray.setToolTip('Drag and drop files here') - this.tray.setImage(mb.getOption('dir') + '/img/logo@18x22xbw.png') - this.tray.on('clicked', function clicked () { - console.log('tray-clicked') - }) - this.tray.on('drop-files', function dropFiles (ev, files) { - loadUrl = mb.getOption('pages')['location']; - mb.showWindow(); - //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 () { -}) - -var loaded = false; -mb.on('show', function show () { - if(loadUrl === null) { - loadUrl = this.getOption('index'); - } - this.window.loadUrl('file://' + this.getOption('dir') + '/' + loadUrl); - loadUrl = null; - //mb.window.openDevTools(); -}) - -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') - this.window.loadUrl('file://' + this.getOption('dir') + '/' + this.getOption('pages')['blank']); -}) +ipc.on('import-photos', broadcast.importPhotos); +ipc.on('update-photos', broadcast.updatePhotos); +ipc.on('launch-finder', broadcast.launchFinder); +ipc.on('program-quit', broadcast.programQuit); diff --git a/app/modules/broadcast.js b/app/modules/broadcast.js new file mode 100644 index 0000000..b067ac3 --- /dev/null +++ b/app/modules/broadcast.js @@ -0,0 +1,106 @@ +var exports = module.exports = {}; + +var exec = require('child_process').exec; + +// The main process listens for events from the web renderer. +// 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. + +exports.importPhotos = 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'); + event.sender.send('update-import-no-photos', null); + 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); + }); +}; + + +// 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. +exports.updatePhotos = function(event, args) { + var params = args, + normalize; + + console.log('update-photos'); + console.log(args); + if(typeof(args['files']) === 'undefined' || args['files'].length === 0) { + console.log('no files passed in to update-photos'); + return; + } + + normalize = function(files) { + for(var i=0; i 0) { + update_command += ' --location="' + args['location'] + '"'; + } + if(args['album'].length > 0) { + update_command += ' --album="' + args['album'] + '"'; + } + if(args['datetime'].length > 0) { + update_command += ' --time="' + args['datetime'] + '"'; + } + if(args['title'].length > 0) { + update_command += ' --title="' + args['title'] + '"'; + } + + update_command += ' "' + files.join('" "') + '"' + + 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-photos-success', params); + }); +}; + +exports.launchFinder = function(event, path) { + console.log(path); + var shell = require('shell'); + shell.showItemInFolder(path); +}; + +exports.programQuit = function(event, path) { + console.log('program-quit'); + //mb.tray.destroy(); + mb.quit(); +}; diff --git a/app/modules/toolbar-ui.js b/app/modules/toolbar-ui.js new file mode 100644 index 0000000..45adea5 --- /dev/null +++ b/app/modules/toolbar-ui.js @@ -0,0 +1,87 @@ +var exports = module.exports = {}; + +var menubar = require('menubar'), + menu = require('menu'), + tray = require('tray'), + loadUrl = null; + +exports.app = app = menubar( + { + preloadWindow: true, + dir: __dirname.substr(0, __dirname.lastIndexOf('/')) + '/html', + index: 'index.html', + pages: { + 'blank': 'blank.html', + 'location': 'location.html' + }, + width: 400, + height: 500, + 'window-position': 'trayCenter' + } +); + +exports.ready = function() { + console.log('app is ready') + 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)); + + this.tray.setToolTip('Drag and drop files here'); + console.log(app.getOption('dir')); + this.tray.setImage(app.getOption('dir') + '/img/logo@18x22xbw.png'); + this.tray.on('clicked', function clicked () { + console.log('tray-clicked') + }); + this.tray.on('drop-files', function dropFiles (ev, files) { + loadUrl = app.getOption('pages')['location']; + app.showWindow(); + //app.window.openDevTools(); + app.window.webContents.on('did-finish-load', function() { + app.window.webContents.send('files', files); + app.window.webContents.send('preview', files); + }); + }); +}; + +exports.createWindow = function() { + console.log('create-window') +}; + +exports.afterCreateWindow = function() { + console.log('after-create-window') +}; + +exports.show = function() { + if(loadUrl === null) { + loadUrl = this.getOption('index'); + } + this.window.loadUrl('file://' + this.getOption('dir') + '/' + loadUrl); + loadUrl = null; + //app.window.openDevTools(); +}; + +exports.afterShow = function() { + console.log('after-show'); +}; + +exports.hide = function() { + console.log('hide'); +}; + +exports.afterHide = function() { + console.log('after-hide') + this.window.loadUrl('file://' + this.getOption('dir') + '/' + this.getOption('pages')['blank']); +};