Browse Source

feat: add option to reauthorize sync service automatically

Gerald 8 years ago
parent
commit
93aa36bf90

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

@@ -420,3 +420,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -422,3 +422,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: Zuletzt aktualisiert am $1
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -420,3 +420,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: Last updated at $1
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: Reauthorize automatically when expired

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

@@ -424,3 +424,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -422,3 +422,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -423,3 +423,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -420,3 +420,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -422,3 +422,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -422,3 +422,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -420,3 +420,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -425,3 +425,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: Ostatnio zaktualizowany $1
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -424,3 +424,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: 'Última atualização: $1'
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -424,3 +424,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: 'Última atualização: $1'
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -420,3 +420,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -427,3 +427,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -420,3 +420,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -424,3 +424,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -420,3 +420,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

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

@@ -418,3 +418,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: 最后更新于 $1
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: 授权失效后自动重新授权

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

@@ -418,3 +418,6 @@ labelFilterSort:
 labelLastUpdatedAt:
   description: Label shown on last updated time.
   message: ''
+labelSyncReauthorize:
+  description: Option to reauthorize sync service when expired.
+  message: ''

+ 13 - 2
src/background/sync/base.js

@@ -209,8 +209,13 @@ export const BaseService = serviceFactory({
       this.authState.set('authorized');
     }, err => {
       if (err && err.type === 'unauthorized') {
-        // _this.config.clear();
         this.authState.set('unauthorized');
+        if (this.config.get('token') && getOption('syncReauthorize') && !this.config.get('reauthorized')) {
+          this.config.set({
+            reauthorized: true,
+          });
+          this.authorize();
+        }
       } else {
         console.error(err);
         this.authState.set('error');
@@ -536,7 +541,13 @@ export function sync() {
 export function checkAuthUrl(url) {
   return serviceNames.some(name => {
     const service = services[name];
-    return service.checkAuth && service.checkAuth(url);
+    const authorized = service.checkAuth && service.checkAuth(url);
+    if (authorized) {
+      service.config.set({
+        reauthorized: false,
+      });
+    }
+    return authorized;
   });
 }
 

+ 1 - 0
src/background/utils/options.js

@@ -16,6 +16,7 @@ const defaults = {
   features: null,
   blacklist: null,
   syncScriptStatus: true,
+  syncReauthorize: true,
   sync: null,
   customCSS: null,
   importSettings: true,

+ 6 - 0
src/options/views/tab-settings/vm-sync.vue

@@ -21,6 +21,12 @@
         <span v-text="i18n('labelSyncScriptStatus')"></span>
       </label>
     </div>
+    <div class="mt-1">
+      <label>
+        <setting-check name="syncReauthorize" />
+        <span v-text="i18n('labelSyncReauthorize')"></span>
+      </label>
+    </div>
   </feature>
 </template>