Index: lib/io.js |
=================================================================== |
--- a/lib/io.js |
+++ b/lib/io.js |
@@ -26,48 +26,23 @@ |
function loadFile(fileName) |
{ |
- return new Promise((resolve, reject) => |
+ let key = fileToKey(fileName); |
+ return browser.storage.local.get(key).then(items => |
{ |
- let key = fileToKey(fileName); |
- |
- ext.storage.get(key, items => |
- { |
- let entry = items[key]; |
- |
- if (entry) |
- resolve(entry); |
- else |
- reject({type: "NoSuchFile"}); |
- }); |
+ let entry = items[key]; |
+ if (entry) |
+ return entry; |
+ throw {type: "NoSuchFile"}; |
kzar
2018/04/24 20:38:56
Don't we normally throw an Error instance? (I get
Sebastian Noack
2018/04/24 21:12:55
Yeah, I had a similar WTF moment when I converted
kzar
2018/04/25 10:33:39
Acknowledged.
|
}); |
} |
function saveFile(fileName, data) |
{ |
- return new Promise((resolve, reject) => |
- { |
- ext.storage.set( |
- fileToKey(fileName), |
- { |
- content: Array.from(data), |
- lastModified: Date.now() |
- }, |
- resolve |
- ); |
- }); |
-} |
- |
-function removeFile(fileName) |
-{ |
- return new Promise((resolve, reject) => |
- { |
- ext.storage.remove(fileToKey(fileName), () => |
- { |
- if (browser.runtime.lastError) |
- reject(browser.runtime.lastError.message); |
- else |
- resolve(); |
- }); |
+ return browser.storage.local.set({ |
+ [fileToKey(fileName)]: { |
+ content: Array.from(data), |
+ lastModified: Date.now() |
+ } |
}); |
} |
@@ -131,19 +106,9 @@ |
*/ |
renameFile(fromFile, newName) |
{ |
- return loadFile(fromFile).then(entry => |
- { |
- return new Promise((resolve, reject) => |
- { |
- ext.storage.set(fileToKey(newName), entry, () => |
- { |
- if (browser.runtime.lastError) |
- reject(browser.runtime.lastError.message); |
- else |
- resolve(); |
- }); |
- }); |
- }).then(() => removeFile(fromFile)); |
+ return loadFile(fromFile) |
+ .then(entry => browser.storage.local.set({[fileToKey(newName)]: entry})) |
+ .then(() => this.removeFile(fromFile)); |
}, |
/** |
@@ -155,7 +120,7 @@ |
*/ |
removeFile(fileName) |
{ |
- return removeFile(fileName); |
+ return browser.storage.local.remove(fileToKey(fileName)); |
}, |
/** |