From d4458e5c3727b4d96e1595a6f5fa2d798a2bd69a Mon Sep 17 00:00:00 2001 From: Edgard Date: Sun, 19 Feb 2023 18:25:59 -0300 Subject: [PATCH] feat: Added deviceSyncTimeout option (close #1551) --- src/api/layers/host.layer.ts | 14 +++++++++----- src/config/create-config.ts | 6 ++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/api/layers/host.layer.ts b/src/api/layers/host.layer.ts index c16216eb1..97654a888 100644 --- a/src/api/layers/host.layer.ts +++ b/src/api/layers/host.layer.ts @@ -200,7 +200,7 @@ export class HostLayer { } if ( - this.options.autoClose > 0 && + (this.options.autoClose > 0 || this.options.deviceSyncTimeout > 0) && !this.autoCloseInterval && !this.page.isClosed() ) { @@ -213,9 +213,13 @@ export class HostLayer { } } - protected startAutoClose() { - if (this.options.autoClose > 0 && !this.autoCloseInterval) { - const seconds = Math.round(this.options.autoClose / 1000); + protected startAutoClose(time: number | null = null) { + if (time === null || time === undefined) { + time = this.options.autoClose; + } + + if (time > 0 && !this.autoCloseInterval) { + const seconds = Math.round(time / 1000); this.log('info', `Auto close configured to ${seconds}s`); let remain = seconds; @@ -358,7 +362,7 @@ export class HostLayer { this.cancelAutoClose(); // Wait for interface update await sleep(200); - this.startAutoClose(); + this.startAutoClose(this.options.deviceSyncTimeout); this.log('http', 'Checking phone is connected...'); const inChat = await this.waitForInChat(); diff --git a/src/config/create-config.ts b/src/config/create-config.ts index 26bedb9ed..bcaa3b3f0 100644 --- a/src/config/create-config.ts +++ b/src/config/create-config.ts @@ -81,6 +81,11 @@ export interface CreateConfig { * @default 60000 */ autoClose?: number; + /** + * Automatically closes the wppconnect only when is syncing the device (default 180000 miliseconds, 3 minutes, if you want to turn it off, assign 0 or false) + * @default 180000 (3 minutes) + */ + deviceSyncTimeout?: number; /** * Wait for in chat to return a instance of {@link Whatsapp} * @default false @@ -176,6 +181,7 @@ export const defaultOptions: CreateConfig = { disableWelcome: false, updatesLog: true, autoClose: 60000, + deviceSyncTimeout: 180000, createPathFileToken: true, waitForLogin: true, logger: defaultLogger,