mirror of https://github.com/keeweb/keeweb
fix #1711: workaround for Dropbox on iOS PWA
parent
f889488915
commit
f6e377f222
|
@ -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 });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue