2013-12-04 18:52:56 +00:00
|
|
|
define([
|
|
|
|
"storage/syncFS",
|
2013-12-23 18:27:33 +00:00
|
|
|
"command",
|
|
|
|
"util/manos"
|
|
|
|
], function(sync, command, M) {
|
2013-12-05 07:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
SyncFile is a wrapper around Chrome's synchronized storage use the same
|
|
|
|
interface as the File module. This means you can assign a SyncFile
|
|
|
|
containing Caret's settings JSON to a tab just as you would a regular file,
|
|
|
|
and the tab can read/write from it without any customization. The one
|
|
|
|
difference is the virtual flag, which is used to prevent some file-only
|
|
|
|
behaviors (such as retainEntry calls).
|
|
|
|
|
|
|
|
As soon as chrome.syncFileSystem allows us to create a filesystem even if
|
|
|
|
the device is offline for the first request, we'll swap these over to a
|
|
|
|
wrapper around file entries from that storage. The change should remain
|
|
|
|
entirely transparent as far as other modules are concerned, although there
|
|
|
|
are some abstraction leaks in settings.js that we'll need to handle.
|
|
|
|
|
|
|
|
*/
|
2013-12-04 18:52:56 +00:00
|
|
|
|
|
|
|
var SyncFile = function(name, c) {
|
|
|
|
this.entry = {};
|
|
|
|
if (name) {
|
|
|
|
this.open(name, c);
|
|
|
|
}
|
|
|
|
this.virtual = true;
|
|
|
|
};
|
|
|
|
SyncFile.prototype = {
|
|
|
|
name: "",
|
2014-05-04 09:09:19 +00:00
|
|
|
open: function(name, c) {
|
2013-12-04 18:52:56 +00:00
|
|
|
this.name = name;
|
|
|
|
this.entry.name = name;
|
2014-05-04 09:09:19 +00:00
|
|
|
if (c) c(null, this);
|
2013-12-04 18:52:56 +00:00
|
|
|
},
|
2014-05-04 09:09:19 +00:00
|
|
|
read: function(c) {
|
2013-12-04 18:52:56 +00:00
|
|
|
var name = this.name;
|
2014-05-04 09:09:19 +00:00
|
|
|
sync.get(this.name).then(function(data) {
|
|
|
|
c(null, data);
|
|
|
|
});
|
2013-12-04 18:52:56 +00:00
|
|
|
},
|
2014-05-04 09:09:19 +00:00
|
|
|
write: function(content, c) {
|
2013-12-23 18:27:33 +00:00
|
|
|
return sync.set(this.name, content).then(function() {
|
2013-12-04 18:52:56 +00:00
|
|
|
command.fire("settings:change-local");
|
2014-05-04 09:09:19 +00:00
|
|
|
c();
|
2013-12-04 18:52:56 +00:00
|
|
|
});
|
|
|
|
},
|
2013-12-23 18:27:33 +00:00
|
|
|
retain: function() { return false; },
|
2014-05-04 09:09:19 +00:00
|
|
|
restore: function(c) { c("Cannot restore sync storage files") }
|
2013-12-04 18:52:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return SyncFile;
|
|
|
|
|
|
|
|
});
|