Passed
Push — master ( 9ddb09...7fc5b5 )
by Jaisen
01:14
created

app/modules/broadcast.js (2 issues)

1
var exports = module.exports = {};
2
var path = require('path');
3
var exec = require('child_process').exec,
4
    config = require('./config.js');
5
6
// The main process listens for events from the web renderer.
7
// When photos are dragged onto the toolbar and photos are requested to be updated it will fire an 'update-photos' ipc event.
8
// The web renderer will send the list of photos, type of update and new value to apply
9
// Once this main process completes the update it will send a 'update-photos-completed' event back to the renderer with information
10
//  so a proper response can be displayed.
11
12
exports.importPhotos = function(event, args) {
13
  var params = args,
14
      normalize;
15
16
  console.log('import-photos');
17
  console.log(args);
18
  if(typeof(args['source']) === 'undefined' || args['source'].length === 0 || typeof(args['destination']) === 'undefined' || args['destination'].length === 0) {
19
    console.log('no source or destination passed in to import-photos');
20
    event.sender.send('update-import-no-photos', null);
21
    return;
22
  }
23
24
  args['source'] = args['source'].normalize();
25
  args['destination'] = args['destination'].normalize();
26
27
  update_command = path.normalize(__dirname + '/../../dist/elodie/elodie') + ' import --source="' + args['source'] +  '" --destination="' + args['destination'] + '"';
0 ignored issues
show
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
28
  //update_command = __dirname + '/../../elodie.py import --source="' + args['source'] +  '" --destination="' + args['destination'] + '"';
29
  
30
  console.log(update_command);
31
  exec(update_command, function(error, stdout, stderr) {
32
    console.log('out ' + stdout);
33
    console.log('err ' + stderr);
34
    /*params['error'] = error
35
    params['stdout'] = '[' + stdout.replace(/\n/g,',').replace(/\,+$/g, '').replace(/\n/g,'') + ']'
36
    params['stderr'] = stderr
37
    console.log('parsed')
38
    console.log(params['stdout'])*/
39
    event.sender.send('update-import-success', args);
40
  });
41
};
42
43
exports.updateConfig = function(event, args) {
44
  var params = args,
45
      status;
46
  status = config.writeConfig(params);
47
  if(status) {
48
    event.sender.send('update-config-status', true);
49
  } else {
50
    event.sender.send('update-config-status', false);
51
  }
52
};
53
54
// When photos are dragged onto the toolbar and photos are requested to be updated it will fire an 'update-photos' ipc event.
55
// The web renderer will send the list of photos, type of update and new value to apply
56
// Once this main process completes the update it will send a 'update-photos-completed' event back to the renderer with information
57
//  so a proper response can be displayed.
58
exports.updatePhotos = function(event, args) {
59
  var params = args,
60
      normalize;
61
62
  console.log('update-photos');
63
  console.log(args);
64
  if(typeof(args['files']) === 'undefined' || args['files'].length === 0) {
65
    console.log('no files passed in to update-photos');
66
    return;
67
  }
68
69
  normalize = function(files) {
70
    for(var i=0; i<files.length; i++) {
71
      files[i] = files[i].normalize()
72
    }
73
    return files
74
  }
75
  files = normalize(args['files'])
76
  elodie_path = path.normalize(__dirname + '/../../dist/elodie/elodie');
0 ignored issues
show
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
77
  update_command = elodie_path +' update'
78
  //update_command = __dirname + '/../../elodie.py update'
79
  if(args['location'].length > 0) {
80
    update_command += ' --location="' + args['location'] + '"';
81
  }
82
  if(args['album'].length > 0) {
83
    update_command += ' --album="' + args['album'] + '"';
84
  }
85
  if(args['datetime'].length > 0) {
86
    update_command += ' --time="' + args['datetime'] + '"';
87
  }
88
  if(args['title'].length > 0) {
89
    update_command += ' --title="' + args['title'] + '"';
90
  }
91
92
  update_command += ' "' + files.join('" "') + '"'
93
  
94
  console.log(update_command)
95
  exec(update_command, function(error, stdout, stderr) {
96
    console.log('out ' + stdout)
97
    console.log('err ' + stderr)
98
    params['error'] = error
99
    params['stdout'] = '[' + stdout.replace(/\n/g,',').replace(/\,+$/g, '').replace(/\n/g,'') + ']'
100
    params['stderr'] = stderr
101
    console.log('parsed')
102
    console.log(params['stdout'])
103
    event.sender.send('update-photos-success', params);
104
  });
105
};
106
107
exports.launchFinder = function(event, path) {
108
  console.log(path);
109
  var shell = require('shell');
110
  shell.showItemInFolder(path);
111
};
112
113
exports.launchUrl = function(event, url) {
114
  console.log(url);
115
  var shell = require('shell');
116
  shell.openExternal(url);
117
};
118
119
exports.programQuit = function(event, path) {
120
  console.log('program-quit');
121
  //mb.tray.destroy();
122
  mb.quit();
123
};
124