Game: Remove popup manager (#6176)

This commit is contained in:
zubiden 2025-08-29 08:58:05 +02:00 committed by Alexander Zinchuk
parent d42ff4566f
commit 67d1495e41
2 changed files with 3 additions and 68 deletions

View File

@ -21,7 +21,6 @@ import { getCurrentTabId } from '../../../util/establishMultitabRole';
import { getTranslationFn } from '../../../util/localization';
import { formatStarsAsText } from '../../../util/localization/format';
import { oldTranslate } from '../../../util/oldLangProvider';
import PopupManager from '../../../util/PopupManager';
import requestActionTimeout from '../../../util/requestActionTimeout';
import { debounce } from '../../../util/schedulers';
import { getServerTime } from '../../../util/serverTime';
@ -73,7 +72,6 @@ import { getPeerStarsForMessage } from './messages';
import { getIsWebAppsFullscreenSupported } from '../../../hooks/useAppLayout';
const GAMEE_URL = 'https://prizes.gamee.com/';
const TOP_PEERS_REQUEST_COOLDOWN = 60; // 1 min
const runDebouncedForSearch = debounce((cb) => cb(), 500, false);
let botFatherId: string | null;
@ -1287,8 +1285,6 @@ async function sendBotCommand(
});
}
let gameePopups: PopupManager | undefined;
async function answerCallbackButton<T extends GlobalState>(
global: T,
actions: RequiredGlobalActions, chat: ApiChat, messageId: number, data?: string, isGame = false,
@ -1298,16 +1294,6 @@ async function answerCallbackButton<T extends GlobalState>(
showDialog, showNotification, openUrl, openGame,
} = 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', {
chatId: chat.id,
accessHash: chat.accessHash,
@ -1327,15 +1313,9 @@ async function answerCallbackButton<T extends GlobalState>(
showNotification({ message, tabId });
} else if (url) {
if (isGame) {
// Workaround for Gamee embedding bug
if (url.includes(GAMEE_URL)) {
gameePopups!.open(url);
} else {
gameePopups!.cancelPreOpen();
openGame({
url, chatId: chat.id, messageId, tabId,
});
}
openGame({
url, chatId: chat.id, messageId, tabId,
});
} else {
openUrl({ url, tabId });
}

View File

@ -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;
}
}