diff options
Diffstat (limited to 'js/io/system')
-rw-r--r-- | js/io/system/chromeapi.js | 41 | ||||
-rwxr-xr-x | js/io/system/coreioapi.js | 44 | ||||
-rw-r--r-- | js/io/system/ninjalibrary.json | 6 |
3 files changed, 84 insertions, 7 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 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 3fb9374a..b821936f 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js | |||
@@ -55,8 +55,50 @@ exports.CoreIoApi = Montage.create(Component, { | |||
55 | handleReady: { | 55 | handleReady: { |
56 | enumerable: false, | 56 | enumerable: false, |
57 | value: function (e) { | 57 | value: function (e) { |
58 | // | ||
58 | this.chromeFileSystem.removeEventListener('ready', this, false); | 59 | this.chromeFileSystem.removeEventListener('ready', this, false); |
59 | this.chromeNinjaLibrary = this.chromeFileSystem.getLocalLibrary(); | 60 | // |
61 | this.chromeFileSystem.addEventListener('library', this, false); | ||
62 | } | ||
63 | }, | ||
64 | //////////////////////////////////////////////////////////////////// | ||
65 | // | ||
66 | handleLibrary: { | ||
67 | enumerable: false, | ||
68 | value: function (e) { | ||
69 | //Removing events | ||
70 | this.chromeFileSystem.removeEventListener('library', this, false); | ||
71 | // | ||
72 | var xhr = new XMLHttpRequest(), libs, tocopylibs = []; | ||
73 | //Getting known json list of libraries to copy to chrome | ||
74 | xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); | ||
75 | xhr.send(); | ||
76 | //Checkng for correct reponse | ||
77 | if (xhr.readyState === 4) { | ||
78 | //Parsing json libraries | ||
79 | libs = JSON.parse(xhr.response); | ||
80 | // | ||
81 | if (e._event.ninjaChromeLibrary.length > 0) { | ||
82 | //Compare | ||
83 | } else { | ||
84 | //No library is present, must copy all | ||
85 | for (var i in libs.libraries) { | ||
86 | if (libs.libraries[i].singular) { | ||
87 | tocopylibs.push({name: String(libs.libraries[i].name+libs.libraries[i].version).toLowerCase(), path: libs.libraries[i].path, singular: true}); | ||
88 | } else { | ||
89 | tocopylibs.push({name: String(libs.libraries[i].name+libs.libraries[i].version).toLowerCase(), path: libs.libraries[i].path, singular: false}); | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | // | ||
94 | if (tocopylibs.length > 0) { | ||
95 | //Copy libraries | ||
96 | } else { | ||
97 | //No libraries to copy | ||
98 | } | ||
99 | } else { | ||
100 | //Error | ||
101 | } | ||
60 | } | 102 | } |
61 | }, | 103 | }, |
62 | //////////////////////////////////////////////////////////////////// | 104 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json new file mode 100644 index 00000000..affb72a0 --- /dev/null +++ b/js/io/system/ninjalibrary.json | |||
@@ -0,0 +1,6 @@ | |||
1 | { | ||
2 | "libraries": [ | ||
3 | {"name": "Montage", "path": "/ninja-internal/node_modules/descriptor.json", "version": "0.6.0"}, | ||
4 | {"name": "RDGE", "path": "/ninja-internal/js/helper-classes/RDGE/rdge-compiled.js", "version": "0.6.0", "singular": "true"} | ||
5 | ] | ||
6 | } \ No newline at end of file | ||