@open-wa/wa-automate 4.28.13 → 4.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,6 +42,8 @@ export declare class Client {
42
42
  private _registeredPageListeners;
43
43
  private _onLogoutCallbacks;
44
44
  private _queues;
45
+ private _autoEmojiSet;
46
+ private _onLogoutSet;
45
47
  /**
46
48
  * This is used to track if a listener is already used via webhook. Before, webhooks used to be set once per listener. Now a listener can be set via multiple webhooks, or revoked from a specific webhook.
47
49
  * For this reason, listeners assigned to a webhook are only set once and map through all possible webhooks to and fire only if the specific listener is assigned.
@@ -56,7 +56,6 @@ const fs = __importStar(require("fs"));
56
56
  const datauri_1 = __importDefault(require("datauri"));
57
57
  const is_url_superb_1 = __importDefault(require("is-url-superb"));
58
58
  const fs_extra_1 = require("fs-extra");
59
- const tree_kill_1 = __importDefault(require("tree-kill"));
60
59
  const browser_1 = require("../controllers/browser");
61
60
  const auth_1 = require("../controllers/auth");
62
61
  const wa_decrypt_1 = require("@open-wa/wa-decrypt");
@@ -92,6 +91,8 @@ class Client {
92
91
  this._registeredPageListeners = [];
93
92
  this._onLogoutCallbacks = [];
94
93
  this._queues = {};
94
+ this._autoEmojiSet = false;
95
+ this._onLogoutSet = false;
95
96
  /**
96
97
  * This is used to track if a listener is already used via webhook. Before, webhooks used to be set once per listener. Now a listener can be set via multiple webhooks, or revoked from a specific webhook.
97
98
  * For this reason, listeners assigned to a webhook are only set once and map through all possible webhooks to and fire only if the specific listener is assigned.
@@ -249,7 +250,7 @@ class Client {
249
250
  logging_1.log.info('LOADED', {
250
251
  PHONE_VERSION: this._sessionInfo.PHONE_VERSION
251
252
  });
252
- if (((_d = this._createConfig) === null || _d === void 0 ? void 0 : _d.autoEmoji) === undefined || ((_e = this._createConfig) === null || _e === void 0 ? void 0 : _e.autoEmoji)) {
253
+ if ((((_d = this._createConfig) === null || _d === void 0 ? void 0 : _d.autoEmoji) === undefined || ((_e = this._createConfig) === null || _e === void 0 ? void 0 : _e.autoEmoji)) && !this._autoEmojiSet) {
253
254
  const ident = typeof ((_f = this._createConfig) === null || _f === void 0 ? void 0 : _f.autoEmoji) === "string" ? (_g = this._createConfig) === null || _g === void 0 ? void 0 : _g.autoEmoji : ":";
254
255
  this.onMessage((message) => __awaiter(this, void 0, void 0, function* () {
255
256
  if (message.body && message.body.startsWith(ident) && message.body.endsWith(ident)) {
@@ -259,8 +260,9 @@ class Client {
259
260
  return yield this.sendEmoji(message.from, emojiId, message.id);
260
261
  }
261
262
  }));
263
+ this._autoEmojiSet = true;
262
264
  }
263
- if (((_h = this._createConfig) === null || _h === void 0 ? void 0 : _h.deleteSessionDataOnLogout) || ((_j = this._createConfig) === null || _j === void 0 ? void 0 : _j.killClientOnLogout)) {
265
+ if ((((_h = this._createConfig) === null || _h === void 0 ? void 0 : _h.deleteSessionDataOnLogout) || ((_j = this._createConfig) === null || _j === void 0 ? void 0 : _j.killClientOnLogout)) && !this._onLogoutSet) {
264
266
  this.onLogout(() => __awaiter(this, void 0, void 0, function* () {
265
267
  var _k, _l;
266
268
  yield this.waitAllQEmpty();
@@ -272,6 +274,7 @@ class Client {
272
274
  this.kill("LOGGED_OUT");
273
275
  }
274
276
  }), -1);
277
+ this._onLogoutSet = true;
275
278
  }
276
279
  });
277
280
  }
@@ -538,7 +541,7 @@ class Client {
538
541
  fn = _fn;
539
542
  }
540
543
  if (this._registeredEvListeners && this._registeredEvListeners[funcName]) {
541
- return events_1.ev.on(this.getEventSignature(funcName), ({ data }) => fn(data));
544
+ return events_1.ev.on(this.getEventSignature(funcName), ({ data }) => fn(data), { objectify: true });
542
545
  }
543
546
  /**
544
547
  * If evMode is on then make the callback come from ev.
@@ -1088,25 +1091,17 @@ class Client {
1088
1091
  * @returns true
1089
1092
  */
1090
1093
  kill(reason = "MANUALLY_KILLED") {
1091
- var _a, _b, _c, _d, _e, _f, _g;
1094
+ var _a, _b;
1092
1095
  return __awaiter(this, void 0, void 0, function* () {
1093
1096
  if (this._currentlyBeingKilled)
1094
1097
  return;
1095
1098
  this._currentlyBeingKilled = true;
1096
1099
  console.log('Killing client. Shutting Down');
1097
1100
  logging_1.log.info('Killing client. Shutting Down');
1098
- (0, tools_1.processSendData)({
1099
- reason
1100
- });
1101
1101
  const browser = yield ((_a = this === null || this === void 0 ? void 0 : this._page) === null || _a === void 0 ? void 0 : _a.browser());
1102
1102
  const pid = (browser === null || browser === void 0 ? void 0 : browser.process()) ? (_b = browser === null || browser === void 0 ? void 0 : browser.process()) === null || _b === void 0 ? void 0 : _b.pid : null;
1103
1103
  try {
1104
- if (this._page && !((_c = this._page) === null || _c === void 0 ? void 0 : _c.isClosed()))
1105
- yield ((_d = this._page) === null || _d === void 0 ? void 0 : _d.close());
1106
- if (this._page && ((_e = this._page) === null || _e === void 0 ? void 0 : _e.browser))
1107
- yield ((_g = (_f = this._page) === null || _f === void 0 ? void 0 : _f.browser()) === null || _g === void 0 ? void 0 : _g.close());
1108
- if (pid)
1109
- (0, tree_kill_1.default)(pid, 'SIGKILL');
1104
+ yield (0, browser_1.kill)(this._page, browser, false, pid, reason);
1110
1105
  }
1111
1106
  catch (error) {
1112
1107
  //ignore error
@@ -41,7 +41,7 @@ const events_1 = require("./events");
41
41
  const pico_s3_1 = require("pico-s3");
42
42
  // eslint-disable-next-line @typescript-eslint/no-var-requires
43
43
  const puppeteer = require('puppeteer-extra');
44
- const tree_kill_1 = __importDefault(require("tree-kill"));
44
+ const promise_1 = __importDefault(require("terminate/promise"));
45
45
  const logging_1 = require("../logging/logging");
46
46
  const tools_1 = require("../utils/tools");
47
47
  let browser;
@@ -406,7 +406,7 @@ const kill = (p, b, exit, pid, reason = "LAUNCH_KILL") => __awaiter(void 0, void
406
406
  yield killBrowser(b);
407
407
  }
408
408
  if (pid)
409
- (0, tree_kill_1.default)(pid, 'SIGKILL');
409
+ yield (0, promise_1.default)(pid, 'SIGKILL').catch(e => console.error('Error while terminating browser PID. You can just ignore this, as the process has most likely been terminated successfully already:', e.message));
410
410
  if (exit)
411
411
  process.exit();
412
412
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.28.13",
3
+ "version": "4.29.0",
4
4
  "licenseCheckUrl": "https://openwa.dev/license-check",
5
5
  "brokenMethodReportUrl": "https://openwa.dev/report-bm",
6
6
  "patches": "https://cdn.openwa.dev/patches.json",
@@ -159,9 +159,9 @@
159
159
  "swagger-ui-express": "^4.1.4",
160
160
  "tcp-port-used": "^1.0.1",
161
161
  "terminal-link": "^2.1.1",
162
+ "terminate": "^2.5.0",
162
163
  "tiny-glob": "^0.2.9",
163
164
  "traverse": "^0.6.6",
164
- "tree-kill": "^1.2.2",
165
165
  "ts-json-schema-generator": "^0.95.0",
166
166
  "ts-morph": "^12.0.0",
167
167
  "type-fest": "^1.1.1",