dsh-prompt-scheduler 0.5.1 → 0.5.2

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/client.js +73 -21
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -369,7 +369,24 @@ window.__ModuleLoader__.load({
369
369
  }
370
370
 
371
371
  // ---------------------------------------------------------------- timer engine
372
- var engine = { timeout: null, interval: null, firing: false, sessionId: null }
372
+ var engine = { timeout: null, interval: null, firing: false, sessionId: null, firingWatch: null }
373
+
374
+ /**
375
+ * 火控锁的唯一写入口:开锁时挂一个看门狗。
376
+ * 到点按发送这条路上有几次网络往返,任何一次异常没收敛都会让 firing 永远为 true,
377
+ * 之后到这里就被 `if (engine.firing) return` 挡掉——表现是"定时还在、但永远不再发"。
378
+ */
379
+ function holdFiring(on) {
380
+ if (engine.firingWatch !== null) { clearTimeout(engine.firingWatch); engine.firingWatch = null }
381
+ engine.firing = !!on
382
+ if (on) {
383
+ engine.firingWatch = setTimeout(function () {
384
+ engine.firingWatch = null
385
+ engine.firing = false
386
+ try { syncTimer() } catch (e) { /* 下一轮轮询会再试 */ }
387
+ }, 15000)
388
+ }
389
+ }
373
390
 
374
391
  function clearEngineTimer() {
375
392
  if (engine.timeout !== null) { clearTimeout(engine.timeout); engine.timeout = null }
@@ -406,10 +423,17 @@ window.__ModuleLoader__.load({
406
423
 
407
424
  function finishClear() {
408
425
  var sessionId = store.state.sessionId
409
- callHost('/timer/clear', { sessionId: sessionId }).catch(function () {}).then(function () {
410
- engine.firing = false
411
- patch({ timer: null, rev: store.state.rev + 1 })
412
- })
426
+ // 成功/失败都要解锁并收起卡片:定时已经没了,卡片继续停在"打开"状态只会让下一次
427
+ // 点击变成"先关掉一个看不见的卡片",看起来就像按钮失灵。
428
+ var done = function () {
429
+ holdFiring(false)
430
+ patch({ timer: null, open: false, rev: store.state.rev + 1 })
431
+ }
432
+ try {
433
+ callHost('/timer/clear', { sessionId: sessionId }).then(done, done)
434
+ } catch (e) {
435
+ done()
436
+ }
413
437
  }
414
438
  /**
415
439
  * 到点结局回报:Host 只记一行事件日志,不改 timer.json、不做副作用。
@@ -438,19 +462,19 @@ window.__ModuleLoader__.load({
438
462
  if (reason !== 'timer' && overdue <= -1000) return
439
463
  if (overdue > GRACE_MS) {
440
464
  // Too late to mean anything: drop the timer instead of sending stale input.
441
- engine.firing = true
465
+ holdFiring(true)
442
466
  reportFire(sessionId, timer, 'skipped-overdue', '', 'overdue ' + Math.round(overdue / 1000) + 's')
443
467
  finishClear()
444
468
  return
445
469
  }
446
470
  if (!String(store.state.draft || '').trim()) {
447
- engine.firing = true
471
+ holdFiring(true)
448
472
  reportFire(sessionId, timer, 'skipped-empty', '', 'composer was empty')
449
473
  finishClear()
450
474
  return
451
475
  }
452
476
  // Hold the lock across press → clear so a concurrent poll cannot press twice.
453
- engine.firing = true
477
+ holdFiring(true)
454
478
  if (!claimFire(sessionId, timer.fireAtMs)) {
455
479
  reportFire(sessionId, timer, 'claimed-elsewhere', '', 'another tab owned the deadline')
456
480
  finishClear()
@@ -459,7 +483,7 @@ window.__ModuleLoader__.load({
459
483
  var method = pressSend()
460
484
  if (!method) {
461
485
  reportFire(sessionId, timer, 'press-failed', '', 'send button and Enter fallback both missed')
462
- engine.firing = false
486
+ holdFiring(false)
463
487
  return
464
488
  }
465
489
  reportFire(sessionId, timer, 'sent', method, '')
@@ -483,7 +507,16 @@ window.__ModuleLoader__.load({
483
507
  if (document.hidden) return
484
508
  syncTimer()
485
509
  }, POLL_MS)
486
- function onVisible() { if (!document.hidden) syncTimer() }
510
+ function onVisible() {
511
+ if (document.hidden) return
512
+ // Self-heal: state says open but no card is mounted (a render threw, or the
513
+ // host remounted the overlay). Clear it so the next click opens instead of
514
+ // closing something invisible.
515
+ try {
516
+ if (store.state.open && !document.querySelector('.psx-pop')) patch({ open: false })
517
+ } catch (e) { /* no document */ }
518
+ syncTimer()
519
+ }
487
520
  document.addEventListener('visibilitychange', onVisible)
488
521
  window.addEventListener('focus', onVisible)
489
522
  return function () {
@@ -502,6 +535,11 @@ window.__ModuleLoader__.load({
502
535
  sendButton: !!labelledSendButton(),
503
536
  editor: !!composerEditor(),
504
537
  commands: { enabled: commands.enabled, registered: commands.registered.slice(), error: commands.error },
538
+ // 排查"点了没反应"用:open 说有卡片、overlayInDom 说实际有没有渲染出来。
539
+ firing: engine.firing,
540
+ open: !!store.state.open,
541
+ overlayInDom: !!document.querySelector('.psx-pop'),
542
+ anchor: store.state.anchor,
505
543
  }
506
544
  }
507
545
  } catch (e) { /* non-browser context */ }
@@ -566,20 +604,32 @@ window.__ModuleLoader__.load({
566
604
 
567
605
  var [rect, setRect] = React.useState(null)
568
606
  var openPopover = function (event) {
569
- var btnRect = event.currentTarget.getBoundingClientRect()
570
- // Anchor above the composer CARD, not above the button: the button sits
571
- // inside the card, so a button-anchored card would cover the draft text.
572
- var card = event.currentTarget.closest ? event.currentTarget.closest('[data-composer-card]') : null
573
- var cardRect = card ? card.getBoundingClientRect() : null
574
- var anchor = cardRect
575
- ? { left: btnRect.left, top: cardRect.top, bottom: cardRect.bottom, width: btnRect.width, height: cardRect.height }
576
- : { left: btnRect.left, top: btnRect.top, bottom: btnRect.bottom, width: btnRect.width, height: btnRect.height }
607
+ // 状态说"已打开"但 DOM 里没有卡片(渲染抛错 / 宿主重挂过 overlay)时,先当作已关闭:
608
+ // 否则第一次点击只是"关掉一个看不见的卡片",看起来就是按钮失灵、要点两次。
609
+ var rendered = false
610
+ try { rendered = !!document.querySelector('.psx-pop') } catch (e) { rendered = false }
611
+ var isOpen = !!state.open && rendered
612
+ var anchor = null
613
+ try {
614
+ var btnRect = event.currentTarget.getBoundingClientRect()
615
+ // Anchor above the composer CARD, not above the button: the button sits
616
+ // inside the card, so a button-anchored card would cover the draft text.
617
+ var card = event.currentTarget.closest ? event.currentTarget.closest('[data-composer-card]') : null
618
+ var cardRect = card ? card.getBoundingClientRect() : null
619
+ anchor = cardRect
620
+ ? { left: btnRect.left, top: cardRect.top, bottom: cardRect.bottom, width: btnRect.width, height: cardRect.height }
621
+ : { left: btnRect.left, top: btnRect.top, bottom: btnRect.bottom, width: btnRect.width, height: btnRect.height }
622
+ } catch (e) {
623
+ anchor = null
624
+ }
577
625
  syncTimer()
578
626
  patch({
579
- open: !state.open,
627
+ open: !isOpen,
580
628
  sessionId: sessionId,
581
629
  draft: draft,
582
- anchor: anchor,
630
+ // 万一取不到矩形也绝不能给 null:null 会让卡片停在视口外(left/top = -9999),
631
+ // 表现为"点了没反应"。
632
+ anchor: anchor || composerAnchorRect(),
583
633
  })
584
634
  }
585
635
 
@@ -603,7 +653,9 @@ window.__ModuleLoader__.load({
603
653
  var state = useStore()
604
654
  var t = useT()
605
655
  if (!state.open) return null
606
- return h(PopoverPosition, { anchor: state.anchor },
656
+ // 锚点缺失时给一个兜底位置,卡片宁可位置不完美,也不能渲染到视口外。
657
+ var anchor = state.anchor || composerAnchorRect()
658
+ return h(PopoverPosition, { anchor: anchor },
607
659
  h('div', { className: 'psx-card', role: 'dialog', 'aria-modal': 'false', 'aria-label': t('title') }, h(ScheduleCard))
608
660
  )
609
661
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-prompt-scheduler",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Arm a timer on the dsh send button: at the chosen time the plugin presses send for you, so the message that leaves the composer is whatever is in it then.",
5
5
  "keywords": [
6
6
  "dsh",