From 8c530e9291721083ba11746fc5b3da66dc692120 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 5 Feb 2012 10:42:58 -0800 Subject: Setting up IO Ninja Library This class will be used to copy locally the library needed for Ninja's IO. --- js/io/system/ninjalibrary.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 js/io/system/ninjalibrary.js (limited to 'js/io/system/ninjalibrary.js') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js new file mode 100644 index 00000000..3f8585ed --- /dev/null +++ b/js/io/system/ninjalibrary.js @@ -0,0 +1,29 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +/* ///////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +NOTES: +//////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////// */ +// +var Montage = require("montage/core/core").Montage; +//////////////////////////////////////////////////////////////////////// +// +exports.NinjaLibrary = Montage.create(Object.prototype, { + //////////////////////////////////////////////////////////////////// + // + init: { + enumerable: true, + value: function() { + // + } + } + //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// +}); +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// \ No newline at end of file -- cgit v1.2.3 From ad85ff92ba44fb3c8ccf24c2f1b9296804dfa8ca Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 6 Feb 2012 22:33:42 -0800 Subject: Single file library syncing Added the ability to store locally in chrome single file libraries used by Ninja. Working on adding multi-file libraries. --- js/io/system/ninjalibrary.js | 93 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) (limited to 'js/io/system/ninjalibrary.js') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 3f8585ed..e3d855f1 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -7,6 +7,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot /* ///////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// NOTES: + + Core API reference in NINJA: this.application.ninja.coreIoApi + //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // @@ -16,12 +19,98 @@ var Montage = require("montage/core/core").Montage; exports.NinjaLibrary = Montage.create(Object.prototype, { //////////////////////////////////////////////////////////////////// // - init: { + _chromeApi: { + enumerable: false, + value: null + }, + //////////////////////////////////////////////////////////////////// + // + chromeApi: { + enumerable: false, + get: function() { + return this._chromeApi; + }, + set: function(value) { + this._chromeApi = value; + } + }, + //////////////////////////////////////////////////////////////////// + // + synchronize: { + enumerable: true, + value: function(chromeLibs, chrome) { + // + this.chromeApi = chrome; + // + var i, libs, xhr = new XMLHttpRequest(), tocopylibs = []; + //Getting known json list of libraries to copy to chrome + xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); + xhr.send(); + //Checkng for correct reponse + if (xhr.readyState === 4) { + //Parsing json libraries + libs = JSON.parse(xhr.response); + // + if (chromeLibs.length > 0) { + //Compare (always deleting for testing) + for (i=0; chromeLibs[i]; i++) { + this.chromeApi.directoryDelete(chromeLibs[i]); + } + } else { + //No library is present, must copy all + for (var j in libs.libraries) { + //name: used to folder container contents + //path: url of descriptor json or single file to load (descriptor has list of files) + //singular: indicates the path is the file to be loaded into folder + if (libs.libraries[j].file) { + tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path, file: libs.libraries[j].file}); + } else { + tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path}); + } + } + } + // + if (tocopylibs.length > 0) { + for (i=0; tocopylibs[i]; i++) { + //Checking for library to be single file + if (tocopylibs[i].file) { + //Creating root folder + this.chromeApi.directoryNew('/'+tocopylibs[i].name); + //Getting file contents + xhr = new XMLHttpRequest(); + xhr.open("GET", tocopylibs[i].path, false); + xhr.send(); + //Checking for status + if (xhr.readyState === 4) { //TODO: add check for mime type + //Creating new file from loaded content + this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain'); + //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain', function (v){console.log(v)}); + } else { + //Error + } + } else { + // + } + } + } else { + //No libraries to copy + } + } else { + //Error + } + } + }/* +, + //////////////////////////////////////////////////////////////////// + // + createFolder: { enumerable: true, - value: function() { + value: function(name) { // + this.chromeApi.directoryNew(name); } } +*/ //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// }); -- cgit v1.2.3 From c4c5a8b49bb26d6344edceba73834754bb9930cf Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 11:14:57 -0800 Subject: Adding ability to copy an entire library for Ninja Added the functionality to copy an entire directory/library from a JSON descriptor file into the app sandbox. Need to add logic to dispatch a 'synchronized' event for Ninja to know everything is up to date. --- js/io/system/ninjalibrary.js | 88 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 13 deletions(-) (limited to 'js/io/system/ninjalibrary.js') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index e3d855f1..09cf7407 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -42,7 +42,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { // this.chromeApi = chrome; // - var i, libs, xhr = new XMLHttpRequest(), tocopylibs = []; + var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = []; //Getting known json list of libraries to copy to chrome xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); xhr.send(); @@ -52,9 +52,9 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { libs = JSON.parse(xhr.response); // if (chromeLibs.length > 0) { - //Compare (always deleting for testing) - for (i=0; chromeLibs[i]; i++) { - this.chromeApi.directoryDelete(chromeLibs[i]); + //TODO: Remove + for (i=0; chromeLibs[i]; i++) { + this.chromeApi.directoryDelete(chromeLibs[i]); } } else { //No library is present, must copy all @@ -84,12 +84,58 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain'); - //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain', function (v){console.log(v)}); } else { - //Error + //Error creating single file library } } else { - // + //Creating root folder + this.chromeApi.directoryNew('/'+tocopylibs[i].name); + //Getting file contents + xhr = new XMLHttpRequest(); + xhr.open("GET", tocopylibs[i].path, false); + xhr.send(); + //Checking for status + if (xhr.readyState === 4) { + // + libjson = JSON.parse(xhr.response); + // + for (l=0; libjson.directories[l]; l++) { + libjson.dirsToCreate = libjson.directories.length; + libjson.dirsCreated = 0; + libjson.filesToCreate = libjson.files.length; + libjson.filesCreated = 0; + libjson.api = this.chromeApi; + libjson.local = tocopylibs[i].name; + this.createDirectory(tocopylibs[i].name, libjson.directories[l], function (status) { + //Checking for success on directories created + if (status) { + this.dirsCreated++; + } + //All directories created + if (this.dirsCreated === this.dirsToCreate) { + var xhr, i; + for (i=0; this.files[i]; i++) { + xhr = new XMLHttpRequest(); + xhr.open("GET", this.root+this.files[i], false); + xhr.send(); + //Checking for status + if (xhr.readyState === 4) { + this.api.fileNew(this.local+'/'+this.files[i], xhr.response, 'text/plain', function (status) { + if (status) { + this.filesCreated++; + } + if (this.filesCreated === this.filesToCreate) { + //TODO: Add logic for task completed + } + }.bind(this)); + } + } + } + }.bind(libjson)); + } + } else { + //Error + } } } } else { @@ -99,18 +145,34 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Error } } - }/* -, + }, //////////////////////////////////////////////////////////////////// // - createFolder: { + createDirectory: { enumerable: true, - value: function(name) { + value: function(root, folder, callback) { // - this.chromeApi.directoryNew(name); + if (folder.name) { + if (root) { + dir = root+'/'+folder.name; + } else { + dir = folder.name; + } + // + this.chromeApi.directoryNew(dir, function (status) {if (callback)callback(status)}); + } + // + if (folder.children) { + for (var j in folder.children) { + if (root) { + this.createDirectory(root+'/'+folder.name, folder.children[j]); + } else { + this.createDirectory(folder.name, folder.children[j]); + } + } + } } } -*/ //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// }); -- cgit v1.2.3 From 111509d5cbbd54b11afbc49f7c78d0c0548bb617 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 12:06:21 -0800 Subject: Adding mime-type detection for new file --- js/io/system/ninjalibrary.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/io/system/ninjalibrary.js') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 09cf7407..658ce589 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -83,7 +83,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Checking for status if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content - this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain'); + this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response); } else { //Error creating single file library } @@ -120,7 +120,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { xhr.send(); //Checking for status if (xhr.readyState === 4) { - this.api.fileNew(this.local+'/'+this.files[i], xhr.response, 'text/plain', function (status) { + this.api.fileNew(this.local+'/'+this.files[i], xhr.response, function (status) { if (status) { this.filesCreated++; } -- cgit v1.2.3 From 516e04ab45ca1dbad9c2847a9a213919d6e812f5 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 14:50:48 -0800 Subject: Adding library synced events Added an event that will be dispatched when Ninja loads and the local chrome Ninja library is fully synced with all required libs. --- js/io/system/ninjalibrary.js | 69 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 8 deletions(-) (limited to 'js/io/system/ninjalibrary.js') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 658ce589..fa2e7d1f 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -33,6 +33,18 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { set: function(value) { this._chromeApi = value; } + }, + //////////////////////////////////////////////////////////////////// + // + _libsToSync: { + enumerable: false, + value: 0 + }, + //////////////////////////////////////////////////////////////////// + // + _syncedLibs: { + enumerable: false, + value: 0 }, //////////////////////////////////////////////////////////////////// // @@ -42,7 +54,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { // this.chromeApi = chrome; // - var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = []; + var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = [], copied; //Getting known json list of libraries to copy to chrome xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); xhr.send(); @@ -52,10 +64,27 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { libs = JSON.parse(xhr.response); // if (chromeLibs.length > 0) { - //TODO: Remove + // for (i=0; chromeLibs[i]; i++) { - this.chromeApi.directoryDelete(chromeLibs[i]); + copied = false; + for (var j in libs.libraries) { + if (String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase() === chromeLibs[i]) { + copied = true; + } + } + // + if (!copied) { + if (libs.libraries[j].file) { + tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path, file: libs.libraries[j].file}); + } else { + tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path}); + } + } else { + //TODO: Remove, currently manually removing copied libraries + this.chromeApi.directoryDelete(chromeLibs[i]); + } } + } else { //No library is present, must copy all for (var j in libs.libraries) { @@ -70,6 +99,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } } // + this._libsToSync = tocopylibs.length; + // if (tocopylibs.length > 0) { for (i=0; tocopylibs[i]; i++) { //Checking for library to be single file @@ -83,7 +114,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Checking for status if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content - this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response); + this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); } else { //Error creating single file library } @@ -104,8 +135,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { libjson.dirsCreated = 0; libjson.filesToCreate = libjson.files.length; libjson.filesCreated = 0; - libjson.api = this.chromeApi; libjson.local = tocopylibs[i].name; + libjson.main = this; this.createDirectory(tocopylibs[i].name, libjson.directories[l], function (status) { //Checking for success on directories created if (status) { @@ -120,12 +151,12 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { xhr.send(); //Checking for status if (xhr.readyState === 4) { - this.api.fileNew(this.local+'/'+this.files[i], xhr.response, function (status) { + this.main.chromeApi.fileNew(this.local+'/'+this.files[i], xhr.response, function (status) { if (status) { this.filesCreated++; } if (this.filesCreated === this.filesToCreate) { - //TODO: Add logic for task completed + this.main.libraryCopied(); } }.bind(this)); } @@ -139,7 +170,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } } } else { - //No libraries to copy + //Dispatching ready event since nothing to copy + this._dispatchEvent(); } } else { //Error @@ -172,6 +204,27 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } } } + }, + //////////////////////////////////////////////////////////////////// + // + libraryCopied: { + enumerable: true, + value: function() { + this._syncedLibs++; + if (this._syncedLibs === this._libsToSync) { + this._dispatchEvent(); + } + } + }, + //////////////////////////////////////////////////////////////////// + // + _dispatchEvent: { + enumerable: true, + value: function () { + var syncEvent = document.createEvent("CustomEvent"); + syncEvent.initEvent('sync', true, true); + this.dispatchEvent(syncEvent); + } } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From af58afcffff5ac556d16f050a325ac0406897fcd Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 17:03:44 -0800 Subject: Copy local library to cloud Adding functionality to copy a local library to the cloud. Currently creating directory structure. Need to add ability to copy files and ensure proper mime-type is set. --- js/io/system/ninjalibrary.js | 77 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) (limited to 'js/io/system/ninjalibrary.js') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index fa2e7d1f..0ab19401 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -8,8 +8,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot //////////////////////////////////////////////////////////////////////// NOTES: - Core API reference in NINJA: this.application.ninja.coreIoApi - //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // @@ -36,6 +34,23 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { }, //////////////////////////////////////////////////////////////////// // + _coreApi: { + enumerable: false, + value: null + }, + //////////////////////////////////////////////////////////////////// + // + coreApi: { + enumerable: false, + get: function() { + return this._coreApi; + }, + set: function(value) { + this._coreApi = value; + } + }, + //////////////////////////////////////////////////////////////////// + // _libsToSync: { enumerable: false, value: 0 @@ -45,6 +60,62 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { _syncedLibs: { enumerable: false, value: 0 + }, + //////////////////////////////////////////////////////////////////// + // + copyLibToCloud: { + enumerable: false, + value: function (path, libName) { + // + if(this.coreApi.directoryExists({uri: '/'+path+'/'+libName+'/'}).status === 404) { + this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) { + for (var i in contents) { + if (libName === contents[i].name) { + //Getting contents of library to be copied + this.chromeApi.directoryContents(contents[i], function (lib) { + //Creating directory structure from subfolders + this.copyDirectoryToCloud(path, contents[i], function (status) {console.log(status)}); + }.bind(this)); + break; + } + } + }.bind(this)); + } else { + //Error + } + } + }, + //////////////////////////////////////////////////////////////////// + // + copyDirectoryToCloud: { + enumerable: true, + value: function(root, folder, callback) { + if (folder.name) { + var dir; + if (root) { + dir = root+'/'+folder.name; + } else { + dir = folder.name; + } + // + if (!this.coreApi.createDirectory({uri: '/'+dir+'/'})) { + //Error occured while creating folders + return; + } + } + // + if (folder.isDirectory) { + this.chromeApi.directoryContents(folder, function (contents) { + for (var i in contents) { + if (contents[i].isDirectory) { + this.copyDirectoryToCloud(dir, contents[i]); + } else if (contents[i].isFile){ + //File to copy + } + } + }.bind(this)); + } + } }, //////////////////////////////////////////////////////////////////// // @@ -81,7 +152,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } } else { //TODO: Remove, currently manually removing copied libraries - this.chromeApi.directoryDelete(chromeLibs[i]); + //this.chromeApi.directoryDelete(chromeLibs[i]); } } -- cgit v1.2.3 From 687cfbbae1df2392267e9602f955f6eadd5b339d Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 23:13:15 -0800 Subject: Mime type fixes Trying to fix mime type issues in FileSystem, Chrome does not support reponseType 'blob', so looking at alternatives. --- js/io/system/ninjalibrary.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'js/io/system/ninjalibrary.js') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 0ab19401..3914ec29 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -74,7 +74,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Getting contents of library to be copied this.chromeApi.directoryContents(contents[i], function (lib) { //Creating directory structure from subfolders - this.copyDirectoryToCloud(path, contents[i], function (status) {console.log(status)}); + this.copyDirectoryToCloud(path, contents[i], '/'+path, function (status) {console.log(status)}); }.bind(this)); break; } @@ -89,7 +89,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { // copyDirectoryToCloud: { enumerable: true, - value: function(root, folder, callback) { + value: function(root, folder, fileRoot, callback) { + // if (folder.name) { var dir; if (root) { @@ -108,9 +109,14 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { this.chromeApi.directoryContents(folder, function (contents) { for (var i in contents) { if (contents[i].isDirectory) { - this.copyDirectoryToCloud(dir, contents[i]); + this.copyDirectoryToCloud(dir, contents[i], fileRoot); } else if (contents[i].isFile){ //File to copy + this.chromeApi.fileContent(contents[i].fullPath, function (result) { + // + this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); + //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); + }.bind(this)); } } }.bind(this)); @@ -185,7 +191,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Checking for status if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content - this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); + //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); } else { //Error creating single file library } -- cgit v1.2.3 From 4bfac53c9a77a3af35d029757eece53f4b7212ed Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 8 Feb 2012 13:11:48 -0800 Subject: Fixed data type issue on copying library files Fixed the methods to allow for ArrayBuffer data to be sent, fixes saving files that are not plain text. --- js/io/system/ninjalibrary.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'js/io/system/ninjalibrary.js') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 3914ec29..7b524189 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -114,8 +114,18 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //File to copy this.chromeApi.fileContent(contents[i].fullPath, function (result) { // - this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); - //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); + + /* +var ui8a = new Uint8Array(result.content); + console.log(ui8a); + + var blob = new window.WebKitBlobBuilder; + blob.append(result.content); +*/ + //console.log(blob.getBlob(result.data.type)); + //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); + //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: blob.getBlob(result.data.type), contentType: result.data.type}); + this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); }.bind(this)); } } @@ -187,11 +197,12 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Getting file contents xhr = new XMLHttpRequest(); xhr.open("GET", tocopylibs[i].path, false); + xhr.responseType = "arraybuffer"; xhr.send(); //Checking for status if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content - //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); + this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); } else { //Error creating single file library } @@ -225,6 +236,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { for (i=0; this.files[i]; i++) { xhr = new XMLHttpRequest(); xhr.open("GET", this.root+this.files[i], false); + xhr.responseType = "arraybuffer"; xhr.send(); //Checking for status if (xhr.readyState === 4) { -- cgit v1.2.3 From 2133bd1e74864b4b69d824ba7977fa07034af962 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 8 Feb 2012 14:38:20 -0800 Subject: Setting up packaged app --- js/io/system/ninjalibrary.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'js/io/system/ninjalibrary.js') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 7b524189..c85de3b0 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -114,16 +114,6 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //File to copy this.chromeApi.fileContent(contents[i].fullPath, function (result) { // - - /* -var ui8a = new Uint8Array(result.content); - console.log(ui8a); - - var blob = new window.WebKitBlobBuilder; - blob.append(result.content); -*/ - //console.log(blob.getBlob(result.data.type)); - //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: blob.getBlob(result.data.type), contentType: result.data.type}); this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); }.bind(this)); @@ -143,7 +133,7 @@ var ui8a = new Uint8Array(result.content); // var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = [], copied; //Getting known json list of libraries to copy to chrome - xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); + xhr.open("GET", '/js/io/system/ninjalibrary.json', false); xhr.send(); //Checkng for correct reponse if (xhr.readyState === 4) { -- cgit v1.2.3 From b62b9d5b3dfd1dfacaf9111f85d40dd246d2b90e Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 8 Feb 2012 16:33:09 -0800 Subject: Adding a purge library method Added a delete libraries function to delete all libraries in Chrome sandbox (as in a force delete). Also updated descriptor files to go with new directory layout of files and relation to the relatives paths used by the packed app and it's manifest. --- js/io/system/ninjalibrary.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'js/io/system/ninjalibrary.js') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index c85de3b0..fc943323 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -297,6 +297,24 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { }, //////////////////////////////////////////////////////////////////// // + deleteLibraries: { + enumerable: true, + value: function () { + function parseLibrary (contents) { + // + for(var i=0; contents[i]; i++) { + // + if (contents[i].isDirectory) { + this.chromeApi.directoryDelete(contents[i].name); + } + } + }; + // + this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, parseLibrary.bind(this)); + } + }, + //////////////////////////////////////////////////////////////////// + // _dispatchEvent: { enumerable: true, value: function () { -- cgit v1.2.3