Index: lib/io.js |
=================================================================== |
--- a/lib/io.js |
+++ b/lib/io.js |
@@ -25,30 +25,44 @@ |
function loadFile(file, successCallback, errorCallback) |
{ |
let key = fileToKey(file); |
- |
kzar
2016/12/20 11:09:01
Nit: Mind adding this blank line back in?
Oleksandr
2016/12/20 14:36:50
Done.
|
- ext.storage.get([key], function(items) |
+ // Make sure we do not have subscriptions in localStorage from older |
+ // versions first |
+ let entry = localStorage.getItem(key); |
+ if (typeof entry == "string") |
{ |
- let entry = items[key]; |
- |
- if (entry) |
- successCallback(entry); |
+ try |
+ { |
+ entry = JSON.parse(entry); |
+ } |
+ catch(err) |
+ { |
+ setTimeout(errorCallback(new Error("File is corrupted"))); |
+ return; |
+ } |
+ setTimeout(successCallback(entry)); |
+ return; |
+ } |
+ // Now try to read from IndexedDB |
+ localforage.getItem(key, function(err, value) |
+ { |
+ if (err || !value) |
+ errorCallback(new Error("File doesn't exist")); |
else |
- errorCallback(new Error("File doesn't exist")); |
+ successCallback(value); |
}); |
} |
function saveFile(file, data, callback) |
{ |
- ext.storage.set( |
- fileToKey(file), |
- { |
- content: Array.from(data), |
- lastModified: Date.now() |
- }, |
- callback |
- ); |
+ var key = fileToKey(file); |
+ var entry = { |
+ lastModified: Date.now(), |
kzar
2016/12/20 11:09:01
Nit: Mind putting these keys lastModified and cont
Oleksandr
2016/12/20 14:36:50
Done.
|
+ content: Array.from(data) |
+ }; |
+ |
+ localStorage.removeItem(key); |
+ localforage.setItem(key, entry, callback); |
} |
- |
kzar
2016/12/20 11:09:01
Nit: Mind adding this blank line back in?
Oleksandr
2016/12/20 14:36:50
Done.
|
exports.IO = |
{ |
resolveFilePath: function(path) |
@@ -60,9 +74,11 @@ |
{ |
function onLoaded(entry) |
{ |
- for (let line of entry.content) |
- listener.process(line); |
- |
+ if ("content" in entry) |
+ { |
+ for (let line of entry.content) |
+ listener.process(line); |
+ } |
listener.process(null); |
callback(null); |
} |