Permalink
Browse files

Add setConflictResolutionPolicy checkbox to syncfs-editor

As the canary syncFileSystem API starts to automatically resolve
conflicts and to supports 'manual' and 'last_write_win' conflict
resolution policies.
  • Loading branch information...
1 parent f81ab26 commit ca5bab04d1cdc754266498919b066b739511da6e @kinu kinu committed Mar 17, 2013
Showing with 34 additions and 6 deletions.
  1. +5 −0 syncfs-editor/css/editor.css
  2. +2 −2 syncfs-editor/js/filer.js
  3. +21 −3 syncfs-editor/js/main.js
  4. +5 −0 syncfs-editor/main.html
  5. +1 −1 syncfs-editor/manifest.json
View
5 syncfs-editor/css/editor.css
@@ -21,6 +21,11 @@ body {
clear: both;
}
+#conflict-policy {
+ float: right;
+ font-size: 12px;
+}
+
#log {
color: #666;
font-size: 12px;
View
4 syncfs-editor/js/filer.js
@@ -1,7 +1,7 @@
-Filer = function(filesystem, container, editor) {
+Filer = function(filesystem, container, editor, isSyncable) {
this.filesystem = filesystem;
this.editor = editor;
- this.isSyncable = (filesystem.name.indexOf('Syncable') != -1);
+ this.isSyncable = isSyncable;
// Directory path => ul node mapping.
var nodes = {};
View
24 syncfs-editor/js/main.js
@@ -13,16 +13,18 @@ document.addEventListener(
}
);
-function onFileSystemOpened(fs) {
+function onFileSystemOpened(fs, isSyncable) {
+ log('Got Syncable FileSystem.');
console.log('Got FileSystem:' + fs.name);
var editor = new Editor(fs, 'editor');
- var filer = new Filer(fs, 'filer', editor);
+ var filer = new Filer(fs, 'filer', editor, isSyncable);
editor.filer = filer;
}
function openTemporaryFileSystem() {
$('#fs-temporary').classList.add('selected');
$('#fs-syncable').classList.remove('selected');
+ hide('#conflict-policy')
webkitRequestFileSystem(TEMPORARY, 1024,
onFileSystemOpened,
error.bind(null, 'requestFileSystem'));
@@ -36,11 +38,27 @@ function openSyncableFileSystem() {
}
$('#fs-syncable').classList.add('selected');
$('#fs-temporary').classList.remove('selected');
+ if (chrome.syncFileSystem.setConflictResolutionPolicy) {
+ chrome.syncFileSystem.setConflictResolutionPolicy('last_write_win');
+ show('#conflict-policy')
+ }
+ log('Obtaining syncable FileSystem...');
chrome.syncFileSystem.requestFileSystem(function (fs) {
if (chrome.runtime.lastError) {
error('requestFileSystem: ' + chrome.runtime.lastError.message);
+ $('#fs-syncable').classList.remove('selected');
+ hide('#conflict-policy')
return;
}
- onFileSystemOpened(fs);
+ onFileSystemOpened(fs, true);
});
}
+
+$('#conflict-policy').addEventListener('click', function() {
+ if ($('#auto-conflict-resolve').checked)
+ policy = 'last_write_win';
+ else
+ policy = 'manual';
+ chrome.syncFileSystem.setConflictResolutionPolicy(policy);
+ log('Changed conflict resolution policy to: ' + policy);
+});
View
5 syncfs-editor/main.html
@@ -11,6 +11,11 @@
</head>
<body>
<div id="fs-selector">
+ <div id="conflict-policy" class="hide">
+ <input id="auto-conflict-resolve" type="checkbox" checked>
+ Resolves Conflicts Automatically
+ </input>
+ </div>
<button id="fs-syncable" class="fs-button">Syncable</button>
<button id="fs-temporary" class="fs-button">Temporary</button>
</div>
View
2 syncfs-editor/manifest.json
@@ -1,6 +1,6 @@
{
"name": "SyncFS editor",
- "version": "0.286",
+ "version": "0.287",
"manifest_version": 2,
"description": "SyncFS editor (syncFileSystem sample)",
"icons": {

0 comments on commit ca5bab0

Please sign in to comment.