Browse Source

feat: add retry button for sync

Gerald 9 years ago
parent
commit
45fabe2952

+ 9 - 1
src/background/main.js

@@ -128,7 +128,15 @@ var commands = {
     return false;
   },
   SyncStart: function (data, src) {
-    sync.sync();
+    if (data) {
+      var service = sync.service(data);
+      if (service) {
+        if (service.authState.is('error')) service.init();
+        else sync.sync(service);
+      }
+    } else {
+      sync.sync();
+    }
     return false;
   },
 };

+ 1 - 0
src/background/sync/dropbox.js

@@ -23,6 +23,7 @@ setTimeout(function () {
   function init() {
     dropbox.inst = null;
     dropbox.authState.set('initializing');
+    dropbox.syncState.set('idle');
     var token = dropbox.config.get('token');
     if (token) {
       dropbox.inst = new Dropbox(token);

+ 3 - 0
src/background/sync/index.js

@@ -71,6 +71,9 @@ var sync = function () {
         }
         return state;
       },
+      is: function (_state) {
+        return state === _state;
+      },
     };
   }
   function onStateChange() {

+ 3 - 0
src/options/templates/sync-service.html

@@ -9,6 +9,9 @@
 <button data-auth="<%= it.name %>" <%= it.unauthorized ? '' : 'disabled' %>><%=
   it.authorized ? _.i18n('buttonAuthorized') : _.i18n('buttonAuthorize')
 %></button>
+<button <%= !_.includes(['authorized', 'error'], it.authState) || it.syncing ? 'disabled' : '' %> class="sync-start">
+  <i class="fa fa-refresh"></i>
+</button>
 <span><%=
   it.initializing ? _.i18n('msgSyncInit') :
   it.error ? _.i18n('msgSyncError') :

+ 9 - 0
src/options/views/sync-service.js

@@ -1,5 +1,8 @@
 var SyncServiceView = BaseView.extend({
   templateUrl: '/options/templates/sync-service.html',
+  events: {
+    'click .sync-start': 'retry',
+  },
   _render: function () {
     var it = this.model.toJSON();
     it.initializing = it.authState === 'initializing';
@@ -10,4 +13,10 @@ var SyncServiceView = BaseView.extend({
     it.lastSync = it.timestamp && new Date(it.timestamp).toLocaleString();
     this.$el.html(this.templateFn(it));
   },
+  retry: function () {
+    _.sendMessage({
+      cmd: 'SyncStart',
+      data: this.model.get('name'),
+    });
+  },
 });