Browse Source

fix sync button statuses

Gerald 9 years ago
parent
commit
cf1c93869f

+ 3 - 0
src/_locales/cs/messages.yml

@@ -343,6 +343,9 @@ lastSync:
 msgSyncInit:
   description: Message shown when sync service is initializing.
   message: ''
+msgSyncInitError:
+  description: Message shown when sync fails in initialization.
+  message: ''
 msgSyncReady:
   description: Message shown when sync will start soon.
   message: ''

+ 3 - 0
src/_locales/de/messages.yml

@@ -343,6 +343,9 @@ lastSync:
 msgSyncInit:
   description: Message shown when sync service is initializing.
   message: ''
+msgSyncInitError:
+  description: Message shown when sync fails in initialization.
+  message: ''
 msgSyncReady:
   description: Message shown when sync will start soon.
   message: ''

+ 3 - 0
src/_locales/en/messages.yml

@@ -345,6 +345,9 @@ lastSync:
 msgSyncInit:
   description: Message shown when sync service is initializing.
   message: Initializing...
+msgSyncInitError:
+  description: Message shown when sync fails in initialization.
+  message: 'Initializing error!'
 msgSyncReady:
   description: Message shown when sync will start soon.
   message: Sync will start soon...

+ 3 - 0
src/_locales/pl/messages.yml

@@ -343,6 +343,9 @@ lastSync:
 msgSyncInit:
   description: Message shown when sync service is initializing.
   message: ''
+msgSyncInitError:
+  description: Message shown when sync fails in initialization.
+  message: ''
 msgSyncReady:
   description: Message shown when sync will start soon.
   message: ''

+ 3 - 0
src/_locales/ru/messages.yml

@@ -345,6 +345,9 @@ lastSync:
 msgSyncInit:
   description: Message shown when sync service is initializing.
   message: ''
+msgSyncInitError:
+  description: Message shown when sync fails in initialization.
+  message: ''
 msgSyncReady:
   description: Message shown when sync will start soon.
   message: ''

+ 3 - 0
src/_locales/zh/messages.yml

@@ -345,6 +345,9 @@ lastSync:
 msgSyncInit:
   description: Message shown when sync service is initializing.
   message: 正在初始化...
+msgSyncInitError:
+  description: Message shown when sync fails in initialization.
+  message: 初始化失败!
 msgSyncReady:
   description: Message shown when sync will start soon.
   message: 即将开始同步...

+ 1 - 9
src/background/main.js

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

+ 13 - 7
src/background/sync/index.js

@@ -230,15 +230,9 @@ var sync = function () {
       _this.authState.set('initializing');
       var token = _this.token = _this.config.get('token');
       _this.initHeaders();
-      return token ? Promise.resolve(_this.user()) : Promise.reject();
-    },
-    checkSync: function () {
-      var _this = this;
-      return _this.prepare()
+      return (token ? Promise.resolve(_this.user()) : Promise.reject())
       .then(function () {
         _this.authState.set('authorized');
-        servicesReady.push(_this);
-        return _this.startSync();
       }, function (err) {
         if (err) {
           if (err.status === 401) {
@@ -252,6 +246,18 @@ var sync = function () {
         } else {
           _this.authState.set('unauthorized');
         }
+        throw err;
+      });
+    },
+    checkSync: function () {
+      var _this = this;
+      return _this.prepare()
+      .then(function () {
+        servicesReady.push(_this);
+        return _this.startSync();
+      }, function () {
+        var i = servicesReady.indexOf(_this);
+        if (~i) servicesReady.splice(i, 1);
       });
     },
     user: function () {},

+ 4 - 4
src/options/templates/sync-service.html

@@ -1,8 +1,6 @@
 <label>
   <input type=checkbox data-check="<%= it.name + 'Enabled' %>" data-sync="<%= it.name %>" <%=
   it.enabled ? 'checked' : ''
-  %> <%=
-  it.authState === 'authorized' ? '' : 'disabled'
   %>>
   <span><%= _.i18n('labelSyncTo', it.displayName || it.name) %></span>
 </label>
@@ -15,13 +13,15 @@
   }[it.authState] || _.i18n('buttonAuthorize')
 %></button>
 <button <%=
-!_.includes(['authorized', 'error'], it.authState) ||
-it.syncState === 'syncing' ? 'disabled' : ''
+  !_.includes(['authorized', 'error'], it.authState) ||
+  _.includes(['ready', 'syncing'], it.syncState)
+  ? 'disabled' : ''
 %> class="sync-start">
   <i class="fa fa-refresh"></i>
 </button>
 <span><%=
   it.authState === 'initializing' ? _.i18n('msgSyncInit') :
+  it.authState === 'error' ? _.i18n('msgSyncInitError') :
   it.syncState === 'error' ? _.i18n('msgSyncError') :
   it.syncState === 'ready' ? _.i18n('msgSyncReady') :
   it.syncState === 'syncing' ? _.i18n('msgSyncing') :