mirror of
https://github.com/flyandi/mazda-custom-application-sdk
synced 2024-12-23 19:52:51 -06:00
More refactor on bootstrapping
This commit is contained in:
parent
6567b2b018
commit
239f34983c
3 changed files with 75 additions and 55 deletions
|
@ -117,8 +117,9 @@ var buildJsonVersion = function(output, destination, name, attributes) {
|
||||||
var appDrivePathOutput = output + 'appdrive/',
|
var appDrivePathOutput = output + 'appdrive/',
|
||||||
systemPathOutput = appDrivePathOutput + 'system/',
|
systemPathOutput = appDrivePathOutput + 'system/',
|
||||||
frameworkPathInput = input + 'framework/',
|
frameworkPathInput = input + 'framework/',
|
||||||
frameworkPathOutput = systemPathOutput,
|
frameworkPathOutput = systemPathOutput + 'framework/',
|
||||||
customPathInput = input + 'custom/',
|
customPathInput = input + 'custom/',
|
||||||
|
customPathOutput = systemPathOutput + 'custom/',
|
||||||
appsPathInput = 'apps/',
|
appsPathInput = 'apps/',
|
||||||
appsPathOutput = appDrivePathOutput + 'apps/';
|
appsPathOutput = appDrivePathOutput + 'apps/';
|
||||||
|
|
||||||
|
@ -184,7 +185,7 @@ gulp.task('appdrive-framework-custom', function() {
|
||||||
return gulp.src(customPathInput + "**/*", {
|
return gulp.src(customPathInput + "**/*", {
|
||||||
base: customPathInput
|
base: customPathInput
|
||||||
})
|
})
|
||||||
.pipe(gulp.dest(frameworkPathOutput));
|
.pipe(gulp.dest(customPathOutput));
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -65,8 +65,12 @@ const APPLICATION_JS = "app.js";
|
||||||
const APPLICATION_WORKER = "worker.js";
|
const APPLICATION_WORKER = "worker.js";
|
||||||
|
|
||||||
const SYSTEM_PATH = "system/";
|
const SYSTEM_PATH = "system/";
|
||||||
const FRAMEWORK_JS = "framework.js";
|
const SYSTEM_FRAMEWORK_PATH = "framework/";
|
||||||
const FRAMEWORK_CSS = "framework.css";
|
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
|
* 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()
|
__construct: function()
|
||||||
{
|
{
|
||||||
this.applications = {};
|
|
||||||
|
|
||||||
this.__socket = new _webSocketServer({
|
this.__socket = new _webSocketServer({
|
||||||
port: this.network.port
|
port: this.network.port
|
||||||
});
|
});
|
||||||
|
@ -124,6 +126,7 @@ cmu.prototype = {
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
this.findAppDrive();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -196,11 +199,10 @@ cmu.prototype = {
|
||||||
case REQUEST_APPDRIVE:
|
case REQUEST_APPDRIVE:
|
||||||
|
|
||||||
// find applications
|
// find applications
|
||||||
this.findAppDrive(function(applications, appdrive) {
|
this.findAppDrive(function(appdrive) {
|
||||||
|
|
||||||
this.sendFromPayload(client, payload, {
|
this.sendFromPayload(client, payload, {
|
||||||
applications: applications,
|
appdrive
|
||||||
appdrive: appdrive,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
@ -255,42 +257,68 @@ cmu.prototype = {
|
||||||
*/
|
*/
|
||||||
findAppDrive: function(callback) {
|
findAppDrive: function(callback) {
|
||||||
|
|
||||||
this.applications = {};
|
this.appdrive = {
|
||||||
|
locations: {},
|
||||||
this.appdrive = false;
|
applications: {},
|
||||||
|
js: [],
|
||||||
this.framework = false;
|
css: [],
|
||||||
|
};
|
||||||
|
|
||||||
var result = [],
|
var result = [],
|
||||||
mountPoints = ['sd_nav', 'sda', 'sdb', 'sdc', 'sdd', 'sde'];
|
mountPoints = ['sd_nav', 'sda', 'sdb', 'sdc', 'sdd', 'sde'];
|
||||||
|
|
||||||
mountPoints.forEach(function(mountPoint) {
|
mountPoints.forEach(function(mountPoint) {
|
||||||
|
|
||||||
/** framework */
|
|
||||||
|
|
||||||
var frameworkPath = [MOUNTROOT_PATH, mountPoint, FRAMEWORK_PATH].join("");
|
|
||||||
|
|
||||||
var appDrivePath = [MOUNTROOT_PATH, mountPoint, APPDRIVE_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
|
* currently we only allow the first application to be registered
|
||||||
* otherwise you would need to restart the CMU
|
* 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)) {
|
if(this._isDir(applicationPath)) {
|
||||||
|
|
||||||
|
@ -322,7 +350,7 @@ cmu.prototype = {
|
||||||
|
|
||||||
|
|
||||||
if(found >= 1) {
|
if(found >= 1) {
|
||||||
this.applications[appId] = profile;
|
this.appdrive.applications[appId] = profile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,8 +360,7 @@ cmu.prototype = {
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
if(callback) callback(this.applications, this.appdrive);
|
if(callback) callback(this.appdrive);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
* (Logger)
|
* (Logger)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
window.Logger = {
|
window.Logger = {
|
||||||
|
|
||||||
levels: {
|
levels: {
|
||||||
|
@ -135,7 +134,7 @@ window.Logger = {
|
||||||
/**
|
/**
|
||||||
* (CustomApplications)
|
* (CustomApplications)
|
||||||
*
|
*
|
||||||
* Registers itself between the JCI system and CustomApplication runtime.
|
* Registers itself between the JCI system and CustomApplication framework.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
window.CustomApplications = {
|
window.CustomApplications = {
|
||||||
|
@ -151,6 +150,9 @@ window.CustomApplications = {
|
||||||
systemAppId: 'system',
|
systemAppId: 'system',
|
||||||
systemAppCategory: 'Applications',
|
systemAppCategory: 'Applications',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrites
|
||||||
|
*/
|
||||||
proxyAppName: 'vdt',
|
proxyAppName: 'vdt',
|
||||||
proxyAppContext: 'DriveChartDetails',
|
proxyAppContext: 'DriveChartDetails',
|
||||||
proxyMmuiEvent: 'SelectDriveRecord',
|
proxyMmuiEvent: 'SelectDriveRecord',
|
||||||
|
@ -192,12 +194,18 @@ window.CustomApplications = {
|
||||||
* Initializes the proxy
|
* Initializes the proxy
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
initialize: function() {
|
initialize: function(callback) {
|
||||||
|
|
||||||
|
if(!this.initialized) {
|
||||||
|
|
||||||
|
this.initialized = true;
|
||||||
|
|
||||||
this.requests = {};
|
this.requests = {};
|
||||||
|
|
||||||
this.obtainConnection();
|
this.obtainConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback ? callback() : true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -366,19 +374,15 @@ window.CustomApplications = {
|
||||||
if(!this.request(this.commands.REQUEST_APPDRIVE, false, function(error, result) {
|
if(!this.request(this.commands.REQUEST_APPDRIVE, false, function(error, result) {
|
||||||
|
|
||||||
if(error) {
|
if(error) {
|
||||||
|
|
||||||
return setTimeout(function() {
|
return setTimeout(function() {
|
||||||
|
|
||||||
this.requestApplications();
|
this.requestAppDrive();
|
||||||
|
|
||||||
}.bind(this), 100);
|
}.bind(this), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(result);
|
// boot strap system
|
||||||
|
this.bootstrap();
|
||||||
Logger.debug(this.ID, "requestAppdrive", result);
|
|
||||||
|
|
||||||
// Continue here
|
|
||||||
|
|
||||||
}.bind(this)));
|
}.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)
|
* (loadCustomApplications)
|
||||||
*/
|
*/
|
||||||
|
@ -672,7 +662,9 @@ window.CustomApplications = {
|
||||||
|
|
||||||
if(window.opera) {
|
if(window.opera) {
|
||||||
window.opera.addEventListener('AfterEvent.load', function (e) {
|
window.opera.addEventListener('AfterEvent.load', function (e) {
|
||||||
CustomApplications.initialize();
|
CustomApplications.initialize(function() {
|
||||||
|
CustomApplications.bootstrap();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue