More refactor on bootstrapping

This commit is contained in:
140b8f67-ec51-4b64-9606-bff2dffa0170 2016-03-28 22:43:10 -07:00
parent 6567b2b018
commit 239f34983c
3 changed files with 75 additions and 55 deletions

View file

@ -117,8 +117,9 @@ var buildJsonVersion = function(output, destination, name, attributes) {
var appDrivePathOutput = output + 'appdrive/',
systemPathOutput = appDrivePathOutput + 'system/',
frameworkPathInput = input + 'framework/',
frameworkPathOutput = systemPathOutput,
frameworkPathOutput = systemPathOutput + 'framework/',
customPathInput = input + 'custom/',
customPathOutput = systemPathOutput + 'custom/',
appsPathInput = 'apps/',
appsPathOutput = appDrivePathOutput + 'apps/';
@ -184,7 +185,7 @@ gulp.task('appdrive-framework-custom', function() {
return gulp.src(customPathInput + "**/*", {
base: customPathInput
})
.pipe(gulp.dest(frameworkPathOutput));
.pipe(gulp.dest(customPathOutput));
});
/**

View file

@ -65,8 +65,12 @@ const APPLICATION_JS = "app.js";
const APPLICATION_WORKER = "worker.js";
const SYSTEM_PATH = "system/";
const FRAMEWORK_JS = "framework.js";
const FRAMEWORK_CSS = "framework.css";
const SYSTEM_FRAMEWORK_PATH = "framework/";
const SYSTEM_FRAMEWORK_JS = "framework.js";
const SYSTEM_FRAMEWORK_CSS = "framework.css";
const JCI_MOUNT_PATH = "/tmp/mnt/data_persist/appdrive/"; // we link our resources in here
const JCI_MOUNT_CUSTOM_PATH = "custom/";
/**
* This is the CMU that is compiled into the node binary and runs the actual link between the
@ -112,8 +116,6 @@ cmu.prototype = {
*/
__construct: function()
{
this.applications = {};
this.__socket = new _webSocketServer({
port: this.network.port
});
@ -124,6 +126,7 @@ cmu.prototype = {
}.bind(this));
this.findAppDrive();
},
@ -196,11 +199,10 @@ cmu.prototype = {
case REQUEST_APPDRIVE:
// find applications
this.findAppDrive(function(applications, appdrive) {
this.findAppDrive(function(appdrive) {
this.sendFromPayload(client, payload, {
applications: applications,
appdrive: appdrive,
appdrive
});
}.bind(this));
@ -255,42 +257,68 @@ cmu.prototype = {
*/
findAppDrive: function(callback) {
this.applications = {};
this.appdrive = false;
this.framework = false;
this.appdrive = {
locations: {},
applications: {},
js: [],
css: [],
};
var result = [],
mountPoints = ['sd_nav', 'sda', 'sdb', 'sdc', 'sdd', 'sde'];
mountPoints.forEach(function(mountPoint) {
/** framework */
var frameworkPath = [MOUNTROOT_PATH, mountPoint, FRAMEWORK_PATH].join("");
var appDrivePath = [MOUNTROOT_PATH, mountPoint, APPDRIVE_PATH].join(""),
appDriveFilename = [appDrivePath, APPDRIVE_JSON].join("");
appDriveFilename = [appDrivePath, APPDRIVE_JSON].join(""),
applicationsPath = [appDrivePath, APPLICATIONS_PATH].join(""),
if(this._isFile(appDriveFilename)) {
systemPath = [appDrivePath, SYSTEM_PATH].join("");
this.appdrive = require(appDriveFilename);
// check primary conditions
if(this._isFile(appDriveFilename) && this._isDir(systemPath) && this._isDir(applicationsPath)) {
var files = fs.readdirSync(appDrivePath);
/**
* Assign location
*/
if(files.length) files.forEach(function(appId) {
this.appdrive.locations = {
root: appDrivePath,
apps: applicationsPath
};
/**
* Load AppDrive
*/
this.appdrive.package = require(appDriveFilename);
/**
* Load Framework
*/
this.appdrive.js.push([systemPath, SYSTEM_FRAMEWORK_PATH, SYSTEM_FRAMEWORK_JS].join(""));
this.appdrive.css.push([systemPath, SYSTEM_FRAMEWORK_PATH, SYSTEM_FRAMEWORK_CSS].join(""))
/**
* Find Applications
*/
var appFiles = fs.readdirSync(applicationsPath);
if(appFiles.length) appFiles.forEach(function(appId) {
/**
* currently we only allow the first application to be registered
* otherwise you would need to restart the CMU
*/
if(!this.applications[appId]) {
if(!this.appdrive.applications[appId]) {
var applicationPath = [appDrivePath, appId, "/"].join("");
var applicationPath = [applicationsPath, appId, "/"].join("");
if(this._isDir(applicationPath)) {
@ -322,7 +350,7 @@ cmu.prototype = {
if(found >= 1) {
this.applications[appId] = profile;
this.appdrive.applications[appId] = profile;
}
}
}
@ -332,8 +360,7 @@ cmu.prototype = {
}.bind(this));
if(callback) callback(this.applications, this.appdrive);
if(callback) callback(this.appdrive);
},
/**

View file

@ -32,7 +32,6 @@
* (Logger)
*/
window.Logger = {
levels: {
@ -135,7 +134,7 @@ window.Logger = {
/**
* (CustomApplications)
*
* Registers itself between the JCI system and CustomApplication runtime.
* Registers itself between the JCI system and CustomApplication framework.
*/
window.CustomApplications = {
@ -151,6 +150,9 @@ window.CustomApplications = {
systemAppId: 'system',
systemAppCategory: 'Applications',
/**
* Overwrites
*/
proxyAppName: 'vdt',
proxyAppContext: 'DriveChartDetails',
proxyMmuiEvent: 'SelectDriveRecord',
@ -192,12 +194,18 @@ window.CustomApplications = {
* Initializes the proxy
* @return void
*/
initialize: function() {
initialize: function(callback) {
this.requests = {};
if(!this.initialized) {
this.obtainConnection();
this.initialized = true;
this.requests = {};
this.obtainConnection();
}
return callback ? callback() : true;
},
@ -366,19 +374,15 @@ window.CustomApplications = {
if(!this.request(this.commands.REQUEST_APPDRIVE, false, function(error, result) {
if(error) {
return setTimeout(function() {
this.requestApplications();
this.requestAppDrive();
}.bind(this), 100);
}
console.log(result);
Logger.debug(this.ID, "requestAppdrive", result);
// Continue here
// boot strap system
this.bootstrap();
}.bind(this)));
},
@ -569,20 +573,6 @@ window.CustomApplications = {
},
/**
* (prepareCustomApplications)
*/
prepareCustomApplications: function() {
this.loadCount = 0;
setTimeout(function() {
this.loadCustomApplications();
}.bind(this), this.debug ? 500 : 5000); // first attempt wait 5s - the system might be booting still anyway
},
/**
* (loadCustomApplications)
*/
@ -672,7 +662,9 @@ window.CustomApplications = {
if(window.opera) {
window.opera.addEventListener('AfterEvent.load', function (e) {
CustomApplications.initialize();
CustomApplications.initialize(function() {
CustomApplications.bootstrap();
});
});
}