mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-30 02:23:47 +00:00
debug: add console logging to Telegram popup flow
Trace showPopup lifecycle (open, callback, popupClosed event, timeout) to diagnose why popup action doesn't execute and subsequent calls fail. Reduce safety timeout to 5s for faster debugging.
This commit is contained in:
@@ -203,6 +203,8 @@ function createDialogController(): DialogController {
|
|||||||
popupOpen = true;
|
popupOpen = true;
|
||||||
let settled = false;
|
let settled = false;
|
||||||
|
|
||||||
|
console.log('[popup] opening', JSON.stringify(params));
|
||||||
|
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
if (settled) return;
|
if (settled) return;
|
||||||
settled = true;
|
settled = true;
|
||||||
@@ -211,10 +213,8 @@ function createDialogController(): DialogController {
|
|||||||
tg.offEvent?.('popupClosed', onPopupClosed);
|
tg.offEvent?.('popupClosed', onPopupClosed);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fallback: listen for popupClosed event in case the callback doesn't fire
|
|
||||||
// (known Telegram Desktop bug: popup_closed payload can be undefined,
|
|
||||||
// crashing the internal handler before it invokes the callback)
|
|
||||||
const onPopupClosed = ((...args: unknown[]) => {
|
const onPopupClosed = ((...args: unknown[]) => {
|
||||||
|
console.log('[popup] popupClosed event', JSON.stringify(args));
|
||||||
if (settled) return;
|
if (settled) return;
|
||||||
const event = args[0] as { button_id?: string } | undefined;
|
const event = args[0] as { button_id?: string } | undefined;
|
||||||
const buttonId = event?.button_id ?? '';
|
const buttonId = event?.button_id ?? '';
|
||||||
@@ -222,22 +222,25 @@ function createDialogController(): DialogController {
|
|||||||
resolve(mapResult(buttonId));
|
resolve(mapResult(buttonId));
|
||||||
}) as (...args: unknown[]) => void;
|
}) as (...args: unknown[]) => void;
|
||||||
|
|
||||||
// Safety timeout: reset state if neither callback nor event arrives
|
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
|
console.log('[popup] timeout — force reset');
|
||||||
if (settled) return;
|
if (settled) return;
|
||||||
cleanup();
|
cleanup();
|
||||||
resolve(mapResult(''));
|
resolve(mapResult(''));
|
||||||
}, 30_000);
|
}, 5_000);
|
||||||
|
|
||||||
tg.onEvent?.('popupClosed', onPopupClosed);
|
tg.onEvent?.('popupClosed', onPopupClosed);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tg.showPopup(params, (buttonId) => {
|
tg.showPopup(params, (buttonId) => {
|
||||||
|
console.log('[popup] callback fired, buttonId=', buttonId);
|
||||||
if (settled) return;
|
if (settled) return;
|
||||||
cleanup();
|
cleanup();
|
||||||
resolve(mapResult(buttonId));
|
resolve(mapResult(buttonId));
|
||||||
});
|
});
|
||||||
} catch {
|
console.log('[popup] showPopup called OK');
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[popup] showPopup threw', e);
|
||||||
cleanup();
|
cleanup();
|
||||||
resolve(fallback());
|
resolve(fallback());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user