Skip to content

Commit

Permalink
checkingCloses code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisk8er authored and jonalan7 committed Oct 23, 2024
1 parent c56d3f3 commit 382cc6d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 35 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## [1.0.31](https://github.com/jonalan7/Hydra-bot/compare/v1.0.30...v1.0.31) (2024-10-23)


### Bug Fixes

* getHost ([b25d180](https://github.com/jonalan7/Hydra-bot/commit/b25d180b44574a6fa3c9ef8aea3992ef297ee16e))
* initial corrections ([c56d3f3](https://github.com/jonalan7/Hydra-bot/commit/c56d3f3c1e5077693967af3baef73389ff53dde0))
* onMod ([19e5814](https://github.com/jonalan7/Hydra-bot/commit/19e5814cd70461971006042e7f5cc9881a557e79))


### Features

* add nodemon dev ([b8ab0fa](https://github.com/jonalan7/Hydra-bot/commit/b8ab0fa398fdb3e902b670bd9b7ff313fa4e90ac))



## [1.0.30](https://github.com/jonalan7/Hydra-bot/compare/v1.0.29...v1.0.30) (2022-08-20)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hydra-bot",
"version": "1.0.30",
"version": "1.0.31",
"description": "The most reliable WhatsApp tool for chatbots with advanced features. Hydra bot is an open source project developed by the JavaScript community with the aim of exporting functions from WhatsApp Web to the node js, . The most complete javascript library for Whatsapp, 100% Open Source.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
41 changes: 9 additions & 32 deletions src/webpack/help/checking-closes.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
export interface process {
close: any;
_process: any
}

import { Browser } from 'puppeteer';
/**
* Function to check if the browser is closed and call the callback function
* @param browser - Browser instance from puppeteer
* @param callStatus - Callback function to call when the browser is closed
*/
export async function checkingCloses(
browser: process,
callStatus: (e: boolean) => void
browser: Browser,
callStatus: (event: boolean) => void
) {
let processClose = false;
if (browser._process) {
browser._process.once('close', () => {
processClose = true;
});
}
new Promise(async (resolve, reject) => {
if (typeof browser !== 'string') {
let err: boolean;
do {
try {
await new Promise((r) => setTimeout(r, 2000));
if (processClose) {
browser.close().catch((e: any) => reject(e));
callStatus && callStatus(true);
err = false;
} else {
throw 1;
}
} catch (e) {
err = true;
}
} while (err);
}
});
browser.on('disconnected', () => callStatus(true));
}

0 comments on commit 382cc6d

Please sign in to comment.