electron-infra-kit 0.0.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.
- package/LICENSE +21 -0
- package/README.md +302 -0
- package/README.zh-CN.md +308 -0
- package/dist/core/error/WindowError.d.ts +56 -0
- package/dist/core/error/WindowError.js +71 -0
- package/dist/core/error/WindowError.js.map +1 -0
- package/dist/core/error/WindowError.mjs +71 -0
- package/dist/core/error/WindowError.mjs.map +1 -0
- package/dist/core/ipc/IpcHandler.d.ts +48 -0
- package/dist/core/ipc/IpcHandler.js +59 -0
- package/dist/core/ipc/IpcHandler.js.map +1 -0
- package/dist/core/ipc/IpcHandler.mjs +59 -0
- package/dist/core/ipc/IpcHandler.mjs.map +1 -0
- package/dist/core/ipc/IpcRouter.d.ts +70 -0
- package/dist/core/ipc/IpcRouter.js +143 -0
- package/dist/core/ipc/IpcRouter.js.map +1 -0
- package/dist/core/ipc/IpcRouter.mjs +143 -0
- package/dist/core/ipc/IpcRouter.mjs.map +1 -0
- package/dist/core/ipc/index.d.ts +3 -0
- package/dist/core/ipc/index.js +1 -0
- package/dist/core/ipc/index.js.map +1 -0
- package/dist/core/ipc/index.mjs +1 -0
- package/dist/core/ipc/index.mjs.map +1 -0
- package/dist/core/ipc/ipc-router.type.d.ts +73 -0
- package/dist/core/ipc/transport/index.d.ts +65 -0
- package/dist/core/ipc/transport/index.js +229 -0
- package/dist/core/ipc/transport/index.js.map +1 -0
- package/dist/core/ipc/transport/index.mjs +229 -0
- package/dist/core/ipc/transport/index.mjs.map +1 -0
- package/dist/core/ipc/transport/ipc.type.d.ts +36 -0
- package/dist/core/lifecycle/LifecycleManager.d.ts +66 -0
- package/dist/core/lifecycle/LifecycleManager.js +140 -0
- package/dist/core/lifecycle/LifecycleManager.js.map +1 -0
- package/dist/core/lifecycle/LifecycleManager.mjs +140 -0
- package/dist/core/lifecycle/LifecycleManager.mjs.map +1 -0
- package/dist/core/message-bus/MessageBus.d.ts +282 -0
- package/dist/core/message-bus/MessageBus.js +677 -0
- package/dist/core/message-bus/MessageBus.js.map +1 -0
- package/dist/core/message-bus/MessageBus.mjs +677 -0
- package/dist/core/message-bus/MessageBus.mjs.map +1 -0
- package/dist/core/message-bus/MessageBusClient.d.ts +100 -0
- package/dist/core/message-bus/MessageBusClient.js +280 -0
- package/dist/core/message-bus/MessageBusClient.js.map +1 -0
- package/dist/core/message-bus/MessageBusClient.mjs +280 -0
- package/dist/core/message-bus/MessageBusClient.mjs.map +1 -0
- package/dist/core/message-bus/core/DataStoreManager.d.ts +51 -0
- package/dist/core/message-bus/core/DataStoreManager.js +94 -0
- package/dist/core/message-bus/core/DataStoreManager.js.map +1 -0
- package/dist/core/message-bus/core/DataStoreManager.mjs +94 -0
- package/dist/core/message-bus/core/DataStoreManager.mjs.map +1 -0
- package/dist/core/message-bus/core/ManagedPort.d.ts +26 -0
- package/dist/core/message-bus/core/ManagedPort.js +55 -0
- package/dist/core/message-bus/core/ManagedPort.js.map +1 -0
- package/dist/core/message-bus/core/ManagedPort.mjs +55 -0
- package/dist/core/message-bus/core/ManagedPort.mjs.map +1 -0
- package/dist/core/message-bus/core/PortManager.d.ts +47 -0
- package/dist/core/message-bus/core/PortManager.js +114 -0
- package/dist/core/message-bus/core/PortManager.js.map +1 -0
- package/dist/core/message-bus/core/PortManager.mjs +114 -0
- package/dist/core/message-bus/core/PortManager.mjs.map +1 -0
- package/dist/core/message-bus/core/SubscriptionManager.d.ts +36 -0
- package/dist/core/message-bus/core/SubscriptionManager.js +78 -0
- package/dist/core/message-bus/core/SubscriptionManager.js.map +1 -0
- package/dist/core/message-bus/core/SubscriptionManager.mjs +78 -0
- package/dist/core/message-bus/core/SubscriptionManager.mjs.map +1 -0
- package/dist/core/message-bus/core/TransactionManager.d.ts +54 -0
- package/dist/core/message-bus/core/TransactionManager.js +95 -0
- package/dist/core/message-bus/core/TransactionManager.js.map +1 -0
- package/dist/core/message-bus/core/TransactionManager.mjs +95 -0
- package/dist/core/message-bus/core/TransactionManager.mjs.map +1 -0
- package/dist/core/message-bus/core/index.d.ts +5 -0
- package/dist/core/message-bus/index.d.ts +4 -0
- package/dist/core/message-bus/index.js +1 -0
- package/dist/core/message-bus/index.js.map +1 -0
- package/dist/core/message-bus/index.mjs +1 -0
- package/dist/core/message-bus/index.mjs.map +1 -0
- package/dist/core/message-bus/message-bus.type.d.ts +143 -0
- package/dist/core/message-bus/message-bus.type.js +26 -0
- package/dist/core/message-bus/message-bus.type.js.map +1 -0
- package/dist/core/message-bus/message-bus.type.mjs +26 -0
- package/dist/core/message-bus/message-bus.type.mjs.map +1 -0
- package/dist/core/message-bus/preload.d.ts +16 -0
- package/dist/core/message-bus/preload.js +27 -0
- package/dist/core/message-bus/preload.js.map +1 -0
- package/dist/core/message-bus/preload.mjs +27 -0
- package/dist/core/message-bus/preload.mjs.map +1 -0
- package/dist/core/message-bus/transport/ITransport.d.ts +40 -0
- package/dist/core/message-bus/transport/IpcTransport.d.ts +18 -0
- package/dist/core/message-bus/transport/IpcTransport.js +60 -0
- package/dist/core/message-bus/transport/IpcTransport.js.map +1 -0
- package/dist/core/message-bus/transport/IpcTransport.mjs +60 -0
- package/dist/core/message-bus/transport/IpcTransport.mjs.map +1 -0
- package/dist/core/message-bus/transport/MessagePortTransport.d.ts +15 -0
- package/dist/core/message-bus/transport/MessagePortTransport.js +35 -0
- package/dist/core/message-bus/transport/MessagePortTransport.js.map +1 -0
- package/dist/core/message-bus/transport/MessagePortTransport.mjs +35 -0
- package/dist/core/message-bus/transport/MessagePortTransport.mjs.map +1 -0
- package/dist/core/message-bus/transport/index.d.ts +3 -0
- package/dist/core/window/IpcSetup.d.ts +50 -0
- package/dist/core/window/IpcSetup.js +96 -0
- package/dist/core/window/IpcSetup.js.map +1 -0
- package/dist/core/window/IpcSetup.mjs +96 -0
- package/dist/core/window/IpcSetup.mjs.map +1 -0
- package/dist/core/window/WindowCreator.d.ts +66 -0
- package/dist/core/window/WindowCreator.js +168 -0
- package/dist/core/window/WindowCreator.js.map +1 -0
- package/dist/core/window/WindowCreator.mjs +168 -0
- package/dist/core/window/WindowCreator.mjs.map +1 -0
- package/dist/core/window/WindowManager.d.ts +214 -0
- package/dist/core/window/WindowManager.js +583 -0
- package/dist/core/window/WindowManager.js.map +1 -0
- package/dist/core/window/WindowManager.mjs +583 -0
- package/dist/core/window/WindowManager.mjs.map +1 -0
- package/dist/core/window/WindowStore.d.ts +136 -0
- package/dist/core/window/WindowStore.js +436 -0
- package/dist/core/window/WindowStore.js.map +1 -0
- package/dist/core/window/WindowStore.mjs +436 -0
- package/dist/core/window/WindowStore.mjs.map +1 -0
- package/dist/core/window/constants.d.ts +17 -0
- package/dist/core/window/constants.js +15 -0
- package/dist/core/window/constants.js.map +1 -0
- package/dist/core/window/constants.mjs +15 -0
- package/dist/core/window/constants.mjs.map +1 -0
- package/dist/core/window/core/MetricsManager.d.ts +14 -0
- package/dist/core/window/core/MetricsManager.js +27 -0
- package/dist/core/window/core/MetricsManager.js.map +1 -0
- package/dist/core/window/core/MetricsManager.mjs +27 -0
- package/dist/core/window/core/MetricsManager.mjs.map +1 -0
- package/dist/core/window/core/PluginExecutor.d.ts +22 -0
- package/dist/core/window/core/PluginExecutor.js +110 -0
- package/dist/core/window/core/PluginExecutor.js.map +1 -0
- package/dist/core/window/core/PluginExecutor.mjs +110 -0
- package/dist/core/window/core/PluginExecutor.mjs.map +1 -0
- package/dist/core/window/core/WindowContextManager.d.ts +26 -0
- package/dist/core/window/core/WindowContextManager.js +59 -0
- package/dist/core/window/core/WindowContextManager.js.map +1 -0
- package/dist/core/window/core/WindowContextManager.mjs +59 -0
- package/dist/core/window/core/WindowContextManager.mjs.map +1 -0
- package/dist/core/window/core/WindowLifecycle.d.ts +15 -0
- package/dist/core/window/core/WindowLifecycle.js +150 -0
- package/dist/core/window/core/WindowLifecycle.js.map +1 -0
- package/dist/core/window/core/WindowLifecycle.mjs +150 -0
- package/dist/core/window/core/WindowLifecycle.mjs.map +1 -0
- package/dist/core/window/core/WindowOperator.d.ts +90 -0
- package/dist/core/window/core/WindowOperator.js +154 -0
- package/dist/core/window/core/WindowOperator.js.map +1 -0
- package/dist/core/window/core/WindowOperator.mjs +154 -0
- package/dist/core/window/core/WindowOperator.mjs.map +1 -0
- package/dist/core/window/core/WindowRegistry.d.ts +168 -0
- package/dist/core/window/core/WindowRegistry.js +331 -0
- package/dist/core/window/core/WindowRegistry.js.map +1 -0
- package/dist/core/window/core/WindowRegistry.mjs +331 -0
- package/dist/core/window/core/WindowRegistry.mjs.map +1 -0
- package/dist/core/window/core/WindowStateManager.d.ts +40 -0
- package/dist/core/window/core/WindowStateManager.js +110 -0
- package/dist/core/window/core/WindowStateManager.js.map +1 -0
- package/dist/core/window/core/WindowStateManager.mjs +110 -0
- package/dist/core/window/core/WindowStateManager.mjs.map +1 -0
- package/dist/core/window/index.d.ts +7 -0
- package/dist/core/window/index.js +1 -0
- package/dist/core/window/index.js.map +1 -0
- package/dist/core/window/index.mjs +1 -0
- package/dist/core/window/index.mjs.map +1 -0
- package/dist/core/window/window-manager.schema.d.ts +50 -0
- package/dist/core/window/window-manager.schema.js +87 -0
- package/dist/core/window/window-manager.schema.js.map +1 -0
- package/dist/core/window/window-manager.schema.mjs +87 -0
- package/dist/core/window/window-manager.schema.mjs.map +1 -0
- package/dist/core/window/window-manager.type.d.ts +365 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +33 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.umd.js +1 -0
- package/dist/infrastructure/config/ConfigManager.d.ts +133 -0
- package/dist/infrastructure/config/ConfigManager.js +218 -0
- package/dist/infrastructure/config/ConfigManager.js.map +1 -0
- package/dist/infrastructure/config/ConfigManager.mjs +218 -0
- package/dist/infrastructure/config/ConfigManager.mjs.map +1 -0
- package/dist/infrastructure/config/index.d.ts +1 -0
- package/dist/infrastructure/debug/EnhancedDebugHelper.d.ts +106 -0
- package/dist/infrastructure/debug/EnhancedDebugHelper.js +218 -0
- package/dist/infrastructure/debug/EnhancedDebugHelper.js.map +1 -0
- package/dist/infrastructure/debug/EnhancedDebugHelper.mjs +218 -0
- package/dist/infrastructure/debug/EnhancedDebugHelper.mjs.map +1 -0
- package/dist/infrastructure/debug/PerformanceMonitor.d.ts +45 -0
- package/dist/infrastructure/debug/PerformanceMonitor.js +67 -0
- package/dist/infrastructure/debug/PerformanceMonitor.js.map +1 -0
- package/dist/infrastructure/debug/PerformanceMonitor.mjs +67 -0
- package/dist/infrastructure/debug/PerformanceMonitor.mjs.map +1 -0
- package/dist/infrastructure/debug/index.d.ts +22 -0
- package/dist/infrastructure/debug/index.js +47 -0
- package/dist/infrastructure/debug/index.js.map +1 -0
- package/dist/infrastructure/debug/index.mjs +47 -0
- package/dist/infrastructure/debug/index.mjs.map +1 -0
- package/dist/infrastructure/errors/ErrorCodes.d.ts +74 -0
- package/dist/infrastructure/errors/ErrorCodes.js +78 -0
- package/dist/infrastructure/errors/ErrorCodes.js.map +1 -0
- package/dist/infrastructure/errors/ErrorCodes.mjs +78 -0
- package/dist/infrastructure/errors/ErrorCodes.mjs.map +1 -0
- package/dist/infrastructure/errors/StandardError.d.ts +61 -0
- package/dist/infrastructure/errors/StandardError.js +84 -0
- package/dist/infrastructure/errors/StandardError.js.map +1 -0
- package/dist/infrastructure/errors/StandardError.mjs +84 -0
- package/dist/infrastructure/errors/StandardError.mjs.map +1 -0
- package/dist/infrastructure/errors/index.d.ts +13 -0
- package/dist/infrastructure/errors/index.js +24 -0
- package/dist/infrastructure/errors/index.js.map +1 -0
- package/dist/infrastructure/errors/index.mjs +24 -0
- package/dist/infrastructure/errors/index.mjs.map +1 -0
- package/dist/infrastructure/logger/ElectronLogger.d.ts +39 -0
- package/dist/infrastructure/logger/ElectronLogger.js +65 -0
- package/dist/infrastructure/logger/ElectronLogger.js.map +1 -0
- package/dist/infrastructure/logger/ElectronLogger.mjs +65 -0
- package/dist/infrastructure/logger/ElectronLogger.mjs.map +1 -0
- package/dist/infrastructure/logger/index.d.ts +2 -0
- package/dist/infrastructure/logger/logger.type.d.ts +8 -0
- package/dist/internal/types/BrandedTypes.d.ts +64 -0
- package/dist/internal/types/BrandedTypes.js +54 -0
- package/dist/internal/types/BrandedTypes.js.map +1 -0
- package/dist/internal/types/BrandedTypes.mjs +54 -0
- package/dist/internal/types/BrandedTypes.mjs.map +1 -0
- package/dist/internal/types/PerformanceOptions.d.ts +87 -0
- package/dist/internal/types/branded.d.ts +42 -0
- package/dist/internal/utils/MessageDispatcher.d.ts +67 -0
- package/dist/internal/utils/MessageDispatcher.js +96 -0
- package/dist/internal/utils/MessageDispatcher.js.map +1 -0
- package/dist/internal/utils/MessageDispatcher.mjs +96 -0
- package/dist/internal/utils/MessageDispatcher.mjs.map +1 -0
- package/dist/internal/utils/RateLimiter.d.ts +41 -0
- package/dist/internal/utils/RateLimiter.js +83 -0
- package/dist/internal/utils/RateLimiter.js.map +1 -0
- package/dist/internal/utils/RateLimiter.mjs +83 -0
- package/dist/internal/utils/RateLimiter.mjs.map +1 -0
- package/dist/internal/utils/StateKeeper.d.ts +125 -0
- package/dist/internal/utils/StateKeeper.js +334 -0
- package/dist/internal/utils/StateKeeper.js.map +1 -0
- package/dist/internal/utils/StateKeeper.mjs +334 -0
- package/dist/internal/utils/StateKeeper.mjs.map +1 -0
- package/dist/internal/utils/branded-helpers.d.ts +33 -0
- package/dist/internal/utils/index.d.ts +5 -0
- package/dist/preload/index.d.ts +45 -0
- package/dist/preload/index.js +91 -0
- package/dist/preload/index.js.map +1 -0
- package/dist/preload/index.mjs +91 -0
- package/dist/preload/index.mjs.map +1 -0
- package/dist/preload/preload.type.d.ts +15 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +1 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +143 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ManagedPort - Wrapper for MessagePortMain to track closed state
|
|
3
|
+
* ManagedPort - MessagePortMain 的包装器,用于追踪关闭状态
|
|
4
|
+
*/
|
|
5
|
+
class ManagedPort {
|
|
6
|
+
port;
|
|
7
|
+
_isClosed = false;
|
|
8
|
+
constructor(port) {
|
|
9
|
+
this.port = port;
|
|
10
|
+
}
|
|
11
|
+
get isClosed() {
|
|
12
|
+
return this._isClosed;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Safe postMessage
|
|
16
|
+
* 安全发送消息
|
|
17
|
+
*/
|
|
18
|
+
postMessage(message) {
|
|
19
|
+
if (this._isClosed) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
this.port.postMessage(message);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
// If error occurs, assume port is closed/invalid
|
|
28
|
+
// 如果发生错误,假设端口已关闭/无效
|
|
29
|
+
this._isClosed = true;
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Safe close
|
|
35
|
+
* 安全关闭
|
|
36
|
+
*/
|
|
37
|
+
close() {
|
|
38
|
+
if (this._isClosed)
|
|
39
|
+
return;
|
|
40
|
+
this._isClosed = true;
|
|
41
|
+
try {
|
|
42
|
+
this.port.close();
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
// Ignore close errors
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get underlying port (use with caution)
|
|
50
|
+
* 获取底层端口(谨慎使用)
|
|
51
|
+
*/
|
|
52
|
+
get rawPort() {
|
|
53
|
+
return this.port;
|
|
54
|
+
}
|
|
55
|
+
}export{ManagedPort};//# sourceMappingURL=ManagedPort.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ManagedPort.mjs","sources":["../../../../src/core/message-bus/core/ManagedPort.ts"],"sourcesContent":["import { MessagePortMain } from 'electron';\n\n/**\n * ManagedPort - Wrapper for MessagePortMain to track closed state\n * ManagedPort - MessagePortMain 的包装器,用于追踪关闭状态\n */\nexport class ManagedPort {\n private port: MessagePortMain;\n private _isClosed: boolean = false;\n\n constructor(port: MessagePortMain) {\n this.port = port;\n }\n\n get isClosed() {\n return this._isClosed;\n }\n\n /**\n * Safe postMessage\n * 安全发送消息\n */\n postMessage(message: any): boolean {\n if (this._isClosed) {\n return false;\n }\n try {\n this.port.postMessage(message);\n return true;\n } catch (error) {\n // If error occurs, assume port is closed/invalid\n // 如果发生错误,假设端口已关闭/无效\n this._isClosed = true;\n throw error;\n }\n }\n\n /**\n * Safe close\n * 安全关闭\n */\n close(): void {\n if (this._isClosed) return;\n this._isClosed = true;\n try {\n this.port.close();\n } catch (error) {\n // Ignore close errors\n }\n }\n\n /**\n * Get underlying port (use with caution)\n * 获取底层端口(谨慎使用)\n */\n get rawPort(): MessagePortMain {\n return this.port;\n }\n}\n"],"names":[],"mappings":"AAEA;;;AAGG;MACU,WAAW,CAAA;AACd,IAAA,IAAI;IACJ,SAAS,GAAY,KAAK;AAElC,IAAA,WAAA,CAAY,IAAqB,EAAA;AAC/B,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;IAClB;AAEA,IAAA,IAAI,QAAQ,GAAA;QACV,OAAO,IAAI,CAAC,SAAS;IACvB;AAEA;;;AAGG;AACH,IAAA,WAAW,CAAC,OAAY,EAAA;AACtB,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAClB,YAAA,OAAO,KAAK;QACd;AACA,QAAA,IAAI;AACF,YAAA,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;AAC9B,YAAA,OAAO,IAAI;QACb;QAAE,OAAO,KAAK,EAAE;;;AAGd,YAAA,IAAI,CAAC,SAAS,GAAG,IAAI;AACrB,YAAA,MAAM,KAAK;QACb;IACF;AAEA;;;AAGG;IACH,KAAK,GAAA;QACH,IAAI,IAAI,CAAC,SAAS;YAAE;AACpB,QAAA,IAAI,CAAC,SAAS,GAAG,IAAI;AACrB,QAAA,IAAI;AACF,YAAA,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;QACnB;QAAE,OAAO,KAAK,EAAE;;QAEhB;IACF;AAEA;;;AAGG;AACH,IAAA,IAAI,OAAO,GAAA;QACT,OAAO,IAAI,CAAC,IAAI;IAClB;AACD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BrowserWindow } from 'electron';
|
|
2
|
+
import { ILogger } from '@/infrastructure/logger';
|
|
3
|
+
import { ManagedPort } from './ManagedPort';
|
|
4
|
+
/**
|
|
5
|
+
* PortManager - Manages window message ports
|
|
6
|
+
* PortManager - 管理窗口消息端口
|
|
7
|
+
*/
|
|
8
|
+
export declare class PortManager {
|
|
9
|
+
private ports;
|
|
10
|
+
private logger;
|
|
11
|
+
constructor(logger: ILogger);
|
|
12
|
+
/**
|
|
13
|
+
* Register a port for a window
|
|
14
|
+
* 为窗口注册端口
|
|
15
|
+
* @param windowId Window ID
|
|
16
|
+
* @param window BrowserWindow instance
|
|
17
|
+
* @param onMessage Message handler callback
|
|
18
|
+
*/
|
|
19
|
+
register(windowId: string, window: BrowserWindow, onMessage: (msg: any, port: ManagedPort) => void): void;
|
|
20
|
+
/**
|
|
21
|
+
* Unregister a window port
|
|
22
|
+
* 注销窗口端口
|
|
23
|
+
*/
|
|
24
|
+
unregister(windowId: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Get a managed port
|
|
27
|
+
* 获取托管端口
|
|
28
|
+
*/
|
|
29
|
+
get(windowId: string): ManagedPort | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Broadcast message to specific windows or all windows
|
|
32
|
+
* 广播消息到指定窗口或所有窗口
|
|
33
|
+
* @param message Serialized message string
|
|
34
|
+
* @param windowIds Target window IDs (optional)
|
|
35
|
+
*/
|
|
36
|
+
broadcast(message: string, windowIds?: string[]): number;
|
|
37
|
+
/**
|
|
38
|
+
* Dispose all ports
|
|
39
|
+
* 释放所有端口
|
|
40
|
+
*/
|
|
41
|
+
dispose(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get all registered window IDs
|
|
44
|
+
* 获取所有已注册的窗口 ID
|
|
45
|
+
*/
|
|
46
|
+
getAllWindowIds(): string[];
|
|
47
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';var electron=require('electron'),ManagedPort=require('./ManagedPort.js'),constants=require('../../window/constants.js');/**
|
|
2
|
+
* PortManager - Manages window message ports
|
|
3
|
+
* PortManager - 管理窗口消息端口
|
|
4
|
+
*/
|
|
5
|
+
class PortManager {
|
|
6
|
+
ports = new Map();
|
|
7
|
+
logger;
|
|
8
|
+
constructor(logger) {
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Register a port for a window
|
|
13
|
+
* 为窗口注册端口
|
|
14
|
+
* @param windowId Window ID
|
|
15
|
+
* @param window BrowserWindow instance
|
|
16
|
+
* @param onMessage Message handler callback
|
|
17
|
+
*/
|
|
18
|
+
register(windowId, window, onMessage) {
|
|
19
|
+
this.unregister(windowId);
|
|
20
|
+
const { port1, port2 } = new electron.MessageChannelMain();
|
|
21
|
+
const managedPort = new ManagedPort.ManagedPort(port1);
|
|
22
|
+
this.ports.set(windowId, managedPort);
|
|
23
|
+
// Listen for messages
|
|
24
|
+
port1.on('message', (event) => {
|
|
25
|
+
let msg;
|
|
26
|
+
try {
|
|
27
|
+
msg = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
this.logger.error(`Failed to parse message from window ${windowId}: ${error}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
onMessage(msg, managedPort);
|
|
34
|
+
});
|
|
35
|
+
port1.start();
|
|
36
|
+
// Inject port
|
|
37
|
+
const injectPort = () => {
|
|
38
|
+
try {
|
|
39
|
+
window.webContents.postMessage(constants.IPC_CHANNELS.MESSAGE_BUS_PORT, null, [port2]);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
this.logger.error(`Failed to post message to window ${windowId}: ${error}`);
|
|
43
|
+
// Cleanup
|
|
44
|
+
managedPort.close();
|
|
45
|
+
this.ports.delete(windowId);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (window.webContents.isLoading()) {
|
|
49
|
+
window.webContents.once('did-finish-load', injectPort);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
injectPort();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Unregister a window port
|
|
57
|
+
* 注销窗口端口
|
|
58
|
+
*/
|
|
59
|
+
unregister(windowId) {
|
|
60
|
+
const port = this.ports.get(windowId);
|
|
61
|
+
if (port) {
|
|
62
|
+
port.close();
|
|
63
|
+
this.ports.delete(windowId);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get a managed port
|
|
70
|
+
* 获取托管端口
|
|
71
|
+
*/
|
|
72
|
+
get(windowId) {
|
|
73
|
+
return this.ports.get(windowId);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Broadcast message to specific windows or all windows
|
|
77
|
+
* 广播消息到指定窗口或所有窗口
|
|
78
|
+
* @param message Serialized message string
|
|
79
|
+
* @param windowIds Target window IDs (optional)
|
|
80
|
+
*/
|
|
81
|
+
broadcast(message, windowIds) {
|
|
82
|
+
let successCount = 0;
|
|
83
|
+
const targets = windowIds || Array.from(this.ports.keys());
|
|
84
|
+
targets.forEach((id) => {
|
|
85
|
+
const port = this.ports.get(id);
|
|
86
|
+
if (port) {
|
|
87
|
+
try {
|
|
88
|
+
if (port.postMessage(message)) {
|
|
89
|
+
successCount++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
this.logger.error(`Failed to broadcast to window ${id}: ${error}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return successCount;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Dispose all ports
|
|
101
|
+
* 释放所有端口
|
|
102
|
+
*/
|
|
103
|
+
dispose() {
|
|
104
|
+
this.ports.forEach((port) => port.close());
|
|
105
|
+
this.ports.clear();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get all registered window IDs
|
|
109
|
+
* 获取所有已注册的窗口 ID
|
|
110
|
+
*/
|
|
111
|
+
getAllWindowIds() {
|
|
112
|
+
return Array.from(this.ports.keys());
|
|
113
|
+
}
|
|
114
|
+
}exports.PortManager=PortManager;//# sourceMappingURL=PortManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortManager.js","sources":["../../../../src/core/message-bus/core/PortManager.ts"],"sourcesContent":["import { BrowserWindow, MessageChannelMain } from 'electron';\nimport { ILogger } from '@/infrastructure/logger';\nimport { ManagedPort } from './ManagedPort';\nimport { IPC_CHANNELS } from '@/core/window/constants';\n\n/**\n * PortManager - Manages window message ports\n * PortManager - 管理窗口消息端口\n */\nexport class PortManager {\n private ports: Map<string, ManagedPort> = new Map();\n private logger: ILogger;\n\n constructor(logger: ILogger) {\n this.logger = logger;\n }\n\n /**\n * Register a port for a window\n * 为窗口注册端口\n * @param windowId Window ID\n * @param window BrowserWindow instance\n * @param onMessage Message handler callback\n */\n register(\n windowId: string,\n window: BrowserWindow,\n onMessage: (msg: any, port: ManagedPort) => void\n ): void {\n this.unregister(windowId);\n\n const { port1, port2 } = new MessageChannelMain();\n const managedPort = new ManagedPort(port1);\n this.ports.set(windowId, managedPort);\n\n // Listen for messages\n port1.on('message', (event) => {\n let msg: any;\n try {\n msg = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;\n } catch (error) {\n this.logger.error(`Failed to parse message from window ${windowId}: ${error}`);\n return;\n }\n\n onMessage(msg, managedPort);\n });\n port1.start();\n\n // Inject port\n const injectPort = () => {\n try {\n window.webContents.postMessage(IPC_CHANNELS.MESSAGE_BUS_PORT, null, [port2]);\n } catch (error) {\n this.logger.error(`Failed to post message to window ${windowId}: ${error}`);\n // Cleanup\n managedPort.close();\n this.ports.delete(windowId);\n }\n };\n\n if (window.webContents.isLoading()) {\n window.webContents.once('did-finish-load', injectPort);\n } else {\n injectPort();\n }\n }\n\n /**\n * Unregister a window port\n * 注销窗口端口\n */\n unregister(windowId: string): boolean {\n const port = this.ports.get(windowId);\n if (port) {\n port.close();\n this.ports.delete(windowId);\n return true;\n }\n return false;\n }\n\n /**\n * Get a managed port\n * 获取托管端口\n */\n get(windowId: string): ManagedPort | undefined {\n return this.ports.get(windowId);\n }\n\n /**\n * Broadcast message to specific windows or all windows\n * 广播消息到指定窗口或所有窗口\n * @param message Serialized message string\n * @param windowIds Target window IDs (optional)\n */\n broadcast(message: string, windowIds?: string[]): number {\n let successCount = 0;\n const targets = windowIds || Array.from(this.ports.keys());\n\n targets.forEach((id) => {\n const port = this.ports.get(id);\n if (port) {\n try {\n if (port.postMessage(message)) {\n successCount++;\n }\n } catch (error) {\n this.logger.error(`Failed to broadcast to window ${id}: ${error}`);\n }\n }\n });\n\n return successCount;\n }\n\n /**\n * Dispose all ports\n * 释放所有端口\n */\n dispose(): void {\n this.ports.forEach((port) => port.close());\n this.ports.clear();\n }\n\n /**\n * Get all registered window IDs\n * 获取所有已注册的窗口 ID\n */\n getAllWindowIds(): string[] {\n return Array.from(this.ports.keys());\n }\n}\n"],"names":["MessageChannelMain","ManagedPort","IPC_CHANNELS"],"mappings":"qIAKA;;;AAGG;MACU,WAAW,CAAA;AACd,IAAA,KAAK,GAA6B,IAAI,GAAG,EAAE;AAC3C,IAAA,MAAM;AAEd,IAAA,WAAA,CAAY,MAAe,EAAA;AACzB,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;IACtB;AAEA;;;;;;AAMG;AACH,IAAA,QAA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AAO,YAAY;IACrB;AAEA;;;AAGG;IACH,OAAO,GAAA;AACL,QAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;AAC1C,QAAA,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;IACpB;AAEA;;;AAGG;IACH,eAAe,GAAA;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACtC;AACD"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {MessageChannelMain}from'electron';import {ManagedPort}from'./ManagedPort.mjs';import {IPC_CHANNELS}from'../../window/constants.mjs';/**
|
|
2
|
+
* PortManager - Manages window message ports
|
|
3
|
+
* PortManager - 管理窗口消息端口
|
|
4
|
+
*/
|
|
5
|
+
class PortManager {
|
|
6
|
+
ports = new Map();
|
|
7
|
+
logger;
|
|
8
|
+
constructor(logger) {
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Register a port for a window
|
|
13
|
+
* 为窗口注册端口
|
|
14
|
+
* @param windowId Window ID
|
|
15
|
+
* @param window BrowserWindow instance
|
|
16
|
+
* @param onMessage Message handler callback
|
|
17
|
+
*/
|
|
18
|
+
register(windowId, window, onMessage) {
|
|
19
|
+
this.unregister(windowId);
|
|
20
|
+
const { port1, port2 } = new MessageChannelMain();
|
|
21
|
+
const managedPort = new ManagedPort(port1);
|
|
22
|
+
this.ports.set(windowId, managedPort);
|
|
23
|
+
// Listen for messages
|
|
24
|
+
port1.on('message', (event) => {
|
|
25
|
+
let msg;
|
|
26
|
+
try {
|
|
27
|
+
msg = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
this.logger.error(`Failed to parse message from window ${windowId}: ${error}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
onMessage(msg, managedPort);
|
|
34
|
+
});
|
|
35
|
+
port1.start();
|
|
36
|
+
// Inject port
|
|
37
|
+
const injectPort = () => {
|
|
38
|
+
try {
|
|
39
|
+
window.webContents.postMessage(IPC_CHANNELS.MESSAGE_BUS_PORT, null, [port2]);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
this.logger.error(`Failed to post message to window ${windowId}: ${error}`);
|
|
43
|
+
// Cleanup
|
|
44
|
+
managedPort.close();
|
|
45
|
+
this.ports.delete(windowId);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (window.webContents.isLoading()) {
|
|
49
|
+
window.webContents.once('did-finish-load', injectPort);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
injectPort();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Unregister a window port
|
|
57
|
+
* 注销窗口端口
|
|
58
|
+
*/
|
|
59
|
+
unregister(windowId) {
|
|
60
|
+
const port = this.ports.get(windowId);
|
|
61
|
+
if (port) {
|
|
62
|
+
port.close();
|
|
63
|
+
this.ports.delete(windowId);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get a managed port
|
|
70
|
+
* 获取托管端口
|
|
71
|
+
*/
|
|
72
|
+
get(windowId) {
|
|
73
|
+
return this.ports.get(windowId);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Broadcast message to specific windows or all windows
|
|
77
|
+
* 广播消息到指定窗口或所有窗口
|
|
78
|
+
* @param message Serialized message string
|
|
79
|
+
* @param windowIds Target window IDs (optional)
|
|
80
|
+
*/
|
|
81
|
+
broadcast(message, windowIds) {
|
|
82
|
+
let successCount = 0;
|
|
83
|
+
const targets = windowIds || Array.from(this.ports.keys());
|
|
84
|
+
targets.forEach((id) => {
|
|
85
|
+
const port = this.ports.get(id);
|
|
86
|
+
if (port) {
|
|
87
|
+
try {
|
|
88
|
+
if (port.postMessage(message)) {
|
|
89
|
+
successCount++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
this.logger.error(`Failed to broadcast to window ${id}: ${error}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return successCount;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Dispose all ports
|
|
101
|
+
* 释放所有端口
|
|
102
|
+
*/
|
|
103
|
+
dispose() {
|
|
104
|
+
this.ports.forEach((port) => port.close());
|
|
105
|
+
this.ports.clear();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get all registered window IDs
|
|
109
|
+
* 获取所有已注册的窗口 ID
|
|
110
|
+
*/
|
|
111
|
+
getAllWindowIds() {
|
|
112
|
+
return Array.from(this.ports.keys());
|
|
113
|
+
}
|
|
114
|
+
}export{PortManager};//# sourceMappingURL=PortManager.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortManager.mjs","sources":["../../../../src/core/message-bus/core/PortManager.ts"],"sourcesContent":["import { BrowserWindow, MessageChannelMain } from 'electron';\nimport { ILogger } from '@/infrastructure/logger';\nimport { ManagedPort } from './ManagedPort';\nimport { IPC_CHANNELS } from '@/core/window/constants';\n\n/**\n * PortManager - Manages window message ports\n * PortManager - 管理窗口消息端口\n */\nexport class PortManager {\n private ports: Map<string, ManagedPort> = new Map();\n private logger: ILogger;\n\n constructor(logger: ILogger) {\n this.logger = logger;\n }\n\n /**\n * Register a port for a window\n * 为窗口注册端口\n * @param windowId Window ID\n * @param window BrowserWindow instance\n * @param onMessage Message handler callback\n */\n register(\n windowId: string,\n window: BrowserWindow,\n onMessage: (msg: any, port: ManagedPort) => void\n ): void {\n this.unregister(windowId);\n\n const { port1, port2 } = new MessageChannelMain();\n const managedPort = new ManagedPort(port1);\n this.ports.set(windowId, managedPort);\n\n // Listen for messages\n port1.on('message', (event) => {\n let msg: any;\n try {\n msg = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;\n } catch (error) {\n this.logger.error(`Failed to parse message from window ${windowId}: ${error}`);\n return;\n }\n\n onMessage(msg, managedPort);\n });\n port1.start();\n\n // Inject port\n const injectPort = () => {\n try {\n window.webContents.postMessage(IPC_CHANNELS.MESSAGE_BUS_PORT, null, [port2]);\n } catch (error) {\n this.logger.error(`Failed to post message to window ${windowId}: ${error}`);\n // Cleanup\n managedPort.close();\n this.ports.delete(windowId);\n }\n };\n\n if (window.webContents.isLoading()) {\n window.webContents.once('did-finish-load', injectPort);\n } else {\n injectPort();\n }\n }\n\n /**\n * Unregister a window port\n * 注销窗口端口\n */\n unregister(windowId: string): boolean {\n const port = this.ports.get(windowId);\n if (port) {\n port.close();\n this.ports.delete(windowId);\n return true;\n }\n return false;\n }\n\n /**\n * Get a managed port\n * 获取托管端口\n */\n get(windowId: string): ManagedPort | undefined {\n return this.ports.get(windowId);\n }\n\n /**\n * Broadcast message to specific windows or all windows\n * 广播消息到指定窗口或所有窗口\n * @param message Serialized message string\n * @param windowIds Target window IDs (optional)\n */\n broadcast(message: string, windowIds?: string[]): number {\n let successCount = 0;\n const targets = windowIds || Array.from(this.ports.keys());\n\n targets.forEach((id) => {\n const port = this.ports.get(id);\n if (port) {\n try {\n if (port.postMessage(message)) {\n successCount++;\n }\n } catch (error) {\n this.logger.error(`Failed to broadcast to window ${id}: ${error}`);\n }\n }\n });\n\n return successCount;\n }\n\n /**\n * Dispose all ports\n * 释放所有端口\n */\n dispose(): void {\n this.ports.forEach((port) => port.close());\n this.ports.clear();\n }\n\n /**\n * Get all registered window IDs\n * 获取所有已注册的窗口 ID\n */\n getAllWindowIds(): string[] {\n return Array.from(this.ports.keys());\n }\n}\n"],"names":[],"mappings":"4IAKA;;;AAGG;MACU,WAAW,CAAA;AACd,IAAA,KAAK,GAA6B,IAAI,GAAG,EAAE;AAC3C,IAAA,MAAM;AAEd,IAAA,WAAA,CAAY,MAAe,EAAA;AACzB,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AK,CAAA,CAAE,CAAC;gBACpE;YACF;AACF,QAAA,CAAC,CAAC;AAEF,QAAA,OAAO,YAAY;IACrB;AAEA;;;AAGG;IACH,OAAO,GAAA;AACL,QAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;AAC1C,QAAA,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;IACpB;AAEA;;;AAGG;IACH,eAAe,GAAA;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACtC;AACD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ILogger } from '@/infrastructure/logger';
|
|
2
|
+
/**
|
|
3
|
+
* SubscriptionManager - Manages message subscriptions
|
|
4
|
+
* SubscriptionManager - 管理消息订阅
|
|
5
|
+
*/
|
|
6
|
+
export declare class SubscriptionManager {
|
|
7
|
+
private subscriptions;
|
|
8
|
+
private logger?;
|
|
9
|
+
private readonly MAX_SUBSCRIPTIONS_PER_KEY;
|
|
10
|
+
constructor(logger?: ILogger);
|
|
11
|
+
/**
|
|
12
|
+
* Subscribe to keys
|
|
13
|
+
* 订阅键
|
|
14
|
+
*/
|
|
15
|
+
subscribe(windowId: string, keys: string[]): void;
|
|
16
|
+
/**
|
|
17
|
+
* Unsubscribe from keys
|
|
18
|
+
* 取消订阅键
|
|
19
|
+
*/
|
|
20
|
+
unsubscribe(windowId: string, keys: string[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Remove all subscriptions for a window
|
|
23
|
+
* 移除窗口的所有订阅
|
|
24
|
+
*/
|
|
25
|
+
removeWindow(windowId: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get subscribers for a key
|
|
28
|
+
* 获取键的订阅者
|
|
29
|
+
*/
|
|
30
|
+
getSubscribers(key: string): Set<string> | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Clear all subscriptions
|
|
33
|
+
* 清除所有订阅
|
|
34
|
+
*/
|
|
35
|
+
clear(): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';/**
|
|
2
|
+
* SubscriptionManager - Manages message subscriptions
|
|
3
|
+
* SubscriptionManager - 管理消息订阅
|
|
4
|
+
*/
|
|
5
|
+
class SubscriptionManager {
|
|
6
|
+
// Key subscriptions map: key -> Set<windowId>
|
|
7
|
+
// 键值订阅映射:key -> Set<windowId>
|
|
8
|
+
subscriptions = new Map();
|
|
9
|
+
logger;
|
|
10
|
+
MAX_SUBSCRIPTIONS_PER_KEY = 100;
|
|
11
|
+
constructor(logger) {
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Subscribe to keys
|
|
16
|
+
* 订阅键
|
|
17
|
+
*/
|
|
18
|
+
subscribe(windowId, keys) {
|
|
19
|
+
keys.forEach((key) => {
|
|
20
|
+
if (!this.subscriptions.has(key)) {
|
|
21
|
+
this.subscriptions.set(key, new Set());
|
|
22
|
+
}
|
|
23
|
+
const subscribers = this.subscriptions.get(key);
|
|
24
|
+
subscribers.add(windowId);
|
|
25
|
+
// Check for potential memory leak / high usage
|
|
26
|
+
if (this.logger && subscribers.size > this.MAX_SUBSCRIPTIONS_PER_KEY) {
|
|
27
|
+
// Debounce warning or just warn? For now just warn.
|
|
28
|
+
// Avoid flooding logs? Maybe only warn on exact multiples or just > 100
|
|
29
|
+
if (subscribers.size === this.MAX_SUBSCRIPTIONS_PER_KEY + 1) {
|
|
30
|
+
this.logger.warn(`High number of subscriptions (${subscribers.size}) for key: "${key}". Potential memory leak or design issue.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Unsubscribe from keys
|
|
37
|
+
* 取消订阅键
|
|
38
|
+
*/
|
|
39
|
+
unsubscribe(windowId, keys) {
|
|
40
|
+
keys.forEach((key) => {
|
|
41
|
+
const subscribers = this.subscriptions.get(key);
|
|
42
|
+
if (subscribers) {
|
|
43
|
+
subscribers.delete(windowId);
|
|
44
|
+
if (subscribers.size === 0) {
|
|
45
|
+
this.subscriptions.delete(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Remove all subscriptions for a window
|
|
52
|
+
* 移除窗口的所有订阅
|
|
53
|
+
*/
|
|
54
|
+
removeWindow(windowId) {
|
|
55
|
+
this.subscriptions.forEach((subscribers, key) => {
|
|
56
|
+
if (subscribers.has(windowId)) {
|
|
57
|
+
subscribers.delete(windowId);
|
|
58
|
+
if (subscribers.size === 0) {
|
|
59
|
+
this.subscriptions.delete(key);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get subscribers for a key
|
|
66
|
+
* 获取键的订阅者
|
|
67
|
+
*/
|
|
68
|
+
getSubscribers(key) {
|
|
69
|
+
return this.subscriptions.get(key);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Clear all subscriptions
|
|
73
|
+
* 清除所有订阅
|
|
74
|
+
*/
|
|
75
|
+
clear() {
|
|
76
|
+
this.subscriptions.clear();
|
|
77
|
+
}
|
|
78
|
+
}exports.SubscriptionManager=SubscriptionManager;//# sourceMappingURL=SubscriptionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionManager.js","sources":["../../../../src/core/message-bus/core/SubscriptionManager.ts"],"sourcesContent":["import { ILogger } from '@/infrastructure/logger';\n\n/**\n * SubscriptionManager - Manages message subscriptions\n * SubscriptionManager - 管理消息订阅\n */\nexport class SubscriptionManager {\n // Key subscriptions map: key -> Set<windowId>\n // 键值订阅映射:key -> Set<windowId>\n private subscriptions: Map<string, Set<string>> = new Map();\n private logger?: ILogger;\n private readonly MAX_SUBSCRIPTIONS_PER_KEY = 100;\n\n constructor(logger?: ILogger) {\n this.logger = logger;\n }\n\n /**\n * Subscribe to keys\n * 订阅键\n */\n subscribe(windowId: string, keys: string[]): void {\n keys.forEach((key) => {\n if (!this.subscriptions.has(key)) {\n this.subscriptions.set(key, new Set());\n }\n const subscribers = this.subscriptions.get(key)!;\n subscribers.add(windowId);\n\n // Check for potential memory leak / high usage\n if (this.logger && subscribers.size > this.MAX_SUBSCRIPTIONS_PER_KEY) {\n // Debounce warning or just warn? For now just warn.\n // Avoid flooding logs? Maybe only warn on exact multiples or just > 100\n if (subscribers.size === this.MAX_SUBSCRIPTIONS_PER_KEY + 1) {\n this.logger.warn(\n `High number of subscriptions (${subscribers.size}) for key: \"${key}\". Potential memory leak or design issue.`\n );\n }\n }\n });\n }\n\n /**\n * Unsubscribe from keys\n * 取消订阅键\n */\n unsubscribe(windowId: string, keys: string[]): void {\n keys.forEach((key) => {\n const subscribers = this.subscriptions.get(key);\n if (subscribers) {\n subscribers.delete(windowId);\n if (subscribers.size === 0) {\n this.subscriptions.delete(key);\n }\n }\n });\n }\n\n /**\n * Remove all subscriptions for a window\n * 移除窗口的所有订阅\n */\n removeWindow(windowId: string): void {\n this.subscriptions.forEach((subscribers, key) => {\n if (subscribers.has(windowId)) {\n subscribers.delete(windowId);\n if (subscribers.size === 0) {\n this.subscriptions.delete(key);\n }\n }\n });\n }\n\n /**\n * Get subscribers for a key\n * 获取键的订阅者\n */\n getSubscribers(key: string): Set<string> | undefined {\n return this.subscriptions.get(key);\n }\n\n /**\n * Clear all subscriptions\n * 清除所有订阅\n */\n clear(): void {\n this.subscriptions.clear();\n }\n}\n"],"names":[],"mappings":"aAEA;;;AAGG;MACU,mBAAmB,CAAA;;;AAGtB,IAAA,aAAa,GAA6B,IAAI,GAAG,EAAE;AACnD,IAAA,MAAM;IACG,yBAAyB,GAAG,GAAG;AAEhD,IAAA,WAAA,CAAY,MAAgB,EAAA;AAC1B,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;IACtB;AAEA;;;AAGG;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O,CAAC,CAAC,WAAW,EAAE,GAAG,KAAI;AAC9C,YAAA,IAAI,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;AAC7B,gBAAA,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;AAC5B,gBAAA,IAAI,WAAW,CAAC,IAAI,KAAK,CAAC,EAAE;AAC1B,oBAAA,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC;gBAChC;YACF;AACF,QAAA,CAAC,CAAC;IACJ;AAEA;;;AAGG;AACH,IAAA,cAAc,CAAC,GAAW,EAAA;QACxB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC;IACpC;AAEA;;;AAGG;IACH,KAAK,GAAA;AACH,QAAA,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE;IAC5B;AACD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SubscriptionManager - Manages message subscriptions
|
|
3
|
+
* SubscriptionManager - 管理消息订阅
|
|
4
|
+
*/
|
|
5
|
+
class SubscriptionManager {
|
|
6
|
+
// Key subscriptions map: key -> Set<windowId>
|
|
7
|
+
// 键值订阅映射:key -> Set<windowId>
|
|
8
|
+
subscriptions = new Map();
|
|
9
|
+
logger;
|
|
10
|
+
MAX_SUBSCRIPTIONS_PER_KEY = 100;
|
|
11
|
+
constructor(logger) {
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Subscribe to keys
|
|
16
|
+
* 订阅键
|
|
17
|
+
*/
|
|
18
|
+
subscribe(windowId, keys) {
|
|
19
|
+
keys.forEach((key) => {
|
|
20
|
+
if (!this.subscriptions.has(key)) {
|
|
21
|
+
this.subscriptions.set(key, new Set());
|
|
22
|
+
}
|
|
23
|
+
const subscribers = this.subscriptions.get(key);
|
|
24
|
+
subscribers.add(windowId);
|
|
25
|
+
// Check for potential memory leak / high usage
|
|
26
|
+
if (this.logger && subscribers.size > this.MAX_SUBSCRIPTIONS_PER_KEY) {
|
|
27
|
+
// Debounce warning or just warn? For now just warn.
|
|
28
|
+
// Avoid flooding logs? Maybe only warn on exact multiples or just > 100
|
|
29
|
+
if (subscribers.size === this.MAX_SUBSCRIPTIONS_PER_KEY + 1) {
|
|
30
|
+
this.logger.warn(`High number of subscriptions (${subscribers.size}) for key: "${key}". Potential memory leak or design issue.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Unsubscribe from keys
|
|
37
|
+
* 取消订阅键
|
|
38
|
+
*/
|
|
39
|
+
unsubscribe(windowId, keys) {
|
|
40
|
+
keys.forEach((key) => {
|
|
41
|
+
const subscribers = this.subscriptions.get(key);
|
|
42
|
+
if (subscribers) {
|
|
43
|
+
subscribers.delete(windowId);
|
|
44
|
+
if (subscribers.size === 0) {
|
|
45
|
+
this.subscriptions.delete(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Remove all subscriptions for a window
|
|
52
|
+
* 移除窗口的所有订阅
|
|
53
|
+
*/
|
|
54
|
+
removeWindow(windowId) {
|
|
55
|
+
this.subscriptions.forEach((subscribers, key) => {
|
|
56
|
+
if (subscribers.has(windowId)) {
|
|
57
|
+
subscribers.delete(windowId);
|
|
58
|
+
if (subscribers.size === 0) {
|
|
59
|
+
this.subscriptions.delete(key);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get subscribers for a key
|
|
66
|
+
* 获取键的订阅者
|
|
67
|
+
*/
|
|
68
|
+
getSubscribers(key) {
|
|
69
|
+
return this.subscriptions.get(key);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Clear all subscriptions
|
|
73
|
+
* 清除所有订阅
|
|
74
|
+
*/
|
|
75
|
+
clear() {
|
|
76
|
+
this.subscriptions.clear();
|
|
77
|
+
}
|
|
78
|
+
}export{SubscriptionManager};//# sourceMappingURL=SubscriptionManager.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionManager.mjs","sources":["../../../../src/core/message-bus/core/SubscriptionManager.ts"],"sourcesContent":["import { ILogger } from '@/infrastructure/logger';\n\n/**\n * SubscriptionManager - Manages message subscriptions\n * SubscriptionManager - 管理消息订阅\n */\nexport class SubscriptionManager {\n // Key subscriptions map: key -> Set<windowId>\n // 键值订阅映射:key -> Set<windowId>\n private subscriptions: Map<string, Set<string>> = new Map();\n private logger?: ILogger;\n private readonly MAX_SUBSCRIPTIONS_PER_KEY = 100;\n\n constructor(logger?: ILogger) {\n this.logger = logger;\n }\n\n /**\n * Subscribe to keys\n * 订阅键\n */\n subscribe(windowId: string, keys: string[]): void {\n keys.forEach((key) => {\n if (!this.subscriptions.has(key)) {\n this.subscriptions.set(key, new Set());\n }\n const subscribers = this.subscriptions.get(key)!;\n subscribers.add(windowId);\n\n // Check for potential memory leak / high usage\n if (this.logger && subscribers.size > this.MAX_SUBSCRIPTIONS_PER_KEY) {\n // Debounce warning or just warn? For now just warn.\n // Avoid flooding logs? Maybe only warn on exact multiples or just > 100\n if (subscribers.size === this.MAX_SUBSCRIPTIONS_PER_KEY + 1) {\n this.logger.warn(\n `High number of subscriptions (${subscribers.size}) for key: \"${key}\". Potential memory leak or design issue.`\n );\n }\n }\n });\n }\n\n /**\n * Unsubscribe from keys\n * 取消订阅键\n */\n unsubscribe(windowId: string, keys: string[]): void {\n keys.forEach((key) => {\n const subscribers = this.subscriptions.get(key);\n if (subscribers) {\n subscribers.delete(windowId);\n if (subscribers.size === 0) {\n this.subscriptions.delete(key);\n }\n }\n });\n }\n\n /**\n * Remove all subscriptions for a window\n * 移除窗口的所有订阅\n */\n removeWindow(windowId: string): void {\n this.subscriptions.forEach((subscribers, key) => {\n if (subscribers.has(windowId)) {\n subscribers.delete(windowId);\n if (subscribers.size === 0) {\n this.subscriptions.delete(key);\n }\n }\n });\n }\n\n /**\n * Get subscribers for a key\n * 获取键的订阅者\n */\n getSubscribers(key: string): Set<string> | undefined {\n return this.subscriptions.get(key);\n }\n\n /**\n * Clear all subscriptions\n * 清除所有订阅\n */\n clear(): void {\n this.subscriptions.clear();\n }\n}\n"],"names":[],"mappings":"AAEA;;;AAGG;MACU,mBAAmB,CAAA;;;AAGtB,IAAA,aAAa,GAA6B,IAAI,GAAG,EAAE;AACnD,IAAA,MAAM;IACG,yBAAyB,GAAG,GAAG;AAEhD,IAAA,WAAA,CAAY,MAAgB,EAAA;AAC1B,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;IACtB;AAEA;;;AAGG;IACH,SAAS,CAAC,QAAgB,EAAE,IAAc,EAAA;AACxC,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;YACnB,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAChC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,EAAE,CAAC;YACxC;YACA,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAE;AAChD,YAAA,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC;;AAGzB,YAAA,IAAI,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC,yBAAyB,EAAE;;;gBAGpE,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,CAAC,yBAAyB,GAAG,CAAC,EAAE;AAC3D,oBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,CAAA,8BAAA,EAAiC,WAAW,CAAC,IAAI,CAAA,YAAA,EAAe,GAAG,CAAA,yCAAA,CAA2C,CAC/G;gBACH;YACF;AACF,QAAA,CAAC,CAAC;IACJ;AAEA;;;AAGG;IACH,WAAW,CAAC,QAAgB,EAAE,IAAc,EAAA;AAC1C,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;YACnB,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC;YAC/C,IAAI,WAAW,EAAE;AACf,gBAAA,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;AAC5B,gBAAA,IAAI,WAAW,CAAC,IAAI,KAAK,CAAC,EAAE;AAC1B,oBAAA,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC;gBAChC;YACF;AACF,QAAA,CAAC,CAAC;IACJ;AAEA;;;AAGG;AACH,IAAA,YAAY,CAAC,QAAgB,EAAA;QAC3B,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,GAAG,KAAI;AAC9C,YAAA,IAAI,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;AAC7B,gBAAA,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;AAC5B,gBAAA,IAAI,WAAW,CAAC,IAAI,KAAK,CAAC,EAAE;AAC1B,oBAAA,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC;gBAChC;YACF;AACF,QAAA,CAAC,CAAC;IACJ;AAEA;;;AAGG;AACH,IAAA,cAAc,CAAC,GAAW,EAAA;QACxB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC;IACpC;AAEA;;;AAGG;IACH,KAAK,GAAA;AACH,QAAA,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE;IAC5B;AACD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ILogger } from '@/infrastructure/logger';
|
|
2
|
+
export interface TransactionOperation {
|
|
3
|
+
type: 'set' | 'delete';
|
|
4
|
+
value?: any;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* TransactionManager - Manages data transactions for windows
|
|
8
|
+
* TransactionManager - 管理窗口的数据事务
|
|
9
|
+
*/
|
|
10
|
+
export declare class TransactionManager {
|
|
11
|
+
private buffers;
|
|
12
|
+
private logger;
|
|
13
|
+
constructor(logger: ILogger);
|
|
14
|
+
/**
|
|
15
|
+
* Start a transaction
|
|
16
|
+
* 开启事务
|
|
17
|
+
*/
|
|
18
|
+
start(windowId: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Commit a transaction
|
|
21
|
+
* 提交事务
|
|
22
|
+
* @returns The buffered operations to apply, or undefined if no transaction exists
|
|
23
|
+
*/
|
|
24
|
+
commit(windowId: string): Map<string, TransactionOperation> | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Rollback a transaction
|
|
27
|
+
* 回滚事务
|
|
28
|
+
*/
|
|
29
|
+
rollback(windowId: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Add operation to transaction
|
|
32
|
+
* 添加操作到事务
|
|
33
|
+
* @returns true if operation was buffered, false if no transaction is active
|
|
34
|
+
*/
|
|
35
|
+
add(windowId: string, key: string, op: TransactionOperation): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Check if a transaction is active for a window
|
|
38
|
+
* 检查窗口是否有活跃事务
|
|
39
|
+
*/
|
|
40
|
+
hasTransaction(windowId: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Get value from transaction buffer
|
|
43
|
+
* 从事务缓冲区获取值
|
|
44
|
+
*/
|
|
45
|
+
getBufferedValue(windowId: string, key: string): {
|
|
46
|
+
has: boolean;
|
|
47
|
+
value?: any;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Clear all transactions
|
|
51
|
+
* 清除所有事务
|
|
52
|
+
*/
|
|
53
|
+
clear(): void;
|
|
54
|
+
}
|