diff options
Diffstat (limited to 'js/io/system/chromeapi.js')
-rw-r--r-- | js/io/system/chromeapi.js | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index 6bf6b9fe..fb141687 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js | |||
@@ -31,6 +31,8 @@ exports.ChromeApi = Montage.create(Object.prototype, { | |||
31 | var readyEvent = document.createEvent("CustomEvent"); | 31 | var readyEvent = document.createEvent("CustomEvent"); |
32 | readyEvent.initEvent('ready', true, true); | 32 | readyEvent.initEvent('ready', true, true); |
33 | this.dispatchEvent(readyEvent); | 33 | this.dispatchEvent(readyEvent); |
34 | //Building data of local Ninja Library | ||
35 | this._listNinjaChromeLibrary(); | ||
34 | }.bind(this), function (e) {return false}); //Returns false on error (not able to init) | 36 | }.bind(this), function (e) {return false}); //Returns false on error (not able to init) |
35 | // | 37 | // |
36 | return true; | 38 | return true; |
@@ -67,16 +69,30 @@ exports.ChromeApi = Montage.create(Object.prototype, { | |||
67 | 69 | ||
68 | //////////////////////////////////////////////////////////////////// | 70 | //////////////////////////////////////////////////////////////////// |
69 | // | 71 | // |
70 | directoryDelete: {//TODO: Make sure it uses a force delete | 72 | directoryDelete: { |
71 | enumerable: true, | 73 | enumerable: true, |
72 | value: function() { | 74 | value: function(directoryPath, callback) { |
75 | // | ||
76 | this.fileSystem.getDirectory(directoryPath, {}, function(dirEntry) { | ||
77 | // | ||
78 | dirEntry.removeRecursively(function() { | ||
79 | callback(true); | ||
80 | }); | ||
81 | }, function (e) {callback(false)}); | ||
73 | } | 82 | } |
74 | }, | 83 | }, |
75 | //////////////////////////////////////////////////////////////////// | 84 | //////////////////////////////////////////////////////////////////// |
76 | // | 85 | //Returns the directory contents to a callback function |
77 | directoryContents: { | 86 | directoryContents: { |
78 | enumerable: true, | 87 | enumerable: true, |
79 | value: function() { | 88 | value: function(directory, callback) { |
89 | //Creating instance of directory reader | ||
90 | this.fileSystem.directoryReader = directory.createReader(); | ||
91 | //Getting directory contents and sending results to callback | ||
92 | this.fileSystem.directoryReader.readEntries(function(results) { | ||
93 | //Calling callback with results (null if invalid directory) | ||
94 | callback(results); | ||
95 | }, function (e) {callback(null)}); | ||
80 | } | 96 | } |
81 | }, | 97 | }, |
82 | //////////////////////////////////////////////////////////////////// | 98 | //////////////////////////////////////////////////////////////////// |
@@ -102,11 +118,24 @@ exports.ChromeApi = Montage.create(Object.prototype, { | |||
102 | }, | 118 | }, |
103 | //////////////////////////////////////////////////////////////////// | 119 | //////////////////////////////////////////////////////////////////// |
104 | // | 120 | // |
105 | getLocalLibrary: { | 121 | _listNinjaChromeLibrary: { |
106 | enumerable: false, | 122 | enumerable: false, |
107 | value: function () { | 123 | value: function () { |
124 | function parseLibrary (contents) { | ||
125 | // | ||
126 | var lib = []; | ||
127 | // | ||
128 | |||
129 | |||
130 | |||
131 | //Dispatching action ready event | ||
132 | var libraryEvent = document.createEvent("CustomEvent"); | ||
133 | libraryEvent.initEvent('library', true, true); | ||
134 | libraryEvent.ninjaChromeLibrary = lib; | ||
135 | this.dispatchEvent(libraryEvent); | ||
136 | }; | ||
108 | // | 137 | // |
109 | return {}; | 138 | this.directoryContents(this.fileSystem.root, parseLibrary.bind(this)); |
110 | } | 139 | } |
111 | } | 140 | } |
112 | //////////////////////////////////////////////////////////////////// | 141 | //////////////////////////////////////////////////////////////////// |