mirror of
https://github.com/flyandi/mazda-custom-application-sdk
synced 2024-12-23 03:35:29 -06:00
more sync
This commit is contained in:
parent
846dd7ea78
commit
63904dac7a
3 changed files with 41 additions and 21 deletions
0
apps/app.helloworld/worker.js
Normal file
0
apps/app.helloworld/worker.js
Normal file
|
@ -45,7 +45,7 @@ const fs = require("fs");
|
|||
|
||||
const REQUEST_VERSION = "version";
|
||||
const REQUEST_PING = "ping";
|
||||
const REQUEST_APPLICATIONS = "applications";
|
||||
const REQUEST_APPDRIVE = "appdrive";
|
||||
|
||||
const RESULT_OK = 200;
|
||||
const RESULT_PONG = 201;
|
||||
|
@ -54,7 +54,7 @@ const RESULT_ERROR = 500;
|
|||
|
||||
|
||||
const MOUNTROOT_PATH = "/tmp/mnt/";
|
||||
const APPLICATIONS_PATH = "/apps/";
|
||||
const APPDRIVE_PATH = "/appdrive/";
|
||||
|
||||
const APPLICATION_JSON = "app.json";
|
||||
const APPLICATION_CSS = "app.css";
|
||||
|
@ -63,6 +63,10 @@ const APPLICATION_WORKER = "worker.js";
|
|||
|
||||
const APPDRIVE_JSON = "appdrive.json";
|
||||
|
||||
const FRAMEWORK_PATH = "/system/framework/";
|
||||
const FRAMEWORK_JS = "framework.js";
|
||||
const FRAMEWORK_CSS = "framework.css";
|
||||
|
||||
/**
|
||||
* This is the CMU that is compiled into the node binary and runs the actual link between the
|
||||
* custom applications and the CMU.
|
||||
|
@ -185,13 +189,13 @@ cmu.prototype = {
|
|||
break;
|
||||
|
||||
/**
|
||||
* Returns the current registered applications
|
||||
* @type REQUEST_APPLICATIONS
|
||||
* Finds the AppDrive
|
||||
* @type REQUEST_APPDRIVE
|
||||
*/
|
||||
case REQUEST_APPLICATIONS:
|
||||
case REQUEST_APPDRIVE:
|
||||
|
||||
// find applications
|
||||
this.findApplications(function(applications, appdrive) {
|
||||
this.findAppDrive(function(applications, appdrive) {
|
||||
|
||||
this.sendFromPayload(client, payload, {
|
||||
applications: applications,
|
||||
|
@ -245,32 +249,41 @@ cmu.prototype = {
|
|||
|
||||
|
||||
/**
|
||||
* Finds all applications in known locations
|
||||
* Finds the appdrive
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
findApplications: function(callback) {
|
||||
findAppDrive: function(callback) {
|
||||
|
||||
this.applications = {};
|
||||
|
||||
this.appdrive = false;
|
||||
|
||||
this.framework = false;
|
||||
|
||||
var result = [],
|
||||
mountPoints = ['sd_nav', 'sda', 'sdb', 'sdc', 'sdd', 'sde'];
|
||||
|
||||
mountPoints.forEach(function(mountPoint) {
|
||||
|
||||
var path = [MOUNTROOT_PATH, mountPoint, APPLICATIONS_PATH].join(""),
|
||||
/** framework */
|
||||
|
||||
var frameworkPath = [MOUNTROOT_PATH, mountPoint, FRAMEWORK_PATH].join("");
|
||||
|
||||
if(this._isDir)
|
||||
|
||||
var applicationsPath = [MOUNTROOT_PATH, mountPoint, APPLICATIONS_PATH].join(""),
|
||||
|
||||
appdriveFilename = [path, APPDRIVE_JSON].join(""),
|
||||
|
||||
appdriveFilename = [path, APPDRIVE_JSON].join("");
|
||||
|
||||
if(this._isFile(appdriveFilename)) {
|
||||
|
||||
this.appdrive = require(appdriveFilename);
|
||||
}
|
||||
|
||||
if(this._isDir(path)) {
|
||||
if(this._isDir(applicationsPath)) {
|
||||
|
||||
var files = fs.readdirSync(path);
|
||||
var files = fs.readdirSync(applicationsPath);
|
||||
|
||||
if(files.length) files.forEach(function(appId) {
|
||||
|
||||
|
@ -281,13 +294,13 @@ cmu.prototype = {
|
|||
|
||||
if(!this.applications[appId]) {
|
||||
|
||||
var applicationPath = [path, appId, "/"].join("");
|
||||
var applicationPath = [applicationsPath, appId, "/"].join("");
|
||||
|
||||
if(this._isDir(applicationPath)) {
|
||||
|
||||
var profile = {
|
||||
appId: appId,
|
||||
appPath: applicationPath,
|
||||
id: appId,
|
||||
path: applicationPath,
|
||||
files: {},
|
||||
},
|
||||
parts = [APPLICATION_JS, APPLICATION_JSON, APPLICATION_CSS, APPLICATION_WORKER],
|
||||
|
@ -301,6 +314,13 @@ cmu.prototype = {
|
|||
|
||||
profile.files[filename] = fullFilename;
|
||||
found++;
|
||||
|
||||
switch(filename) {
|
||||
|
||||
case APPLICATION_JSON:
|
||||
profile.info = require(fullFilename);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ window.CustomApplications = {
|
|||
commands: {
|
||||
|
||||
REQUEST_PING: 'ping',
|
||||
REQUEST_APPLICATIONS: 'applications',
|
||||
REQUEST_APPDRIVE: 'appdrive',
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -239,7 +239,7 @@ window.CustomApplications = {
|
|||
|
||||
this.client.ping();
|
||||
|
||||
this.requestApplications();
|
||||
this.requestAppDrive();
|
||||
|
||||
}.bind(this);
|
||||
|
||||
|
@ -356,14 +356,14 @@ window.CustomApplications = {
|
|||
|
||||
|
||||
/**
|
||||
* Trys to load the Custom Applications
|
||||
* Trys to load the AppDrive
|
||||
* @return void
|
||||
*/
|
||||
requestApplications: function() {
|
||||
requestAppDrive: function() {
|
||||
|
||||
if(typeof(CustomApplicationsHandler) != "undefined") return false;
|
||||
|
||||
if(!this.request(this.commands.REQUEST_APPLICATIONS, false, function(error, result) {
|
||||
if(!this.request(this.commands.REQUEST_APPDRIVE, false, function(error, result) {
|
||||
|
||||
if(error) {
|
||||
|
||||
|
@ -374,7 +374,7 @@ window.CustomApplications = {
|
|||
}.bind(this), 100);
|
||||
}
|
||||
|
||||
console.log(result);
|
||||
// Continue here
|
||||
|
||||
}.bind(this)));
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue