From 777d47a2751336948b957a84f5ccf975ca786103 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Mon, 3 Dec 2018 21:22:01 -0600 Subject: [PATCH 1/7] fix chrome drive sync issues --- src/models/backup.ts | 47 ++++++++++++++++++++++++++++++++------------ src/ui/backup.ts | 8 ++++---- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/models/backup.ts b/src/models/backup.ts index 17e459792..e1f273c22 100644 --- a/src/models/backup.ts +++ b/src/models/backup.ts @@ -83,7 +83,9 @@ class Drive { const res = JSON.parse(xhr.responseText); if (res.error) { if (res.error.code === 401) { - localStorage.driveToken = ''; + if (navigator.userAgent.indexOf('Chrome') === -1) { + localStorage.driveToken = ''; + } resolve(true); } } else { @@ -106,18 +108,37 @@ class Drive { async refreshToken() { if (navigator.userAgent.indexOf('Chrome') !== -1) { return new Promise((resolve: (value: boolean) => void) => { - return chrome.identity.getAuthToken( - { - 'interactive': false, - 'scopes': ['https://www.googleapis.com/auth/drive.file'] - }, - (token) => { - localStorage.driveToken = token; - if (!Boolean(token)) { - localStorage.driveRevoked = true; - } - resolve(Boolean(token)); - }); + if (localStorage.driveToken) { + chrome.identity.removeCachedAuthToken( + {'token': localStorage.driveToken}, () => { + localStorage.driveToken = ''; + return chrome.identity.getAuthToken( + { + 'interactive': false, + 'scopes': ['https://www.googleapis.com/auth/drive.file'] + }, + (token) => { + localStorage.driveToken = token; + if (!Boolean(token)) { + localStorage.driveRevoked = true; + } + resolve(Boolean(token)); + }); + }); + } else { + return chrome.identity.getAuthToken( + { + 'interactive': false, + 'scopes': ['https://www.googleapis.com/auth/drive.file'] + }, + (token) => { + localStorage.driveToken = token; + if (!Boolean(token)) { + localStorage.driveRevoked = true; + } + resolve(Boolean(token)); + }); + } }); } else { return new Promise( diff --git a/src/ui/backup.ts b/src/ui/backup.ts index 9b59ed814..0f92c633d 100644 --- a/src/ui/backup.ts +++ b/src/ui/backup.ts @@ -19,7 +19,7 @@ async function backup(_ui: UI) { _ui.instance.alert(_ui.instance.i18n.updateSuccess); } else if (localStorage.dropboxRevoked === 'true') { _ui.instance.alert(String(_ui.instance.i18n.token_revoked) - .replace(/\${service}/, 'Dropbox')); + .replace(/\$?{?service}/, 'Dropbox')); localStorage.removeItem('dropboxRevoked'); } else { _ui.instance.alert(_ui.instance.i18n.updateFailure); @@ -31,7 +31,7 @@ async function backup(_ui: UI) { _ui.instance.alert(_ui.instance.i18n.updateSuccess); } else if (localStorage.driveRevoked === 'true') { _ui.instance.alert(String(_ui.instance.i18n.token_revoked) - .replace(/\${service}/, 'Google Drive')); + .replace(/\$?{?service}/, 'Google Drive')); localStorage.removeItem('driveRevoked'); } else { _ui.instance.alert(_ui.instance.i18n.updateFailure); @@ -108,7 +108,7 @@ async function backup(_ui: UI) { } else if (localStorage.dropboxRevoked === 'true') { _ui.instance.alert( String(_ui.instance.i18n.token_revoked) - .replace(/\${service}/, 'Dropbox')); + .replace(/\$?{?service}/, 'Dropbox')); localStorage.removeItem('dropboxRevoked'); } } catch (error) { @@ -138,7 +138,7 @@ async function backup(_ui: UI) { } else if (localStorage.driveRevoked === 'true') { _ui.instance.alert( String(_ui.instance.i18n.token_revoked) - .replace(/\${service}/, 'Google Drive')); + .replace(/\$?{?service}/, 'Google Drive')); localStorage.removeItem('driveRevoked'); } } catch (error) { From 416e8d399db2460c93ed8671b8afbfd3f0e2b9e8 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Thu, 20 Dec 2018 15:37:24 -0600 Subject: [PATCH 2/7] review fixes --- _locales/cs/messages.json | 12 +++++++++--- _locales/de/messages.json | 10 ++++++++-- _locales/el/messages.json | 10 ++++++++-- _locales/en/messages.json | 10 ++++++++-- _locales/es/messages.json | 12 +++++++++--- _locales/fr/messages.json | 12 +++++++++--- _locales/id/messages.json | 12 +++++++++--- _locales/it/messages.json | 12 +++++++++--- _locales/ja/messages.json | 10 ++++++++-- _locales/nl/messages.json | 12 +++++++++--- _locales/pl/messages.json | 12 +++++++++--- _locales/pt_BR/messages.json | 12 +++++++++--- _locales/ru/messages.json | 12 +++++++++--- _locales/sv/messages.json | 12 +++++++++--- _locales/tr/messages.json | 12 +++++++++--- _locales/vi/messages.json | 12 +++++++++--- _locales/zh_CN/messages.json | 12 +++++++++--- _locales/zh_TW/messages.json | 12 +++++++++--- src/ui/backup.ts | 13 +++++-------- 19 files changed, 163 insertions(+), 58 deletions(-) diff --git a/_locales/cs/messages.json b/_locales/cs/messages.json index b369f38f9..9e012952a 100644 --- a/_locales/cs/messages.json +++ b/_locales/cs/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/de/messages.json b/_locales/de/messages.json index 5310c715a..33790246e 100644 --- a/_locales/de/messages.json +++ b/_locales/de/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } } diff --git a/_locales/el/messages.json b/_locales/el/messages.json index 4aa1af2b8..e0336cce5 100644 --- a/_locales/el/messages.json +++ b/_locales/el/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } } diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 141d4a2e3..54985c2f9 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } } diff --git a/_locales/es/messages.json b/_locales/es/messages.json index c77faa550..6523973bb 100644 --- a/_locales/es/messages.json +++ b/_locales/es/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index 03db2d9f1..0b849b5cf 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/id/messages.json b/_locales/id/messages.json index 085df401c..bdbbb8f7a 100644 --- a/_locales/id/messages.json +++ b/_locales/id/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/it/messages.json b/_locales/it/messages.json index 48d362650..07f26be01 100644 --- a/_locales/it/messages.json +++ b/_locales/it/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/ja/messages.json b/_locales/ja/messages.json index b495a345a..c8c9ac7f1 100644 --- a/_locales/ja/messages.json +++ b/_locales/ja/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } } diff --git a/_locales/nl/messages.json b/_locales/nl/messages.json index d8c73b86f..fe4f82d69 100644 --- a/_locales/nl/messages.json +++ b/_locales/nl/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "Er was een probleem verbinding met uw account ${service}, log opnieuw in.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "Er was een probleem verbinding met uw account $SERVICE$, log opnieuw in.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/pl/messages.json b/_locales/pl/messages.json index 3d663b632..d05112143 100644 --- a/_locales/pl/messages.json +++ b/_locales/pl/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "Wystąpił problem z połączeniem z twoim kontem ${service}, zaloguj się ponownie.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "Wystąpił problem z połączeniem z twoim kontem $SERVICE$, zaloguj się ponownie.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/pt_BR/messages.json b/_locales/pt_BR/messages.json index 60f957c2e..9ac861b74 100644 --- a/_locales/pt_BR/messages.json +++ b/_locales/pt_BR/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "Houve um problema na conexão com sua conta do ${service}, por favor tente novamente.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "Houve um problema na conexão com sua conta do $SERVICE$, por favor tente novamente.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/ru/messages.json b/_locales/ru/messages.json index 6442fdeab..1ef1cb55e 100644 --- a/_locales/ru/messages.json +++ b/_locales/ru/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "Существует проблема подключения к вашей учетной записи ${service} , пожалуйста войдите в систему снова.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "Существует проблема подключения к вашей учетной записи $SERVICE$ , пожалуйста войдите в систему снова.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/sv/messages.json b/_locales/sv/messages.json index 687fc080f..c140da862 100644 --- a/_locales/sv/messages.json +++ b/_locales/sv/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/tr/messages.json b/_locales/tr/messages.json index 4b0767fef..e34ac3795 100644 --- a/_locales/tr/messages.json +++ b/_locales/tr/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/vi/messages.json b/_locales/vi/messages.json index 8d653e8a5..a86effad4 100644 --- a/_locales/vi/messages.json +++ b/_locales/vi/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "Có một vấn đề kết nối với tài khoản ${service} , xin vui lòng đăng nhập lại.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "Có một vấn đề kết nối với tài khoản $SERVICE$ , xin vui lòng đăng nhập lại.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/zh_CN/messages.json b/_locales/zh_CN/messages.json index ecf825ac1..03e32fc57 100644 --- a/_locales/zh_CN/messages.json +++ b/_locales/zh_CN/messages.json @@ -300,7 +300,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/_locales/zh_TW/messages.json b/_locales/zh_TW/messages.json index 18fed0afd..4f282c6e2 100644 --- a/_locales/zh_TW/messages.json +++ b/_locales/zh_TW/messages.json @@ -276,7 +276,13 @@ "description": "Sign out of 3rd party storage services" }, "token_revoked": { - "message": "There was an issue connecting to your ${service} account, please sign in again.", - "description": "Error authenticating to backup service. ${service} will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')" + "message": "There was an issue connecting to your $SERVICE$ account, please sign in again.", + "description": "Error authenticating to backup service. $SERVICE$ will be replaced with a proper noun (E.g.: 'Google Drive' or 'Dropbox')", + "placeholders": { + "service": { + "content": "$1", + "example": "Google Drive" + } + } } -} \ No newline at end of file +} diff --git a/src/ui/backup.ts b/src/ui/backup.ts index 0f92c633d..cca919c4d 100644 --- a/src/ui/backup.ts +++ b/src/ui/backup.ts @@ -18,8 +18,8 @@ async function backup(_ui: UI) { if (response === true) { _ui.instance.alert(_ui.instance.i18n.updateSuccess); } else if (localStorage.dropboxRevoked === 'true') { - _ui.instance.alert(String(_ui.instance.i18n.token_revoked) - .replace(/\$?{?service}/, 'Dropbox')); + _ui.instance.alert( + chrome.i18n.getMessage('token_revoked', ['Dropbox'])); localStorage.removeItem('dropboxRevoked'); } else { _ui.instance.alert(_ui.instance.i18n.updateFailure); @@ -30,8 +30,7 @@ async function backup(_ui: UI) { if (response === true) { _ui.instance.alert(_ui.instance.i18n.updateSuccess); } else if (localStorage.driveRevoked === 'true') { - _ui.instance.alert(String(_ui.instance.i18n.token_revoked) - .replace(/\$?{?service}/, 'Google Drive')); + _ui.instance.alert(chrome.i18n.getMessage('token_revoked', ['Google Drive'])); localStorage.removeItem('driveRevoked'); } else { _ui.instance.alert(_ui.instance.i18n.updateFailure); @@ -107,8 +106,7 @@ async function backup(_ui: UI) { return; } else if (localStorage.dropboxRevoked === 'true') { _ui.instance.alert( - String(_ui.instance.i18n.token_revoked) - .replace(/\$?{?service}/, 'Dropbox')); + chrome.i18n.getMessage('token_revoked', ['Dropbox'])); localStorage.removeItem('dropboxRevoked'); } } catch (error) { @@ -137,8 +135,7 @@ async function backup(_ui: UI) { return; } else if (localStorage.driveRevoked === 'true') { _ui.instance.alert( - String(_ui.instance.i18n.token_revoked) - .replace(/\$?{?service}/, 'Google Drive')); + chrome.i18n.getMessage('token_revoked', ['Google Drive'])); localStorage.removeItem('driveRevoked'); } } catch (error) { From 6d03517a62cf92e3757b296493523cee2cc4c80f Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Thu, 20 Dec 2018 15:38:58 -0600 Subject: [PATCH 3/7] gts fix --- src/ui/backup.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui/backup.ts b/src/ui/backup.ts index cca919c4d..6a3a25df5 100644 --- a/src/ui/backup.ts +++ b/src/ui/backup.ts @@ -30,7 +30,8 @@ async function backup(_ui: UI) { if (response === true) { _ui.instance.alert(_ui.instance.i18n.updateSuccess); } else if (localStorage.driveRevoked === 'true') { - _ui.instance.alert(chrome.i18n.getMessage('token_revoked', ['Google Drive'])); + _ui.instance.alert( + chrome.i18n.getMessage('token_revoked', ['Google Drive'])); localStorage.removeItem('driveRevoked'); } else { _ui.instance.alert(_ui.instance.i18n.updateFailure); @@ -106,7 +107,7 @@ async function backup(_ui: UI) { return; } else if (localStorage.dropboxRevoked === 'true') { _ui.instance.alert( - chrome.i18n.getMessage('token_revoked', ['Dropbox'])); + chrome.i18n.getMessage('token_revoked', ['Dropbox'])); localStorage.removeItem('dropboxRevoked'); } } catch (error) { @@ -134,8 +135,8 @@ async function backup(_ui: UI) { localStorage.lastRemindingBackupTime = clientTime; return; } else if (localStorage.driveRevoked === 'true') { - _ui.instance.alert( - chrome.i18n.getMessage('token_revoked', ['Google Drive'])); + _ui.instance.alert(chrome.i18n.getMessage( + 'token_revoked', ['Google Drive'])); localStorage.removeItem('driveRevoked'); } } catch (error) { From bc0056af999ae06efebd955fb24955b400f245e4 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Thu, 20 Dec 2018 16:04:39 -0600 Subject: [PATCH 4/7] fix lintspaces --- .travis.yml | 2 +- src/models/credentials.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6d1b87f27..a36f9af6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ jobs: script: "gts check" - stage: test name: "lintspaces" - script: "npm i -g lintspaces-cli && lintspaces -nt -d 'spaces' -i 'js-comments' src/* view/* manifest-*.json css/popup.css css/import.css" + script: "npm i -g lintspaces-cli && lintspaces -nt -d 'spaces' -i 'js-comments' src/*/* src/*.ts view/* manifest-*.json css/popup.css css/import.css" env: CACHE_NAME=LINTSPACES - stage: test name: "Build Firefox and run addons-linter" diff --git a/src/models/credentials.ts b/src/models/credentials.ts index b5a1134f4..440d335a9 100644 --- a/src/models/credentials.ts +++ b/src/models/credentials.ts @@ -9,4 +9,4 @@ function getCredentials() { client_id: 'mmx38seexw3tvps' // Dropbox client ID } }; -} \ No newline at end of file +} From cd95c066d6cfa3c6476bf4976e308e7baa437445 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Tue, 25 Dec 2018 12:58:54 -0600 Subject: [PATCH 5/7] refactor --- src/models/backup.ts | 51 +++++++++++++++----------------------------- src/ui/backup.ts | 2 ++ 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/src/models/backup.ts b/src/models/backup.ts index e1f273c22..394be4244 100644 --- a/src/models/backup.ts +++ b/src/models/backup.ts @@ -77,15 +77,17 @@ class Drive { xhr.open('GET', 'https://www.googleapis.com/drive/v3/files'); xhr.setRequestHeader( 'Authorization', 'Bearer ' + localStorage.driveToken); - xhr.onreadystatechange = () => { + xhr.onreadystatechange = async () => { if (xhr.readyState === 4) { try { const res = JSON.parse(xhr.responseText); if (res.error) { if (res.error.code === 401) { - if (navigator.userAgent.indexOf('Chrome') === -1) { - localStorage.driveToken = ''; + if (navigator.userAgent.indexOf('Chrome') !== -1) { + await chrome.identity.removeCachedAuthToken( + {'token': localStorage.driveToken}); } + localStorage.driveToken = ''; resolve(true); } } else { @@ -108,37 +110,18 @@ class Drive { async refreshToken() { if (navigator.userAgent.indexOf('Chrome') !== -1) { return new Promise((resolve: (value: boolean) => void) => { - if (localStorage.driveToken) { - chrome.identity.removeCachedAuthToken( - {'token': localStorage.driveToken}, () => { - localStorage.driveToken = ''; - return chrome.identity.getAuthToken( - { - 'interactive': false, - 'scopes': ['https://www.googleapis.com/auth/drive.file'] - }, - (token) => { - localStorage.driveToken = token; - if (!Boolean(token)) { - localStorage.driveRevoked = true; - } - resolve(Boolean(token)); - }); - }); - } else { - return chrome.identity.getAuthToken( - { - 'interactive': false, - 'scopes': ['https://www.googleapis.com/auth/drive.file'] - }, - (token) => { - localStorage.driveToken = token; - if (!Boolean(token)) { - localStorage.driveRevoked = true; - } - resolve(Boolean(token)); - }); - } + return chrome.identity.getAuthToken( + { + 'interactive': false, + 'scopes': ['https://www.googleapis.com/auth/drive.file'] + }, + (token) => { + localStorage.driveToken = token; + if (!Boolean(token)) { + localStorage.driveRevoked = true; + } + resolve(Boolean(token)); + }); }); } else { return new Promise( diff --git a/src/ui/backup.ts b/src/ui/backup.ts index 6a3a25df5..f0b922f81 100644 --- a/src/ui/backup.ts +++ b/src/ui/backup.ts @@ -21,6 +21,7 @@ async function backup(_ui: UI) { _ui.instance.alert( chrome.i18n.getMessage('token_revoked', ['Dropbox'])); localStorage.removeItem('dropboxRevoked'); + _ui.instance.dropboxToken = ''; } else { _ui.instance.alert(_ui.instance.i18n.updateFailure); } @@ -33,6 +34,7 @@ async function backup(_ui: UI) { _ui.instance.alert( chrome.i18n.getMessage('token_revoked', ['Google Drive'])); localStorage.removeItem('driveRevoked'); + _ui.instance.driveToken = ''; } else { _ui.instance.alert(_ui.instance.i18n.updateFailure); } From d69a3a86baed6e8b25981811f4783ab3d0960c39 Mon Sep 17 00:00:00 2001 From: mymindstorm <27789806+mymindstorm@users.noreply.github.com> Date: Sat, 5 Jan 2019 19:34:30 -0600 Subject: [PATCH 6/7] Update backup.ts --- src/models/backup.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/models/backup.ts b/src/models/backup.ts index 394be4244..07a38ae86 100644 --- a/src/models/backup.ts +++ b/src/models/backup.ts @@ -84,6 +84,7 @@ class Drive { if (res.error) { if (res.error.code === 401) { if (navigator.userAgent.indexOf('Chrome') !== -1) { + // Clear invalid token from chrome://identity-internals/ await chrome.identity.removeCachedAuthToken( {'token': localStorage.driveToken}); } From 87673ced03bb9b7bf4c0638a375ca35178c29712 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Tue, 15 Jan 2019 15:05:16 -0600 Subject: [PATCH 7/7] gts fix --- src/models/backup.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/models/backup.ts b/src/models/backup.ts index 07a38ae86..f3ab14fb9 100644 --- a/src/models/backup.ts +++ b/src/models/backup.ts @@ -84,7 +84,8 @@ class Drive { if (res.error) { if (res.error.code === 401) { if (navigator.userAgent.indexOf('Chrome') !== -1) { - // Clear invalid token from chrome://identity-internals/ + // Clear invalid token from + // chrome://identity-internals/ await chrome.identity.removeCachedAuthToken( {'token': localStorage.driveToken}); }