From 20803c71179bcffeaeaba4375bd06155d21dafe6 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 5 Feb 2012 22:46:24 -0800 Subject: Setting up Chrome IO class --- js/io/system/chromeapi.js | 17 ++++++++++++++++- js/io/system/coreioapi.js | 46 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 10 deletions(-) (limited to 'js/io/system') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index 04e62b11..6bf6b9fe 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -25,8 +25,14 @@ exports.ChromeApi = Montage.create(Object.prototype, { if (window.webkitRequestFileSystem) { //Current way to init Chrome's fileSystem API window.webkitRequestFileSystem(window.PERSISTENT, size*1024*1024, function (fs) { + //Storing reference to instance this.fileSystem = fs; - }.bind(this)); + //Dispatching action ready event + var readyEvent = document.createEvent("CustomEvent"); + readyEvent.initEvent('ready', true, true); + this.dispatchEvent(readyEvent); + }.bind(this), function (e) {return false}); //Returns false on error (not able to init) + // return true; } else { //No fileSystem API @@ -93,6 +99,15 @@ exports.ChromeApi = Montage.create(Object.prototype, { enumerable: true, value: function() { } + }, + //////////////////////////////////////////////////////////////////// + // + getLocalLibrary: { + enumerable: false, + value: function () { + // + return {}; + } } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 73d9fa76..3fb9374a 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -25,15 +25,6 @@ exports.CoreIoApi = Montage.create(Component, { deserializedFromTemplate: { enumerable: false, value: function () { - //////////////////////////////////////////////////////////// - //Getting reference of chrome file system API - this.chromeFileSystem = ChromeApi; - //Sending size in MBs for file system storage - if (this.chromeFileSystem.init(20)) { - //Available - } else { - //Not available - } //////////////////////////////////////////////////////////// //Checking for local storage of URL for IO if (window.localStorage['ioRootUrl']) { @@ -46,8 +37,45 @@ exports.CoreIoApi = Montage.create(Component, { this.ioServiceDetected = false; } //////////////////////////////////////////////////////////// + //Getting reference of chrome file system API + this.chromeFileSystem = ChromeApi; + //Sending size in MBs for file system storage + var chromeFs = this.chromeFileSystem.init(20); + //Checking for availability of API + if (chromeFs) { + this.chromeFileSystem.addEventListener('ready', this, false); + } else { + //Error, Chrome File System API not detected + } + //////////////////////////////////////////////////////////// } }, + //////////////////////////////////////////////////////////////////// + // + handleReady: { + enumerable: false, + value: function (e) { + this.chromeFileSystem.removeEventListener('ready', this, false); + this.chromeNinjaLibrary = this.chromeFileSystem.getLocalLibrary(); + } + }, + //////////////////////////////////////////////////////////////////// + // + _chromeNinjaLibrary: { + enumerable: false, + value: null + }, + //////////////////////////////////////////////////////////////////// + // + chromeNinjaLibrary: { + enumerable: false, + get: function() { + return this._chromeNinjaLibrary; + }, + set: function(value) { + this._chromeNinjaLibrary = value; + } + }, //////////////////////////////////////////////////////////////////// // _chromeFileSystem: { -- cgit v1.2.3