2019-09-16 22:57:56 +02:00
|
|
|
import { Events } from 'framework/events';
|
2019-09-15 14:16:32 +02:00
|
|
|
import { Launcher } from 'comp/launcher';
|
|
|
|
import { Alerts } from 'comp/ui/alerts';
|
|
|
|
import { Timeouts } from 'const/timeouts';
|
|
|
|
import { Locale } from 'util/locale';
|
|
|
|
import { Logger } from 'util/logger';
|
2020-04-17 19:42:35 +02:00
|
|
|
import { noop } from 'util/fn';
|
2016-03-26 21:12:56 +01:00
|
|
|
|
2017-01-31 07:50:28 +01:00
|
|
|
const PopupNotifier = {
|
2018-02-01 01:42:49 +01:00
|
|
|
logger: null,
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
init() {
|
2018-02-16 19:32:44 +01:00
|
|
|
this.logger = new Logger('popup-notifier');
|
2018-02-01 01:42:49 +01:00
|
|
|
|
2016-03-27 16:47:29 +02:00
|
|
|
if (Launcher) {
|
2020-04-17 19:42:35 +02:00
|
|
|
window.open = noop;
|
2016-03-27 16:47:29 +02:00
|
|
|
} else {
|
2017-01-31 07:50:28 +01:00
|
|
|
const windowOpen = window.open;
|
2020-06-01 16:53:51 +02:00
|
|
|
window.open = function (...args) {
|
2019-08-18 10:17:09 +02:00
|
|
|
const win = windowOpen.apply(window, args);
|
2016-03-26 21:12:56 +01:00
|
|
|
if (win) {
|
|
|
|
PopupNotifier.deferCheckClosed(win);
|
2019-09-16 22:57:56 +02:00
|
|
|
Events.emit('popup-opened', win);
|
2016-03-27 15:36:07 +02:00
|
|
|
} else {
|
|
|
|
if (!Alerts.alertDisplayed) {
|
|
|
|
Alerts.error({
|
|
|
|
header: Locale.authPopupRequired,
|
|
|
|
body: Locale.authPopupRequiredBody
|
|
|
|
});
|
|
|
|
}
|
2016-03-26 21:12:56 +01:00
|
|
|
}
|
|
|
|
return win;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
deferCheckClosed(win) {
|
2016-03-26 21:12:56 +01:00
|
|
|
setTimeout(PopupNotifier.checkClosed.bind(PopupNotifier, win), Timeouts.CheckWindowClosed);
|
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
checkClosed(win) {
|
2016-03-26 21:12:56 +01:00
|
|
|
if (win.closed) {
|
2019-08-18 08:05:38 +02:00
|
|
|
setTimeout(
|
|
|
|
PopupNotifier.triggerClosed.bind(PopupNotifier, win),
|
|
|
|
Timeouts.CheckWindowClosed
|
|
|
|
);
|
2016-03-26 21:12:56 +01:00
|
|
|
} else {
|
|
|
|
PopupNotifier.deferCheckClosed(win);
|
|
|
|
}
|
2016-03-27 13:54:35 +02:00
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
triggerClosed(win) {
|
2019-09-16 22:57:56 +02:00
|
|
|
Events.emit('popup-closed', win);
|
2016-03-26 21:12:56 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-15 14:16:32 +02:00
|
|
|
export { PopupNotifier };
|