fix #1711: workaround for Dropbox on iOS PWA

This commit is contained in:
antelle 2021-02-11 23:01:28 +01:00
parent 7a7381eac0
commit 0464e1de5c
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
2 changed files with 47 additions and 19 deletions

View File

@ -1,5 +1,6 @@
import { Events } from 'framework/events';
import { Launcher } from 'comp/launcher';
import { Features } from 'util/features';
import { Alerts } from 'comp/ui/alerts';
import { Timeouts } from 'const/timeouts';
import { Locale } from 'util/locale';
@ -45,12 +46,30 @@ const PopupNotifier = {
Timeouts.CheckWindowClosed
);
} else {
if (Features.isStandalone) {
const loc = PopupNotifier.tryGetLocationSearch(win);
if (loc) {
try {
win.close();
} catch {}
PopupNotifier.triggerClosed(win, loc);
return;
}
}
PopupNotifier.deferCheckClosed(win);
}
},
triggerClosed(win) {
Events.emit('popup-closed', win);
tryGetLocationSearch(win) {
try {
if (win.location.host === location.host) {
return win.location.search;
}
} catch {}
},
triggerClosed(window, locationSearch) {
Events.emit('popup-closed', { window, locationSearch });
}
};

View File

@ -264,11 +264,33 @@ class StorageBase {
this.logger.debug('OAuth: popup opened');
const popupClosed = () => {
const processWindowMessage = (locationSearch) => {
const data = {};
for (const [key, value] of new URLSearchParams(locationSearch).entries()) {
data[key] = value;
}
if (data.error) {
this.logger.error('OAuth error', data.error, data.error_description);
callback('OAuth: ' + data.error);
} else if (data.code) {
Events.off('popup-closed', popupClosed);
window.removeEventListener('message', windowMessage);
this._oauthCodeReceived(data, session, callback);
} else {
this.logger.debug('Skipped OAuth message', data);
}
};
const popupClosed = (e) => {
Events.off('popup-closed', popupClosed);
window.removeEventListener('message', windowMessage);
this.logger.error('OAuth error', 'popup closed');
callback('OAuth: popup closed');
if (e.locationSearch) {
// see #1711: mobile Safari in PWA mode can't close the pop-up, but it returns the url
processWindowMessage(e.locationSearch);
} else {
this.logger.error('OAuth error', 'popup closed');
callback('OAuth: popup closed');
}
};
const windowMessage = (e) => {
@ -283,20 +305,7 @@ class StorageBase {
this.logger.debug('Skipped OAuth message for another storage', e.data.storage);
return;
}
const data = {};
for (const [key, value] of new URLSearchParams(e.data.search).entries()) {
data[key] = value;
}
if (data.error) {
this.logger.error('OAuth error', data.error, data.error_description);
callback('OAuth: ' + data.error);
} else if (data.code) {
Events.off('popup-closed', popupClosed);
window.removeEventListener('message', windowMessage);
this._oauthCodeReceived(data, session, callback);
} else {
this.logger.debug('Skipped OAuth message', data);
}
processWindowMessage(e.data.search);
};
Events.on('popup-closed', popupClosed);
window.addEventListener('message', windowMessage);