From 16585331d475d7e09721ead758abe34be82ebea7 Mon Sep 17 00:00:00 2001 From: Matheus Faustino Date: Sun, 17 Mar 2019 21:32:08 -0300 Subject: [PATCH] Dropbox workaround for Firefox on Android --- manifest.json | 3 +++ sync/dropbox-auth-receiver.js | 11 +++++++++++ sync/dropbox-oauth.html | 12 ++++++++++++ sync/import-export-dropbox.js | 20 +++++++++++++------- 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 sync/dropbox-auth-receiver.js create mode 100644 sync/dropbox-oauth.html diff --git a/manifest.json b/manifest.json index b8eab624..53d4d792 100644 --- a/manifest.json +++ b/manifest.json @@ -110,6 +110,9 @@ "js": ["content/install-hook-usercss.js"] } ], + "web_accessible_resources": [ + "/sync/dropbox-oauth.html" + ], "browser_action": { "default_icon": { "16": "/images/icon/16w.png", diff --git a/sync/dropbox-auth-receiver.js b/sync/dropbox-auth-receiver.js new file mode 100644 index 00000000..8286a37d --- /dev/null +++ b/sync/dropbox-auth-receiver.js @@ -0,0 +1,11 @@ +/* global chromeLocal */ +'use strict'; + +window.onload = () => { + const params = new URLSearchParams(new URL(location.href).hash.substr(1)); + /* it uses browser direct here because it supports just firefox yet */ + chromeLocal.setValue('dropbox_access_token', params.get('access_token')) + .then(() => { + window.location.href = window.location.origin + '/manage.html'; + }); +} diff --git a/sync/dropbox-oauth.html b/sync/dropbox-oauth.html new file mode 100644 index 00000000..e4f83a33 --- /dev/null +++ b/sync/dropbox-oauth.html @@ -0,0 +1,12 @@ + + + + + + OAuth Receiver + + + + + + diff --git a/sync/import-export-dropbox.js b/sync/import-export-dropbox.js index 222df852..64ce44a8 100644 --- a/sync/import-export-dropbox.js +++ b/sync/import-export-dropbox.js @@ -3,7 +3,8 @@ $ $create t chromeLocal API getOwnTab */ 'use strict'; -const DROPBOX_API_KEY = 'zg52vphuapvpng9'; +// const DROPBOX_API_KEY = 'zg52vphuapvpng9'; +const DROPBOX_API_KEY = 'uyfixgzre8v1bkg'; const FILENAME_ZIP_FILE = 'stylus.json'; const DROPBOX_FILE = 'stylus.zip'; const API_ERROR_STATUS_FILE_NOT_FOUND = 409; @@ -35,6 +36,11 @@ function requestDropboxAccessToken() { clientId: DROPBOX_API_KEY, fetch }); + const isFirefoxAndroid = /Android/.test(navigator.userAgent) && /Mozilla/.test(navigator.userAgent); + if (isFirefoxAndroid) { + window.location.href = client.getAuthenticationUrl(window.location.origin + '/sync/dropbox-oauth.html'); + return; + } const authUrl = client.getAuthenticationUrl(getRedirectUrlAuthFlow()); return launchWebAuthFlow({url: authUrl, interactive: true}) .then(urlReturned => { @@ -51,9 +57,9 @@ function uploadFileDropbox(client, stylesText) { $('#sync-dropbox-export').onclick = () => { const mode = localStorage.installType; const title = t('syncDropboxStyles'); - const text = mode === 'normal' ? t('connectingDropbox') : t('connectingDropboxNotAllowed'); - messageProgressBar({title, text}); - if (mode !== 'normal') return; + // const text = mode === 'normal' ? t('connectingDropbox') : t('connectingDropboxNotAllowed'); + // messageProgressBar({title, text}); + // if (mode !== 'normal') return; hasDropboxAccessToken() .then(token => token || requestDropboxAccessToken()) @@ -125,9 +131,9 @@ $('#sync-dropbox-export').onclick = () => { $('#sync-dropbox-import').onclick = () => { const mode = localStorage.installType; const title = t('retrieveDropboxSync'); - const text = mode === 'normal' ? t('connectingDropbox') : t('connectingDropboxNotAllowed'); - messageProgressBar({title, text}); - if (mode !== 'normal') return; + // const text = mode === 'normal' ? t('connectingDropbox') : t('connectingDropboxNotAllowed'); + // messageProgressBar({title, text}); + // if (mode !== 'normal') return; hasDropboxAccessToken() .then(token => token || requestDropboxAccessToken())