cortico-world-hands 0.20.16 → 0.20.17

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.
Files changed (2) hide show
  1. package/dist/index.js +28 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2238,6 +2238,8 @@ var HandsWorld = class {
2238
2238
  qqTimer = null;
2239
2239
  qqDueTimer = null;
2240
2240
  mediaTimer = null;
2241
+ watchTimer = null;
2242
+ handDown = null;
2241
2243
  lastMediaDay = "";
2242
2244
  cursor = 0;
2243
2245
  lastHitKey = "";
@@ -2295,6 +2297,9 @@ var HandsWorld = class {
2295
2297
  this.mediaTimer = setInterval(() => {
2296
2298
  void this.maybeCleanMedia();
2297
2299
  }, 30 * 60 * 1e3);
2300
+ this.watchTimer = setInterval(() => {
2301
+ void this.watchHands();
2302
+ }, 6e4);
2298
2303
  setTimeout(() => {
2299
2304
  void this.maybeCleanMedia();
2300
2305
  }, 2e4);
@@ -2315,6 +2320,7 @@ var HandsWorld = class {
2315
2320
  if (this.qqTimer) clearInterval(this.qqTimer);
2316
2321
  if (this.qqDueTimer) clearInterval(this.qqDueTimer);
2317
2322
  if (this.mediaTimer) clearInterval(this.mediaTimer);
2323
+ if (this.watchTimer) clearInterval(this.watchTimer);
2318
2324
  this.pollTimer = null;
2319
2325
  this.mineTimer = null;
2320
2326
  }
@@ -2546,6 +2552,28 @@ ${lines.join("\n")}
2546
2552
  );
2547
2553
  }
2548
2554
  }
2555
+ /** 手掉线时立刻告诉主人(每分钟看一次,掉了只报一次)。 */
2556
+ async watchHands() {
2557
+ const port = this.opts.cfg.handPort && this.opts.cfg.handPort > 1024 ? this.opts.cfg.handPort : 17897;
2558
+ let ok = false;
2559
+ try {
2560
+ const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(2500) });
2561
+ ok = res.ok;
2562
+ } catch {
2563
+ ok = false;
2564
+ }
2565
+ if (!ok && this.handDown !== true) {
2566
+ this.handDown = true;
2567
+ await this.pushEvent(
2568
+ "[\u624B\u6389\u4E86] \u61FF\u5FC3\u7684\u624B\u8FDE\u4E0D\u4E0A\u4E86\uFF0817897 \u6CA1\u54CD\u5E94\uFF09\u3002\u4E3B\u4EBA\uFF1A\u70B9\u4E00\u4E0B\u300C\u61FF\u5FC3\u300D\u8FD9\u4E2A App \u5C31\u597D\uFF0C\u4E0D\u7528\u91CD\u542F Coopanin\u3002",
2569
+ "hands.down",
2570
+ "hands:watch"
2571
+ );
2572
+ } else if (ok && this.handDown === true) {
2573
+ this.handDown = false;
2574
+ await this.pushEvent("[\u624B\u56DE\u6765\u4E86] \u61FF\u5FC3\u91CD\u65B0\u8FDE\u4E0A\uFF0C\u624B\u548C\u773C\u775B\u90FD\u80FD\u7528\u4E86\u3002", "hands.up", "hands:watch");
2575
+ }
2576
+ }
2549
2577
  async pollQq() {
2550
2578
  if (!this.host) return;
2551
2579
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-hands",
3
- "version": "0.20.16",
3
+ "version": "0.20.17",
4
4
  "type": "module",
5
5
  "description": "Cortico World: hands for the desktop pet — looks at the phone screen, then taps, swipes, pinches, drags, types and presses keys through whatever actuator the device actually has",
6
6
  "license": "MIT",