up(WEBJS): hide "What's new on WhatsApp Web" - fix #2217
This commit is contained in:
1 parent
f6ed147acc
commit
8d4eb02202
2 files changed
+66
No files matched your search
@@ -147,6 +147,37 @@ export class WebjsClientCore extends Client {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @result indicating whether the "What's New" auto-modal was prevented or dismissed.
|
||||
*/
|
||||
hideWhatsNewModal(): Promise<boolean> {
|
||||
return this.pupPage.evaluate(() => {
|
||||
// Module registry is not available until the app bundle has loaded
|
||||
if (typeof window.require !== 'function') {
|
||||
return false;
|
||||
}
|
||||
const WAWebWhatsNewNux = window.require('WAWebWhatsNewNux');
|
||||
if (!WAWebWhatsNewNux) {
|
||||
return false;
|
||||
}
|
||||
// user prefs are not writable before login
|
||||
const WAWebUserPrefsMeUser = window.require('WAWebUserPrefsMeUser');
|
||||
if (!WAWebUserPrefsMeUser.getMaybeMePnUser()) {
|
||||
return false;
|
||||
}
|
||||
const nux = WAWebWhatsNewNux.createWhatsNewNux();
|
||||
if (!nux.shouldShow()) {
|
||||
return false;
|
||||
}
|
||||
// Bump the dismiss count and start the cool-off, so the app never auto-opens the modal
|
||||
nux.dismiss();
|
||||
// If the modal has already opened - close the topmost modal (no-op when nothing is open)
|
||||
const WAWebModalManager = window.require('WAWebModalManager');
|
||||
WAWebModalManager.ModalManager.close();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
async attachCustomEventListeners() {
|
||||
await exposeFunctionIfAbsent(
|
||||
this.pupPage,
|
||||
|
||||
@@ -152,6 +152,7 @@ import {
|
||||
import { PaginatorInMemory } from '@waha/utils/Paginator';
|
||||
import { promiseTimeout, sleep, waitUntil } from '@waha/utils/promiseTimeout';
|
||||
import { SingleDelayedJobRunner } from '@waha/utils/SingleDelayedJobRunner';
|
||||
import { SinglePeriodicJobRunner } from '@waha/utils/SinglePeriodicJobRunner';
|
||||
import { TmpDir } from '@waha/utils/tmpdir';
|
||||
import * as lodash from 'lodash';
|
||||
import * as path from 'path';
|
||||
@@ -230,6 +231,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
|
||||
|
||||
private startDelayedJob: SingleDelayedJobRunner;
|
||||
private engineStateCheckDelayedJob: SingleDelayedJobRunner;
|
||||
private whatsNewModalJob: SinglePeriodicJobRunner;
|
||||
private shouldRestart: boolean;
|
||||
private lastQRDate: Date = null;
|
||||
private static readonly REACTION_MAX_AGE_MS = 2 * 24 * 60 * 60 * 1000;
|
||||
@@ -254,6 +256,13 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
|
||||
2 * SECOND,
|
||||
this.logger,
|
||||
);
|
||||
// Hide the "What's New" modal that blocks app init after QR login
|
||||
this.whatsNewModalJob = new SinglePeriodicJobRunner(
|
||||
'hide-whats-new-modal',
|
||||
SECOND,
|
||||
this.logger,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,6 +433,8 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
|
||||
console.log(`url is ${location.href}`),
|
||||
);
|
||||
}
|
||||
|
||||
this.startWhatsNewModalJob();
|
||||
})
|
||||
.catch((error) => {
|
||||
this.logger.error(error);
|
||||
@@ -492,6 +503,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
|
||||
this.cleanupPresenceTimeout();
|
||||
this.presence = null;
|
||||
this.engineStateCheckDelayedJob.cancel();
|
||||
this.whatsNewModalJob.stop();
|
||||
this.whatsapp?.removeAllListeners();
|
||||
this.whatsapp?.pupBrowser?.removeAllListeners();
|
||||
this.whatsapp?.pupPage?.removeAllListeners();
|
||||
@@ -592,6 +604,29 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
|
||||
}
|
||||
}
|
||||
|
||||
private startWhatsNewModalJob() {
|
||||
// The "What's New" modal can block app init right after QR login, so the session never leaves STARTING
|
||||
// https://github.com/devlikeapro/waha/issues/2217
|
||||
this.whatsNewModalJob.start(async () => {
|
||||
let hidden = false;
|
||||
try {
|
||||
hidden = await this.whatsapp.hideWhatsNewModal();
|
||||
} catch (err) {
|
||||
// The page navigates during login, evaluate() can fail - retry on the next tick
|
||||
this.logger.debug(`Failed to hide "What's New" modal: ${err}`);
|
||||
return;
|
||||
}
|
||||
if (hidden) {
|
||||
this.logger.info(`"What's New" modal has been dismissed`);
|
||||
return;
|
||||
}
|
||||
// The cool-off is stored user-scoped, so keep re-checking until it holds after login
|
||||
if (this.status === WAHASessionStatus.WORKING) {
|
||||
this.whatsNewModalJob.stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected listenConnectionEvents() {
|
||||
this.whatsapp.on(Events.REACHOUT_TIMELOCK_UPDATE, (record: any) => {
|
||||
if (!record) {
|
||||
|
||||
Reference in new issue
Block a user