more sync

This commit is contained in:
140b8f67-ec51-4b64-9606-bff2dffa0170 2016-03-28 07:26:35 -07:00
parent 846dd7ea78
commit 63904dac7a
3 changed files with 41 additions and 21 deletions

View file

View file

@ -45,7 +45,7 @@ const fs = require("fs");
const REQUEST_VERSION = "version"; const REQUEST_VERSION = "version";
const REQUEST_PING = "ping"; const REQUEST_PING = "ping";
const REQUEST_APPLICATIONS = "applications"; const REQUEST_APPDRIVE = "appdrive";
const RESULT_OK = 200; const RESULT_OK = 200;
const RESULT_PONG = 201; const RESULT_PONG = 201;
@ -54,7 +54,7 @@ const RESULT_ERROR = 500;
const MOUNTROOT_PATH = "/tmp/mnt/"; const MOUNTROOT_PATH = "/tmp/mnt/";
const APPLICATIONS_PATH = "/apps/"; const APPDRIVE_PATH = "/appdrive/";
const APPLICATION_JSON = "app.json"; const APPLICATION_JSON = "app.json";
const APPLICATION_CSS = "app.css"; const APPLICATION_CSS = "app.css";
@ -63,6 +63,10 @@ const APPLICATION_WORKER = "worker.js";
const APPDRIVE_JSON = "appdrive.json"; 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 * This is the CMU that is compiled into the node binary and runs the actual link between the
* custom applications and the CMU. * custom applications and the CMU.
@ -185,13 +189,13 @@ cmu.prototype = {
break; break;
/** /**
* Returns the current registered applications * Finds the AppDrive
* @type REQUEST_APPLICATIONS * @type REQUEST_APPDRIVE
*/ */
case REQUEST_APPLICATIONS: case REQUEST_APPDRIVE:
// find applications // find applications
this.findApplications(function(applications, appdrive) { this.findAppDrive(function(applications, appdrive) {
this.sendFromPayload(client, payload, { this.sendFromPayload(client, payload, {
applications: applications, applications: applications,
@ -245,32 +249,41 @@ cmu.prototype = {
/** /**
* Finds all applications in known locations * Finds the appdrive
* @return {[type]} [description] * @return {[type]} [description]
*/ */
findApplications: function(callback) { findAppDrive: function(callback) {
this.applications = {}; this.applications = {};
this.appdrive = false; this.appdrive = false;
this.framework = false;
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) {
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)) { if(this._isFile(appdriveFilename)) {
this.appdrive = require(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) { if(files.length) files.forEach(function(appId) {
@ -281,13 +294,13 @@ cmu.prototype = {
if(!this.applications[appId]) { if(!this.applications[appId]) {
var applicationPath = [path, appId, "/"].join(""); var applicationPath = [applicationsPath, appId, "/"].join("");
if(this._isDir(applicationPath)) { if(this._isDir(applicationPath)) {
var profile = { var profile = {
appId: appId, id: appId,
appPath: applicationPath, path: applicationPath,
files: {}, files: {},
}, },
parts = [APPLICATION_JS, APPLICATION_JSON, APPLICATION_CSS, APPLICATION_WORKER], parts = [APPLICATION_JS, APPLICATION_JSON, APPLICATION_CSS, APPLICATION_WORKER],
@ -301,6 +314,13 @@ cmu.prototype = {
profile.files[filename] = fullFilename; profile.files[filename] = fullFilename;
found++; found++;
switch(filename) {
case APPLICATION_JSON:
profile.info = require(fullFilename);
break;
}
} }
}.bind(this)); }.bind(this));

View file

@ -174,7 +174,7 @@ window.CustomApplications = {
commands: { commands: {
REQUEST_PING: 'ping', REQUEST_PING: 'ping',
REQUEST_APPLICATIONS: 'applications', REQUEST_APPDRIVE: 'appdrive',
}, },
/** /**
@ -239,7 +239,7 @@ window.CustomApplications = {
this.client.ping(); this.client.ping();
this.requestApplications(); this.requestAppDrive();
}.bind(this); }.bind(this);
@ -356,14 +356,14 @@ window.CustomApplications = {
/** /**
* Trys to load the Custom Applications * Trys to load the AppDrive
* @return void * @return void
*/ */
requestApplications: function() { requestAppDrive: function() {
if(typeof(CustomApplicationsHandler) != "undefined") return false; 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) { if(error) {
@ -374,7 +374,7 @@ window.CustomApplications = {
}.bind(this), 100); }.bind(this), 100);
} }
console.log(result); // Continue here
}.bind(this))); }.bind(this)));
}, },