Game: Remove popup manager (#6176)
This commit is contained in:
parent
d42ff4566f
commit
67d1495e41
@ -21,7 +21,6 @@ import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
|||||||
import { getTranslationFn } from '../../../util/localization';
|
import { getTranslationFn } from '../../../util/localization';
|
||||||
import { formatStarsAsText } from '../../../util/localization/format';
|
import { formatStarsAsText } from '../../../util/localization/format';
|
||||||
import { oldTranslate } from '../../../util/oldLangProvider';
|
import { oldTranslate } from '../../../util/oldLangProvider';
|
||||||
import PopupManager from '../../../util/PopupManager';
|
|
||||||
import requestActionTimeout from '../../../util/requestActionTimeout';
|
import requestActionTimeout from '../../../util/requestActionTimeout';
|
||||||
import { debounce } from '../../../util/schedulers';
|
import { debounce } from '../../../util/schedulers';
|
||||||
import { getServerTime } from '../../../util/serverTime';
|
import { getServerTime } from '../../../util/serverTime';
|
||||||
@ -73,7 +72,6 @@ import { getPeerStarsForMessage } from './messages';
|
|||||||
|
|
||||||
import { getIsWebAppsFullscreenSupported } from '../../../hooks/useAppLayout';
|
import { getIsWebAppsFullscreenSupported } from '../../../hooks/useAppLayout';
|
||||||
|
|
||||||
const GAMEE_URL = 'https://prizes.gamee.com/';
|
|
||||||
const TOP_PEERS_REQUEST_COOLDOWN = 60; // 1 min
|
const TOP_PEERS_REQUEST_COOLDOWN = 60; // 1 min
|
||||||
const runDebouncedForSearch = debounce((cb) => cb(), 500, false);
|
const runDebouncedForSearch = debounce((cb) => cb(), 500, false);
|
||||||
let botFatherId: string | null;
|
let botFatherId: string | null;
|
||||||
@ -1287,8 +1285,6 @@ async function sendBotCommand(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let gameePopups: PopupManager | undefined;
|
|
||||||
|
|
||||||
async function answerCallbackButton<T extends GlobalState>(
|
async function answerCallbackButton<T extends GlobalState>(
|
||||||
global: T,
|
global: T,
|
||||||
actions: RequiredGlobalActions, chat: ApiChat, messageId: number, data?: string, isGame = false,
|
actions: RequiredGlobalActions, chat: ApiChat, messageId: number, data?: string, isGame = false,
|
||||||
@ -1298,16 +1294,6 @@ async function answerCallbackButton<T extends GlobalState>(
|
|||||||
showDialog, showNotification, openUrl, openGame,
|
showDialog, showNotification, openUrl, openGame,
|
||||||
} = actions;
|
} = actions;
|
||||||
|
|
||||||
if (isGame) {
|
|
||||||
if (!gameePopups) {
|
|
||||||
gameePopups = new PopupManager('popup,width=800,height=600', () => {
|
|
||||||
showNotification({ message: 'Allow browser to open popup window', tabId });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
gameePopups.preOpenIfNeeded();
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await callApi('answerCallbackButton', {
|
const result = await callApi('answerCallbackButton', {
|
||||||
chatId: chat.id,
|
chatId: chat.id,
|
||||||
accessHash: chat.accessHash,
|
accessHash: chat.accessHash,
|
||||||
@ -1327,15 +1313,9 @@ async function answerCallbackButton<T extends GlobalState>(
|
|||||||
showNotification({ message, tabId });
|
showNotification({ message, tabId });
|
||||||
} else if (url) {
|
} else if (url) {
|
||||||
if (isGame) {
|
if (isGame) {
|
||||||
// Workaround for Gamee embedding bug
|
openGame({
|
||||||
if (url.includes(GAMEE_URL)) {
|
url, chatId: chat.id, messageId, tabId,
|
||||||
gameePopups!.open(url);
|
});
|
||||||
} else {
|
|
||||||
gameePopups!.cancelPreOpen();
|
|
||||||
openGame({
|
|
||||||
url, chatId: chat.id, messageId, tabId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
openUrl({ url, tabId });
|
openUrl({ url, tabId });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,45 +0,0 @@
|
|||||||
import { IS_ANDROID, IS_IOS } from './browser/windowEnvironment';
|
|
||||||
|
|
||||||
const SHOULD_PRE_OPEN = IS_IOS || IS_ANDROID;
|
|
||||||
|
|
||||||
export default class PopupManager {
|
|
||||||
private preOpened?: WindowProxy | null;
|
|
||||||
|
|
||||||
constructor(private features?: string, private onFail?: NoneToVoidFunction) {
|
|
||||||
}
|
|
||||||
|
|
||||||
preOpenIfNeeded() {
|
|
||||||
if (!SHOULD_PRE_OPEN) return;
|
|
||||||
|
|
||||||
this.preOpened = window.open('about:blank', undefined, this.features);
|
|
||||||
if (this.preOpened) {
|
|
||||||
this.preOpened.blur();
|
|
||||||
} else {
|
|
||||||
this.onFail?.();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
open(url: string) {
|
|
||||||
if (this.preOpened) {
|
|
||||||
this.preOpened.location.href = url;
|
|
||||||
this.preOpened.focus();
|
|
||||||
this.preOpened = undefined;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SHOULD_PRE_OPEN) {
|
|
||||||
const popup = window.open(url, undefined, this.features);
|
|
||||||
if (popup) {
|
|
||||||
popup.focus();
|
|
||||||
} else {
|
|
||||||
this.onFail?.();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cancelPreOpen() {
|
|
||||||
this.preOpened?.close();
|
|
||||||
this.preOpened = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user