Index: lib/io.js |
=================================================================== |
--- a/lib/io.js |
+++ b/lib/io.js |
@@ -28,32 +28,22 @@ |
{ |
return new Promise((resolve, reject) => |
{ |
- let key = fileToKey(fileName); |
- |
- ext.storage.get(key, items => |
+ localforage.getItem(fileToKey(fileName), (err, value) => |
{ |
- let entry = items[key]; |
- |
- if (entry) |
- resolve(entry); |
+ if (err || !value) |
+ reject({type: "NoSuchFile"}); |
else |
- reject({type: "NoSuchFile"}); |
+ resolve(value); |
}); |
}); |
} |
function saveFile(fileName, data) |
{ |
- return new Promise((resolve, reject) => |
- { |
- ext.storage.set( |
- fileToKey(fileName), |
- { |
- content: Array.from(data), |
- lastModified: Date.now() |
- }, |
- resolve |
- ); |
+ let key = fileToKey(fileName); |
+ return localforage.setItem(key, { |
+ content: Array.from(data), |
+ lastModified: Date.now() |
}); |
} |
@@ -86,8 +76,11 @@ |
{ |
return loadFile(fileName).then(entry => |
{ |
- for (let line of entry.content) |
- listener(line); |
+ if ("content" in entry) |
+ { |
+ for (let line of entry.content) |
+ listener(line); |
+ } |
}); |
}, |
@@ -133,16 +126,7 @@ |
{ |
return loadFile(fromFile).then(entry => |
{ |
- return new Promise((resolve, reject) => |
- { |
- ext.storage.set(fileToKey(newName), entry, () => |
- { |
- if (chrome.runtime.lastError) |
- reject(chrome.runtime.lastError.message); |
- else |
- resolve(); |
- }); |
- }); |
+ return saveFile(fileToKey(newName), entry); |
}).then(() => removeFile(fromFile)); |
}, |