From 295d72960cad391850803e8c4e83d5133bbe82f7 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 6 Feb 2012 11:40:15 -0800 Subject: Setting up library detection for Chrome File System --- js/io/system/chromeapi.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'js/io/system/chromeapi.js') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index 6bf6b9fe..f4e04a09 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -31,6 +31,8 @@ exports.ChromeApi = Montage.create(Object.prototype, { var readyEvent = document.createEvent("CustomEvent"); readyEvent.initEvent('ready', true, true); this.dispatchEvent(readyEvent); + //Building data of local Ninja Library + this._listNinjaChromeLibrary(); }.bind(this), function (e) {return false}); //Returns false on error (not able to init) // return true; @@ -73,10 +75,17 @@ exports.ChromeApi = Montage.create(Object.prototype, { } }, //////////////////////////////////////////////////////////////////// - // + //Returns the directory contents to a callback function directoryContents: { enumerable: true, - value: function() { + value: function(directory, callback) { + //Creating instance of directory reader + this.fileSystem.directoryReader = directory.createReader(); + //Getting directory contents and sending results to callback + this.fileSystem.directoryReader.readEntries(function(results) { + //Calling callback with results (null if invalid directory) + callback(results); + }, function (e) {callback(null)}); } }, //////////////////////////////////////////////////////////////////// @@ -102,11 +111,24 @@ exports.ChromeApi = Montage.create(Object.prototype, { }, //////////////////////////////////////////////////////////////////// // - getLocalLibrary: { + _listNinjaChromeLibrary: { enumerable: false, value: function () { + function parseLibrary (contents) { + // + var lib = []; + // + + + + //Dispatching action ready event + var libraryEvent = document.createEvent("CustomEvent"); + libraryEvent.initEvent('library', true, true); + libraryEvent.ninjaChromeLibrary = lib; + this.dispatchEvent(libraryEvent); + }; // - return {}; + this.directoryContents(this.fileSystem.root, parseLibrary.bind(this)); } } //////////////////////////////////////////////////////////////////// -- cgit v1.2.3