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 ++++++++++++++++++++++++++---- js/io/system/coreioapi.js | 19 ++++++++++++++++++- 2 files changed, 44 insertions(+), 5 deletions(-) (limited to 'js/io') 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)); } } //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 3fb9374a..3be6011d 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -55,8 +55,25 @@ exports.CoreIoApi = Montage.create(Component, { handleReady: { enumerable: false, value: function (e) { + // this.chromeFileSystem.removeEventListener('ready', this, false); - this.chromeNinjaLibrary = this.chromeFileSystem.getLocalLibrary(); + // + this.chromeFileSystem.addEventListener('library', this, false); + } + }, + //////////////////////////////////////////////////////////////////// + // + handleLibrary: { + enumerable: false, + value: function (e) { + // + this.chromeFileSystem.removeEventListener('library', this, false); + // + if (e._event.ninjaChromeLibrary.length < 1) { + console.log('no libraries'); + } else { + console.log('found libraries'); + } } }, //////////////////////////////////////////////////////////////////// -- cgit v1.2.3