@konemono/nostr-login 1.7.34 → 1.7.35

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konemono/nostr-login",
3
- "version": "1.7.34",
3
+ "version": "1.7.35",
4
4
  "description": "",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -401,6 +401,7 @@ export class IframeNostrRpc extends NostrRpc {
401
401
 
402
402
  if (!this.iframePort) {
403
403
  try {
404
+ console.log(this.processManager);
404
405
  this.processManager?.pause();
405
406
  await this.ensureConnected();
406
407
  } catch (e) {
@@ -21,13 +21,18 @@ class ProcessManager extends EventEmitter {
21
21
  }
22
22
 
23
23
  private resetTimer() {
24
+ // 既存のタイマーがあればクリア
24
25
  if (this.callTimer) {
25
26
  clearTimeout(this.callTimer);
27
+ this.callTimer = undefined; // IDをクリア
26
28
  console.log('ProcessManager: timer reset');
27
29
  }
28
- if (this.callCount > 0) {
30
+
31
+ // 監視対象が残っていて、かつ一時停止中でなければ、新しいタイマーを設定
32
+ if (this.callCount > 0 && !this.paused) {
29
33
  this.callTimer = setTimeout(() => {
30
34
  console.log('ProcessManager: timeout reached, emitting onCallTimeout');
35
+ this.callTimer = undefined; // タイムアウト時にIDをクリア
31
36
  this.emit('onCallTimeout');
32
37
  }, CALL_TIMEOUT);
33
38
  console.log(`ProcessManager: new timer set for ${CALL_TIMEOUT} ms`);
@@ -37,13 +42,10 @@ class ProcessManager extends EventEmitter {
37
42
  public async wait<T>(cb: () => Promise<T>): Promise<T> {
38
43
  console.log('ProcessManager.wait called, callTimer exists:', !!this.callTimer, 'callCount:', this.callCount);
39
44
 
40
- if (!this.callTimer) {
41
- this.callTimer = setTimeout(() => {
42
- console.log('ProcessManager: timeout reached, emitting onCallTimeout');
43
- this.callTimer = undefined; // ★ タイムアウト時にタイマーIDをクリア
44
- this.emit('onCallTimeout');
45
- }, CALL_TIMEOUT);
46
- console.log(`Setting up timeout timer for ${CALL_TIMEOUT} ms`);
45
+ // 修正点: タイマーの初期設定を resetTimer に任せる
46
+ if (!this.callTimer && this.callCount === 0) {
47
+ // waitの最初の呼び出し時のみ、タイマーを初期設定
48
+ this.resetTimer();
47
49
  }
48
50
 
49
51
  if (!this.callCount) {
@@ -52,7 +54,7 @@ class ProcessManager extends EventEmitter {
52
54
 
53
55
  this.callCount++;
54
56
 
55
- let error: any; // 型をanyに変更
57
+ let error: any;
56
58
  let result: any;
57
59
 
58
60
  // 非同期処理の実行
@@ -62,21 +64,13 @@ class ProcessManager extends EventEmitter {
62
64
  error = e;
63
65
  }
64
66
 
65
- // ★ 修正後のクリーンアップロジック (finallyブロック相当)
66
- // ----------------------------------------------------
67
-
67
+ // ★ 修正点: クリーンアップロジックを resetTimer に置き換え
68
68
  // ProcessManagerの呼び出しカウントをデクリメント
69
69
  this.callCount--;
70
70
  this.emit('onCallEnd');
71
71
 
72
- // タイマーがまだ存在していればクリアし、IDもクリア
73
- // この処理は、cb()が成功/失敗したどちらの場合でも実行される
74
- if (this.callTimer) {
75
- clearTimeout(this.callTimer);
76
- }
77
- this.callTimer = undefined; // ProcessManager のタイマーIDもここでクリア
78
-
79
- // ----------------------------------------------------
72
+ // リクエスト完了後、タイマーをリセットし、callCountに応じて再設定
73
+ this.resetTimer();
80
74
 
81
75
  // エラーがあればスローし、呼び出し元に伝播させる
82
76
  if (error) {
@@ -88,18 +82,24 @@ class ProcessManager extends EventEmitter {
88
82
  }
89
83
 
90
84
  public pause() {
91
- if (this.callTimer) clearTimeout(this.callTimer);
92
- this.callTimer = undefined;
85
+ console.log('ProcessManager: PAUSING timer...');
86
+ if (this.callTimer) {
87
+ clearTimeout(this.callTimer);
88
+ }
89
+ this.callTimer = undefined; // タイマーをクリア
93
90
  this.paused = true;
91
+ this.emit('onCallPause');
94
92
  }
95
93
 
96
94
  public resume() {
95
+ console.log('ProcessManager: RESUMING timer...');
97
96
  this.paused = false;
97
+
98
+ // ★ 修正点: pause解除後、監視対象が残っていればタイマーを再設定 (resetTimerを呼び出す)
98
99
  if (this.callCount > 0 && !this.callTimer) {
99
- this.callTimer = setTimeout(() => {
100
- this.emit('onCallTimeout');
101
- }, CALL_TIMEOUT);
100
+ this.resetTimer();
102
101
  }
102
+ this.emit('onCallResume');
103
103
  }
104
104
  }
105
105