61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
//first add the robot's global module search path to the global paths
|
|
require('module').globalPaths.push('/usr/lib/node_modules/');
|
|
|
|
const spawn = require('child_process').spawn;
|
|
const ipcRenderer = require('electron').ipcRenderer;
|
|
const path = require('path');
|
|
const GetConfig = require('../lib/skills-service-manager').default.GetConfig;
|
|
const StartupView = require('./startup-view');
|
|
const view = new StartupView();
|
|
|
|
function postSemaphore() {
|
|
ipcRenderer.once('set-pid', function(sender, pid) {
|
|
const child = spawn('node', [path.join(__dirname, 'semaphore.js'), pid], {
|
|
env: {
|
|
NODE_PATH: '/usr/lib/node_modules/'
|
|
}
|
|
});
|
|
function onData(data) {
|
|
console.info(data.toString());
|
|
}
|
|
child.stdout.on('data', onData);
|
|
child.stderr.on('data', onData);
|
|
child.on('exit', function(code) {
|
|
console.log('semaphore exited with code', code);
|
|
});
|
|
});
|
|
ipcRenderer.send('get-pid');
|
|
}
|
|
|
|
const getter = new GetConfig();
|
|
getter.getConfig(function(error, configPath, mode) {
|
|
view.mode = mode;
|
|
if (error) {
|
|
postSemaphore();
|
|
view.complete(error);
|
|
return console.error('Could not get config path: ', error);
|
|
}
|
|
try {
|
|
const config = require(configPath);
|
|
const Factory = require('../lib/skills-service-manager').default.Factory;
|
|
const factory = new Factory(config, path.join(__dirname, '..'), mode);
|
|
factory.init(function(error) {
|
|
if (error) {
|
|
view.complete(error);
|
|
console.error('Factory initialization failed:', error);
|
|
}
|
|
else {
|
|
view.complete();
|
|
}
|
|
postSemaphore();
|
|
});
|
|
}
|
|
catch(error) {
|
|
view.complete(error);
|
|
console.error('Error. Maybe in identified mode?', error);
|
|
postSemaphore();
|
|
}
|
|
|
|
}); |