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,168 @@
|
|
|
1
|
+
'use strict';var ElectronLogger=require('../../infrastructure/logger/ElectronLogger.js');/**
|
|
2
|
+
* WindowCreator - Universal window creation helper class
|
|
3
|
+
* WindowCreator - 通用窗口创建辅助类
|
|
4
|
+
*
|
|
5
|
+
* Handles window creation, restoration, display, and exception recovery.
|
|
6
|
+
* 用于处理窗口创建、恢复、显示以及异常恢复逻辑。
|
|
7
|
+
*/
|
|
8
|
+
class WindowCreator {
|
|
9
|
+
api;
|
|
10
|
+
data;
|
|
11
|
+
winId;
|
|
12
|
+
creator;
|
|
13
|
+
extraOptions;
|
|
14
|
+
logger;
|
|
15
|
+
/**
|
|
16
|
+
* Constructor
|
|
17
|
+
* 构造函数
|
|
18
|
+
*
|
|
19
|
+
* @param api - WindowManager API interface (WindowManager API 接口)
|
|
20
|
+
* @param data - Data object passed to the window, including winId (传递给窗口的数据对象,包含 winId)
|
|
21
|
+
* @param creator - Window creation function (窗口创建函数)
|
|
22
|
+
* @param extraOptions - Optional function to generate extra configuration (可选的额外配置生成函数)
|
|
23
|
+
* @param logger - Optional logger instance (可选的日志实例)
|
|
24
|
+
*/
|
|
25
|
+
constructor(api, data, creator, extraOptions, logger) {
|
|
26
|
+
this.api = api;
|
|
27
|
+
this.data = data;
|
|
28
|
+
this.winId = data?.data?.winId || '';
|
|
29
|
+
this.creator = creator;
|
|
30
|
+
this.extraOptions = extraOptions;
|
|
31
|
+
this.logger = logger || new ElectronLogger.ElectronLogger({ appName: 'WindowCreator' });
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Internal method: Create window
|
|
35
|
+
* 内部方法:创建窗口
|
|
36
|
+
*
|
|
37
|
+
* Checks if window exists. If it exists but is destroyed, cleans up and recreates.
|
|
38
|
+
* 检查窗口是否存在。如果存在但已销毁,则清理并重新创建。
|
|
39
|
+
*
|
|
40
|
+
* @returns Object containing window ID and isNew flag (包含窗口 ID 和是否为新创建标志的对象)
|
|
41
|
+
*/
|
|
42
|
+
async createWindow() {
|
|
43
|
+
let isNew = false;
|
|
44
|
+
// Check if window exists
|
|
45
|
+
// 检查窗口是否存在
|
|
46
|
+
if (this.winId && this.api.window.hasById(this.winId)) {
|
|
47
|
+
// If exists but destroyed, clean it up
|
|
48
|
+
// 如果存在但已销毁,进行清理
|
|
49
|
+
if (this.api.window.isDestroyed(this.winId)) {
|
|
50
|
+
this.logger.warn(`Window ${this.winId} is found in store but destroyed. Cleaning up and recreating.`);
|
|
51
|
+
// Clean up using the API which should handle both ID and Name maps if possible
|
|
52
|
+
// 使用 API 清理,应该同时处理 ID 和名称映射
|
|
53
|
+
await this.api.window.removeWindow(this.winId);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Window exists and is valid
|
|
57
|
+
// 窗口存在且有效
|
|
58
|
+
return { winId: this.winId, isNew: false };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Create new window instance
|
|
62
|
+
// 创建新窗口实例
|
|
63
|
+
const options = this.winId
|
|
64
|
+
? {
|
|
65
|
+
windowId: this.winId,
|
|
66
|
+
...(this.extraOptions?.(this.data.data) || {}),
|
|
67
|
+
}
|
|
68
|
+
: this.data.data;
|
|
69
|
+
this.winId = await this.creator(options);
|
|
70
|
+
isNew = true;
|
|
71
|
+
return { winId: this.winId, isNew };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Internal method: Show window
|
|
75
|
+
* 内部方法:显示窗口
|
|
76
|
+
*
|
|
77
|
+
* @param winId - Window ID (窗口 ID)
|
|
78
|
+
* @param isNew - Is newly created (是否为新创建)
|
|
79
|
+
*/
|
|
80
|
+
showWindow(winId, isNew) {
|
|
81
|
+
const win = this.api.window.getTargetWindow(winId);
|
|
82
|
+
if (!win || win.isDestroyed()) {
|
|
83
|
+
this.logger.error(`Failed to show window ${winId}: Window not found or destroyed`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (isNew) {
|
|
87
|
+
// For new windows, wait for ready-to-show to prevent flickering
|
|
88
|
+
// 对于新窗口,等待 ready-to-show 事件以防止闪烁
|
|
89
|
+
win.once('ready-to-show', () => {
|
|
90
|
+
this.api.window.show(win, winId);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// For existing windows, show immediately
|
|
95
|
+
// 对于现有窗口,立即显示
|
|
96
|
+
this.api.window.show(win, winId);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Internal method: Load content
|
|
101
|
+
* 内部方法:加载内容
|
|
102
|
+
*/
|
|
103
|
+
async loadContent(winId, options) {
|
|
104
|
+
const win = this.api.window.getTargetWindow(winId);
|
|
105
|
+
if (!win || win.isDestroyed())
|
|
106
|
+
return;
|
|
107
|
+
// Handle custom load handler
|
|
108
|
+
// 处理自定义加载处理程序
|
|
109
|
+
if (options.loadWindowContent) {
|
|
110
|
+
try {
|
|
111
|
+
await options.loadWindowContent(win);
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
this.logger.error(`Custom loadWindowContent failed for window ${winId}: ${e}`);
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (this.data.contentLoader) {
|
|
119
|
+
try {
|
|
120
|
+
await this.data.contentLoader(win, options);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
this.logger.error(`Global contentLoader failed for window ${winId}: ${e}`);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (options.loadUrl) {
|
|
128
|
+
win.loadURL(options.loadUrl).catch((e) => {
|
|
129
|
+
this.logger.error(`Failed to load URL "${options.loadUrl}" for window ${winId}: ${e}`);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else if (options.loadFile) {
|
|
133
|
+
win.loadFile(options.loadFile).catch((e) => {
|
|
134
|
+
this.logger.error(`Failed to load file "${options.loadFile}" for window ${winId}: ${e}`);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Create and show window
|
|
140
|
+
* 创建并显示窗口
|
|
141
|
+
*
|
|
142
|
+
* If window exists, restores and focuses it. If not, creates it.
|
|
143
|
+
* 如果窗口已存在则恢复并聚焦,如果不存在则创建。
|
|
144
|
+
*
|
|
145
|
+
* @returns Window ID (窗口 ID)
|
|
146
|
+
*/
|
|
147
|
+
async createAndShow() {
|
|
148
|
+
try {
|
|
149
|
+
const { isNew } = await this.createWindow();
|
|
150
|
+
// Load content if it's a new window
|
|
151
|
+
if (isNew) {
|
|
152
|
+
const options = this.winId
|
|
153
|
+
? {
|
|
154
|
+
windowId: this.winId,
|
|
155
|
+
...(this.extraOptions?.(this.data.data) || {}),
|
|
156
|
+
}
|
|
157
|
+
: this.data.data;
|
|
158
|
+
await this.loadContent(this.winId, options);
|
|
159
|
+
}
|
|
160
|
+
this.showWindow(this.winId, isNew);
|
|
161
|
+
return this.winId;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
this.logger.error(`Failed to create and show window: ${error}`);
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}module.exports=WindowCreator;//# sourceMappingURL=WindowCreator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WindowCreator.js","sources":["../../../src/core/window/WindowCreator.ts"],"sourcesContent":["import { Logger, ILogger } from '@/infrastructure/logger';\nimport type { WindowManagerApi, WindowCreationOptions } from './window-manager.type';\n\n/**\n * WindowCreator - Universal window creation helper class\n * WindowCreator - 通用窗口创建辅助类\n *\n * Handles window creation, restoration, display, and exception recovery.\n * 用于处理窗口创建、恢复、显示以及异常恢复逻辑。\n */\nexport default class WindowCreator<T = WindowCreationOptions> {\n private api: WindowManagerApi;\n private data: {\n data: T & { winId?: string };\n contentLoader?: (window: any, options: any) => Promise<void> | void;\n };\n private winId: string;\n private creator: (options: WindowCreationOptions) => string | Promise<string>;\n private extraOptions?: (data: T) => object;\n private logger: ILogger;\n\n /**\n * Constructor\n * 构造函数\n *\n * @param api - WindowManager API interface (WindowManager API 接口)\n * @param data - Data object passed to the window, including winId (传递给窗口的数据对象,包含 winId)\n * @param creator - Window creation function (窗口创建函数)\n * @param extraOptions - Optional function to generate extra configuration (可选的额外配置生成函数)\n * @param logger - Optional logger instance (可选的日志实例)\n */\n constructor(\n api: WindowManagerApi,\n data: {\n data: T & { winId?: string };\n contentLoader?: (window: any, options: any) => Promise<void> | void;\n },\n creator: (options: WindowCreationOptions) => string | Promise<string>,\n extraOptions?: (data: T) => object,\n logger?: ILogger\n ) {\n this.api = api;\n this.data = data;\n this.winId = data?.data?.winId || '';\n this.creator = creator;\n this.extraOptions = extraOptions;\n this.logger = logger || new Logger({ appName: 'WindowCreator' });\n }\n\n /**\n * Internal method: Create window\n * 内部方法:创建窗口\n *\n * Checks if window exists. If it exists but is destroyed, cleans up and recreates.\n * 检查窗口是否存在。如果存在但已销毁,则清理并重新创建。\n *\n * @returns Object containing window ID and isNew flag (包含窗口 ID 和是否为新创建标志的对象)\n */\n private async createWindow(): Promise<{ winId: string; isNew: boolean }> {\n let isNew = false;\n\n // Check if window exists\n // 检查窗口是否存在\n if (this.winId && this.api.window.hasById(this.winId)) {\n // If exists but destroyed, clean it up\n // 如果存在但已销毁,进行清理\n if (this.api.window.isDestroyed(this.winId)) {\n this.logger.warn(\n `Window ${this.winId} is found in store but destroyed. Cleaning up and recreating.`\n );\n // Clean up using the API which should handle both ID and Name maps if possible\n // 使用 API 清理,应该同时处理 ID 和名称映射\n await this.api.window.removeWindow(this.winId);\n } else {\n // Window exists and is valid\n // 窗口存在且有效\n return { winId: this.winId, isNew: false };\n }\n }\n\n // Create new window instance\n // 创建新窗口实例\n const options = this.winId\n ? {\n windowId: this.winId,\n ...(this.extraOptions?.(this.data.data) || {}),\n }\n : this.data.data;\n\n this.winId = await this.creator(options);\n isNew = true;\n\n return { winId: this.winId, isNew };\n }\n\n /**\n * Internal method: Show window\n * 内部方法:显示窗口\n *\n * @param winId - Window ID (窗口 ID)\n * @param isNew - Is newly created (是否为新创建)\n */\n private showWindow(winId: string, isNew: boolean): void {\n const win = this.api.window.getTargetWindow(winId);\n\n if (!win || win.isDestroyed()) {\n this.logger.error(`Failed to show window ${winId}: Window not found or destroyed`);\n return;\n }\n\n if (isNew) {\n // For new windows, wait for ready-to-show to prevent flickering\n // 对于新窗口,等待 ready-to-show 事件以防止闪烁\n win.once('ready-to-show', () => {\n this.api.window.show(win, winId);\n });\n } else {\n // For existing windows, show immediately\n // 对于现有窗口,立即显示\n this.api.window.show(win, winId);\n }\n }\n\n /**\n * Internal method: Load content\n * 内部方法:加载内容\n */\n private async loadContent(winId: string, options: WindowCreationOptions): Promise<void> {\n const win = this.api.window.getTargetWindow(winId);\n if (!win || win.isDestroyed()) return;\n\n // Handle custom load handler\n // 处理自定义加载处理程序\n if (options.loadWindowContent) {\n try {\n await options.loadWindowContent(win);\n } catch (e) {\n this.logger.error(`Custom loadWindowContent failed for window ${winId}: ${e}`);\n }\n return;\n }\n\n if (this.data.contentLoader) {\n try {\n await this.data.contentLoader(win, options);\n } catch (e) {\n this.logger.error(`Global contentLoader failed for window ${winId}: ${e}`);\n }\n return;\n }\n\n if (options.loadUrl) {\n win.loadURL(options.loadUrl).catch((e) => {\n this.logger.error(`Failed to load URL \"${options.loadUrl}\" for window ${winId}: ${e}`);\n });\n } else if (options.loadFile) {\n win.loadFile(options.loadFile).catch((e) => {\n this.logger.error(`Failed to load file \"${options.loadFile}\" for window ${winId}: ${e}`);\n });\n }\n }\n\n /**\n * Create and show window\n * 创建并显示窗口\n *\n * If window exists, restores and focuses it. If not, creates it.\n * 如果窗口已存在则恢复并聚焦,如果不存在则创建。\n *\n * @returns Window ID (窗口 ID)\n */\n public async createAndShow(): Promise<string> {\n try {\n const { isNew } = await this.createWindow();\n\n // Load content if it's a new window\n if (isNew) {\n const options = this.winId\n ? {\n windowId: this.winId,\n ...(this.extraOptions?.(this.data.data) || {}),\n }\n : this.data.data;\n await this.loadContent(this.winId, options);\n }\n\n this.showWindow(this.winId, isNew);\n return this.winId;\n } catch (error) {\n this.logger.error(`Failed to create and show window: ${error}`);\n throw error;\n }\n }\n}\n"],"names":["Logger"],"mappings":"yFAGA;;;;;;AAMG;AACW,MAAO,aAAa,CAAA;AACxB,IAAA,GAAG;AACH,IAAA,IAAI;AAIJ,IAAA,KAAK;AACL,IAAA,OAAO;AACP,IAAA,YAAY;AACZ,IAAA,MAAM;AAEd;;;;;;;;;AASG;IACH,WAAA,CACE,GAAqB,EACrB,IAGC,EACD,OAAqE,EACrE,YAAkC,EAClC,MAAgB,EAAA;AAEhB,QAAA,IAAI,CAAC,GAAG,GAAG,GAAG;AACd,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE;AACpC,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;AACtB,QAAA,IAAI,CAAC,YAAY,GAAG,YAAY;AAChC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAIA,6BAAM,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;IAClE;AAEA;;;;;;;;AAQG;AACK,IAAA,MAAM,YAAY,GAAA;QACxB,IAAI,KAAK,GAAG,KAAK;;;AAIjB,QAAA,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;;;AAGrD,YAAA,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;gBAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,CAAA,OAAA,EAAU,IAAI,CAAC,KAAK,CAAA,6DAAA,CAA+D,CACpF;;;AAGD,gBAAA,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC;YAChD;iBAAO;;;gBAGL,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AAK,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAC;AAC1F,YAAA,CAAC,CAAC;QACJ;IACF;AAEA;;;;;;;;AAQG;AACI,IAAA,MAAM,aAAa,GAAA;AACxB,QAAA,IAAI;YACF,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE;;YAG3C,IAAI,KAAK,EAAE;AACT,gBAAA,MAAM,OAAO,GAAG,IAAI,CAAC;AACnB,sBAAE;wBACE,QAAQ,EAAE,IAAI,CAAC,KAAK;AACpB,wBAAA,IAAI,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;AAC/C;AACH,sBAAE,IAAI,CAAC,IAAI,CAAC,IAAI;gBAClB,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC;YAC7C;YAEA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC;YAClC,OAAO,IAAI,CAAC,KAAK;QACnB;QAAE,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA,kCAAA,EAAqC,KAAK,CAAA,CAAE,CAAC;AAC/D,YAAA,MAAM,KAAK;QACb;IACF;AACD"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {ElectronLogger}from'../../infrastructure/logger/ElectronLogger.mjs';/**
|
|
2
|
+
* WindowCreator - Universal window creation helper class
|
|
3
|
+
* WindowCreator - 通用窗口创建辅助类
|
|
4
|
+
*
|
|
5
|
+
* Handles window creation, restoration, display, and exception recovery.
|
|
6
|
+
* 用于处理窗口创建、恢复、显示以及异常恢复逻辑。
|
|
7
|
+
*/
|
|
8
|
+
class WindowCreator {
|
|
9
|
+
api;
|
|
10
|
+
data;
|
|
11
|
+
winId;
|
|
12
|
+
creator;
|
|
13
|
+
extraOptions;
|
|
14
|
+
logger;
|
|
15
|
+
/**
|
|
16
|
+
* Constructor
|
|
17
|
+
* 构造函数
|
|
18
|
+
*
|
|
19
|
+
* @param api - WindowManager API interface (WindowManager API 接口)
|
|
20
|
+
* @param data - Data object passed to the window, including winId (传递给窗口的数据对象,包含 winId)
|
|
21
|
+
* @param creator - Window creation function (窗口创建函数)
|
|
22
|
+
* @param extraOptions - Optional function to generate extra configuration (可选的额外配置生成函数)
|
|
23
|
+
* @param logger - Optional logger instance (可选的日志实例)
|
|
24
|
+
*/
|
|
25
|
+
constructor(api, data, creator, extraOptions, logger) {
|
|
26
|
+
this.api = api;
|
|
27
|
+
this.data = data;
|
|
28
|
+
this.winId = data?.data?.winId || '';
|
|
29
|
+
this.creator = creator;
|
|
30
|
+
this.extraOptions = extraOptions;
|
|
31
|
+
this.logger = logger || new ElectronLogger({ appName: 'WindowCreator' });
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Internal method: Create window
|
|
35
|
+
* 内部方法:创建窗口
|
|
36
|
+
*
|
|
37
|
+
* Checks if window exists. If it exists but is destroyed, cleans up and recreates.
|
|
38
|
+
* 检查窗口是否存在。如果存在但已销毁,则清理并重新创建。
|
|
39
|
+
*
|
|
40
|
+
* @returns Object containing window ID and isNew flag (包含窗口 ID 和是否为新创建标志的对象)
|
|
41
|
+
*/
|
|
42
|
+
async createWindow() {
|
|
43
|
+
let isNew = false;
|
|
44
|
+
// Check if window exists
|
|
45
|
+
// 检查窗口是否存在
|
|
46
|
+
if (this.winId && this.api.window.hasById(this.winId)) {
|
|
47
|
+
// If exists but destroyed, clean it up
|
|
48
|
+
// 如果存在但已销毁,进行清理
|
|
49
|
+
if (this.api.window.isDestroyed(this.winId)) {
|
|
50
|
+
this.logger.warn(`Window ${this.winId} is found in store but destroyed. Cleaning up and recreating.`);
|
|
51
|
+
// Clean up using the API which should handle both ID and Name maps if possible
|
|
52
|
+
// 使用 API 清理,应该同时处理 ID 和名称映射
|
|
53
|
+
await this.api.window.removeWindow(this.winId);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Window exists and is valid
|
|
57
|
+
// 窗口存在且有效
|
|
58
|
+
return { winId: this.winId, isNew: false };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Create new window instance
|
|
62
|
+
// 创建新窗口实例
|
|
63
|
+
const options = this.winId
|
|
64
|
+
? {
|
|
65
|
+
windowId: this.winId,
|
|
66
|
+
...(this.extraOptions?.(this.data.data) || {}),
|
|
67
|
+
}
|
|
68
|
+
: this.data.data;
|
|
69
|
+
this.winId = await this.creator(options);
|
|
70
|
+
isNew = true;
|
|
71
|
+
return { winId: this.winId, isNew };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Internal method: Show window
|
|
75
|
+
* 内部方法:显示窗口
|
|
76
|
+
*
|
|
77
|
+
* @param winId - Window ID (窗口 ID)
|
|
78
|
+
* @param isNew - Is newly created (是否为新创建)
|
|
79
|
+
*/
|
|
80
|
+
showWindow(winId, isNew) {
|
|
81
|
+
const win = this.api.window.getTargetWindow(winId);
|
|
82
|
+
if (!win || win.isDestroyed()) {
|
|
83
|
+
this.logger.error(`Failed to show window ${winId}: Window not found or destroyed`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (isNew) {
|
|
87
|
+
// For new windows, wait for ready-to-show to prevent flickering
|
|
88
|
+
// 对于新窗口,等待 ready-to-show 事件以防止闪烁
|
|
89
|
+
win.once('ready-to-show', () => {
|
|
90
|
+
this.api.window.show(win, winId);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// For existing windows, show immediately
|
|
95
|
+
// 对于现有窗口,立即显示
|
|
96
|
+
this.api.window.show(win, winId);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Internal method: Load content
|
|
101
|
+
* 内部方法:加载内容
|
|
102
|
+
*/
|
|
103
|
+
async loadContent(winId, options) {
|
|
104
|
+
const win = this.api.window.getTargetWindow(winId);
|
|
105
|
+
if (!win || win.isDestroyed())
|
|
106
|
+
return;
|
|
107
|
+
// Handle custom load handler
|
|
108
|
+
// 处理自定义加载处理程序
|
|
109
|
+
if (options.loadWindowContent) {
|
|
110
|
+
try {
|
|
111
|
+
await options.loadWindowContent(win);
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
this.logger.error(`Custom loadWindowContent failed for window ${winId}: ${e}`);
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (this.data.contentLoader) {
|
|
119
|
+
try {
|
|
120
|
+
await this.data.contentLoader(win, options);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
this.logger.error(`Global contentLoader failed for window ${winId}: ${e}`);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (options.loadUrl) {
|
|
128
|
+
win.loadURL(options.loadUrl).catch((e) => {
|
|
129
|
+
this.logger.error(`Failed to load URL "${options.loadUrl}" for window ${winId}: ${e}`);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else if (options.loadFile) {
|
|
133
|
+
win.loadFile(options.loadFile).catch((e) => {
|
|
134
|
+
this.logger.error(`Failed to load file "${options.loadFile}" for window ${winId}: ${e}`);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Create and show window
|
|
140
|
+
* 创建并显示窗口
|
|
141
|
+
*
|
|
142
|
+
* If window exists, restores and focuses it. If not, creates it.
|
|
143
|
+
* 如果窗口已存在则恢复并聚焦,如果不存在则创建。
|
|
144
|
+
*
|
|
145
|
+
* @returns Window ID (窗口 ID)
|
|
146
|
+
*/
|
|
147
|
+
async createAndShow() {
|
|
148
|
+
try {
|
|
149
|
+
const { isNew } = await this.createWindow();
|
|
150
|
+
// Load content if it's a new window
|
|
151
|
+
if (isNew) {
|
|
152
|
+
const options = this.winId
|
|
153
|
+
? {
|
|
154
|
+
windowId: this.winId,
|
|
155
|
+
...(this.extraOptions?.(this.data.data) || {}),
|
|
156
|
+
}
|
|
157
|
+
: this.data.data;
|
|
158
|
+
await this.loadContent(this.winId, options);
|
|
159
|
+
}
|
|
160
|
+
this.showWindow(this.winId, isNew);
|
|
161
|
+
return this.winId;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
this.logger.error(`Failed to create and show window: ${error}`);
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}export{WindowCreator as default};//# sourceMappingURL=WindowCreator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WindowCreator.mjs","sources":["../../../src/core/window/WindowCreator.ts"],"sourcesContent":["import { Logger, ILogger } from '@/infrastructure/logger';\nimport type { WindowManagerApi, WindowCreationOptions } from './window-manager.type';\n\n/**\n * WindowCreator - Universal window creation helper class\n * WindowCreator - 通用窗口创建辅助类\n *\n * Handles window creation, restoration, display, and exception recovery.\n * 用于处理窗口创建、恢复、显示以及异常恢复逻辑。\n */\nexport default class WindowCreator<T = WindowCreationOptions> {\n private api: WindowManagerApi;\n private data: {\n data: T & { winId?: string };\n contentLoader?: (window: any, options: any) => Promise<void> | void;\n };\n private winId: string;\n private creator: (options: WindowCreationOptions) => string | Promise<string>;\n private extraOptions?: (data: T) => object;\n private logger: ILogger;\n\n /**\n * Constructor\n * 构造函数\n *\n * @param api - WindowManager API interface (WindowManager API 接口)\n * @param data - Data object passed to the window, including winId (传递给窗口的数据对象,包含 winId)\n * @param creator - Window creation function (窗口创建函数)\n * @param extraOptions - Optional function to generate extra configuration (可选的额外配置生成函数)\n * @param logger - Optional logger instance (可选的日志实例)\n */\n constructor(\n api: WindowManagerApi,\n data: {\n data: T & { winId?: string };\n contentLoader?: (window: any, options: any) => Promise<void> | void;\n },\n creator: (options: WindowCreationOptions) => string | Promise<string>,\n extraOptions?: (data: T) => object,\n logger?: ILogger\n ) {\n this.api = api;\n this.data = data;\n this.winId = data?.data?.winId || '';\n this.creator = creator;\n this.extraOptions = extraOptions;\n this.logger = logger || new Logger({ appName: 'WindowCreator' });\n }\n\n /**\n * Internal method: Create window\n * 内部方法:创建窗口\n *\n * Checks if window exists. If it exists but is destroyed, cleans up and recreates.\n * 检查窗口是否存在。如果存在但已销毁,则清理并重新创建。\n *\n * @returns Object containing window ID and isNew flag (包含窗口 ID 和是否为新创建标志的对象)\n */\n private async createWindow(): Promise<{ winId: string; isNew: boolean }> {\n let isNew = false;\n\n // Check if window exists\n // 检查窗口是否存在\n if (this.winId && this.api.window.hasById(this.winId)) {\n // If exists but destroyed, clean it up\n // 如果存在但已销毁,进行清理\n if (this.api.window.isDestroyed(this.winId)) {\n this.logger.warn(\n `Window ${this.winId} is found in store but destroyed. Cleaning up and recreating.`\n );\n // Clean up using the API which should handle both ID and Name maps if possible\n // 使用 API 清理,应该同时处理 ID 和名称映射\n await this.api.window.removeWindow(this.winId);\n } else {\n // Window exists and is valid\n // 窗口存在且有效\n return { winId: this.winId, isNew: false };\n }\n }\n\n // Create new window instance\n // 创建新窗口实例\n const options = this.winId\n ? {\n windowId: this.winId,\n ...(this.extraOptions?.(this.data.data) || {}),\n }\n : this.data.data;\n\n this.winId = await this.creator(options);\n isNew = true;\n\n return { winId: this.winId, isNew };\n }\n\n /**\n * Internal method: Show window\n * 内部方法:显示窗口\n *\n * @param winId - Window ID (窗口 ID)\n * @param isNew - Is newly created (是否为新创建)\n */\n private showWindow(winId: string, isNew: boolean): void {\n const win = this.api.window.getTargetWindow(winId);\n\n if (!win || win.isDestroyed()) {\n this.logger.error(`Failed to show window ${winId}: Window not found or destroyed`);\n return;\n }\n\n if (isNew) {\n // For new windows, wait for ready-to-show to prevent flickering\n // 对于新窗口,等待 ready-to-show 事件以防止闪烁\n win.once('ready-to-show', () => {\n this.api.window.show(win, winId);\n });\n } else {\n // For existing windows, show immediately\n // 对于现有窗口,立即显示\n this.api.window.show(win, winId);\n }\n }\n\n /**\n * Internal method: Load content\n * 内部方法:加载内容\n */\n private async loadContent(winId: string, options: WindowCreationOptions): Promise<void> {\n const win = this.api.window.getTargetWindow(winId);\n if (!win || win.isDestroyed()) return;\n\n // Handle custom load handler\n // 处理自定义加载处理程序\n if (options.loadWindowContent) {\n try {\n await options.loadWindowContent(win);\n } catch (e) {\n this.logger.error(`Custom loadWindowContent failed for window ${winId}: ${e}`);\n }\n return;\n }\n\n if (this.data.contentLoader) {\n try {\n await this.data.contentLoader(win, options);\n } catch (e) {\n this.logger.error(`Global contentLoader failed for window ${winId}: ${e}`);\n }\n return;\n }\n\n if (options.loadUrl) {\n win.loadURL(options.loadUrl).catch((e) => {\n this.logger.error(`Failed to load URL \"${options.loadUrl}\" for window ${winId}: ${e}`);\n });\n } else if (options.loadFile) {\n win.loadFile(options.loadFile).catch((e) => {\n this.logger.error(`Failed to load file \"${options.loadFile}\" for window ${winId}: ${e}`);\n });\n }\n }\n\n /**\n * Create and show window\n * 创建并显示窗口\n *\n * If window exists, restores and focuses it. If not, creates it.\n * 如果窗口已存在则恢复并聚焦,如果不存在则创建。\n *\n * @returns Window ID (窗口 ID)\n */\n public async createAndShow(): Promise<string> {\n try {\n const { isNew } = await this.createWindow();\n\n // Load content if it's a new window\n if (isNew) {\n const options = this.winId\n ? {\n windowId: this.winId,\n ...(this.extraOptions?.(this.data.data) || {}),\n }\n : this.data.data;\n await this.loadContent(this.winId, options);\n }\n\n this.showWindow(this.winId, isNew);\n return this.winId;\n } catch (error) {\n this.logger.error(`Failed to create and show window: ${error}`);\n throw error;\n }\n }\n}\n"],"names":["Logger"],"mappings":"4EAGA;;;;;;AAMG;AACW,MAAO,aAAa,CAAA;AACxB,IAAA,GAAG;AACH,IAAA,IAAI;AAIJ,IAAA,KAAK;AACL,IAAA,OAAO;AACP,IAAA,YAAY;AACZ,IAAA,MAAM;AAEd;;;;;;;;;AASG;IACH,WAAA,CACE,GAAqB,EACrB,IAGC,EACD,OAAqE,EACrE,YAAkC,EAClC,MAAgB,EAAA;AAEhB,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C,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;AAC/C;AACH,sBAAE,IAAI,CAAC,IAAI,CAAC,IAAI;gBAClB,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC;YAC7C;YAEA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC;YAClC,OAAO,IAAI,CAAC,KAAK;QACnB;QAAE,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA,kCAAA,EAAqC,KAAK,CAAA,CAAE,CAAC;AAC/D,YAAA,MAAM,KAAK;QACb;IACF;AACD"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { BrowserWindow, BrowserWindowConstructorOptions } from 'electron';
|
|
2
|
+
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
3
|
+
import { ILogger } from '@/infrastructure/logger';
|
|
4
|
+
import WindowStore from './WindowStore';
|
|
5
|
+
import type { WindowManagerConfig, WindowManagerPlugin, WindowCreationOptions, WindowManagerEvents } from './window-manager.type';
|
|
6
|
+
import type IpcRouter from '@/core/ipc/IpcRouter';
|
|
7
|
+
import type { IIpcTransport } from '@/core/ipc/transport/ipc.type';
|
|
8
|
+
import type { MessageBus } from '@/core/message-bus/MessageBus';
|
|
9
|
+
import { IpcSetup } from './IpcSetup';
|
|
10
|
+
import { MetricsManager } from './core/MetricsManager';
|
|
11
|
+
import { PluginExecutor } from './core/PluginExecutor';
|
|
12
|
+
import { WindowLifecycle } from './core/WindowLifecycle';
|
|
13
|
+
/**
|
|
14
|
+
* WindowManager - Core class for managing Electron windows
|
|
15
|
+
* WindowManager - 管理 Electron 窗口的核心类
|
|
16
|
+
*
|
|
17
|
+
* Uses WindowStore via composition to handle window management
|
|
18
|
+
* 使用组合方式通过 WindowStore 处理窗口管理
|
|
19
|
+
*/
|
|
20
|
+
export default class WindowManager extends TypedEmitter<WindowManagerEvents> {
|
|
21
|
+
config: WindowManagerConfig;
|
|
22
|
+
ipcRouter?: IpcRouter;
|
|
23
|
+
ipcTransport?: IIpcTransport;
|
|
24
|
+
messageBus?: MessageBus;
|
|
25
|
+
protected currentIpcChannel: string | null;
|
|
26
|
+
protected currentIpcSyncChannel: string | null;
|
|
27
|
+
logger: ILogger;
|
|
28
|
+
readonly windowStore: WindowStore;
|
|
29
|
+
protected metricsManager: MetricsManager;
|
|
30
|
+
protected pluginExecutor: PluginExecutor;
|
|
31
|
+
protected lifecycle: WindowLifecycle;
|
|
32
|
+
private isInitialized;
|
|
33
|
+
private initPromise;
|
|
34
|
+
private initError;
|
|
35
|
+
/**
|
|
36
|
+
* Constructor
|
|
37
|
+
* 构造函数
|
|
38
|
+
* @param config - WindowManager configuration
|
|
39
|
+
*/
|
|
40
|
+
constructor(config?: WindowManagerConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Returns a promise that resolves when initialization is complete
|
|
43
|
+
* 返回一个 Promise,当初始化完成时 resolve
|
|
44
|
+
* @throws {Error} If initialization failed
|
|
45
|
+
*/
|
|
46
|
+
ready(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Check if WindowManager is initialized
|
|
49
|
+
* 检查 WindowManager 是否已初始化
|
|
50
|
+
*/
|
|
51
|
+
get initialized(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Get initialization error if any
|
|
54
|
+
* 获取初始化错误(如果有)
|
|
55
|
+
*/
|
|
56
|
+
get initializationError(): Error | null;
|
|
57
|
+
/**
|
|
58
|
+
* Initialize plugins
|
|
59
|
+
* 初始化插件
|
|
60
|
+
*/
|
|
61
|
+
private init;
|
|
62
|
+
/**
|
|
63
|
+
* Register a plugin
|
|
64
|
+
* 注册插件
|
|
65
|
+
* @param plugin - Plugin instance
|
|
66
|
+
*/
|
|
67
|
+
use(plugin: WindowManagerPlugin): this;
|
|
68
|
+
/**
|
|
69
|
+
* Setup IPC communication
|
|
70
|
+
* 设置 IPC 通信
|
|
71
|
+
* @param options - Optional IPC configuration (可选的 IPC 配置)
|
|
72
|
+
*/
|
|
73
|
+
setupIPC(options?: {
|
|
74
|
+
channel?: string;
|
|
75
|
+
syncChannel?: string;
|
|
76
|
+
setupImpl?: typeof IpcSetup.setup;
|
|
77
|
+
}): void;
|
|
78
|
+
/**
|
|
79
|
+
* Create a new window
|
|
80
|
+
* 创建一个新窗口
|
|
81
|
+
* @param config - Configuration object (配置对象)
|
|
82
|
+
* @returns Window ID (窗口 ID)
|
|
83
|
+
*/
|
|
84
|
+
create(config?: WindowCreationOptions): Promise<string>;
|
|
85
|
+
/**
|
|
86
|
+
* Remove window
|
|
87
|
+
* 移除窗口
|
|
88
|
+
* @param windowId - Window ID
|
|
89
|
+
*/
|
|
90
|
+
removeWindow(windowId: string): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Get performance metrics
|
|
93
|
+
* 获取性能指标
|
|
94
|
+
* @returns Performance metrics object
|
|
95
|
+
*/
|
|
96
|
+
getMetrics(): import("./core/MetricsManager").WindowManagerMetricsData;
|
|
97
|
+
/**
|
|
98
|
+
* Dispose all resources
|
|
99
|
+
* 释放所有资源
|
|
100
|
+
*/
|
|
101
|
+
dispose(): void;
|
|
102
|
+
private getMainWindowId;
|
|
103
|
+
createBrowserWindow(config?: BrowserWindowConstructorOptions): BrowserWindow;
|
|
104
|
+
protected getDefaultWindowConfig(): BrowserWindowConstructorOptions;
|
|
105
|
+
configureWindowBehavior(window: BrowserWindow, windowId: string): void;
|
|
106
|
+
/**
|
|
107
|
+
* Join a window to a group
|
|
108
|
+
* 将窗口加入组
|
|
109
|
+
*/
|
|
110
|
+
joinGroup(windowId: string, group: string): void;
|
|
111
|
+
/**
|
|
112
|
+
* Leave a window from a group
|
|
113
|
+
* 将窗口移出组
|
|
114
|
+
*/
|
|
115
|
+
leaveGroup(windowId: string, group: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Get all window IDs in a group
|
|
118
|
+
* 获取组内所有窗口 ID
|
|
119
|
+
*/
|
|
120
|
+
getGroup(group: string): string[];
|
|
121
|
+
/**
|
|
122
|
+
* Close all windows in a group
|
|
123
|
+
* 关闭组内所有窗口
|
|
124
|
+
*/
|
|
125
|
+
closeGroup(group: string): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Hide all windows in a group
|
|
128
|
+
* 隐藏组内所有窗口
|
|
129
|
+
*/
|
|
130
|
+
hideGroup(group: string): void;
|
|
131
|
+
/**
|
|
132
|
+
* Show all windows in a group
|
|
133
|
+
* 显示组内所有窗口
|
|
134
|
+
*/
|
|
135
|
+
showGroup(group: string): void;
|
|
136
|
+
/**
|
|
137
|
+
* Focus all windows in a group
|
|
138
|
+
* 聚焦组内所有窗口
|
|
139
|
+
*/
|
|
140
|
+
focusGroup(group: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* Send message to all windows in a group via MessageBus
|
|
143
|
+
* 通过 MessageBus 向组内所有窗口发送消息
|
|
144
|
+
* @param group - Group name (组名)
|
|
145
|
+
* @param channel - Channel name (频道名称)
|
|
146
|
+
* @param data - Message data (消息数据)
|
|
147
|
+
* @returns Number of successful sends (成功发送的数量)
|
|
148
|
+
*/
|
|
149
|
+
sendToGroup(group: string, channel: string, data: any): number;
|
|
150
|
+
/**
|
|
151
|
+
* Focus previous window in history
|
|
152
|
+
* 聚焦历史记录中的上一个窗口
|
|
153
|
+
*/
|
|
154
|
+
focusPrevious(): void;
|
|
155
|
+
validateWindowId(windowId: string | undefined | null, methodName: string): string;
|
|
156
|
+
show(window: BrowserWindow, windowId?: string): void;
|
|
157
|
+
hide(windowId: string): void;
|
|
158
|
+
isDestroyed(windowId: string): boolean;
|
|
159
|
+
isVisible(windowId: string): boolean;
|
|
160
|
+
isMinimized(windowId: string): boolean;
|
|
161
|
+
isMaximized(windowId: string): boolean;
|
|
162
|
+
fullScreenState(windowId: string): boolean;
|
|
163
|
+
minimize(windowId?: string): void;
|
|
164
|
+
restore(windowId: string): void;
|
|
165
|
+
maximize(windowId: string): void;
|
|
166
|
+
unmaximize(windowId: string): void;
|
|
167
|
+
fullScreen(windowId: string): void;
|
|
168
|
+
focus(windowId: string): void;
|
|
169
|
+
setMovable(window: BrowserWindow): void;
|
|
170
|
+
/**
|
|
171
|
+
* Close a window
|
|
172
|
+
* 关闭窗口
|
|
173
|
+
* @param windowId - Window ID (窗口 ID)
|
|
174
|
+
*/
|
|
175
|
+
close(windowId: string): void;
|
|
176
|
+
/**
|
|
177
|
+
* @deprecated Use close() instead
|
|
178
|
+
* @deprecated 使用 close() 代替
|
|
179
|
+
*/
|
|
180
|
+
winClose(windowId: string): void;
|
|
181
|
+
openDevTools(windowId: string): void;
|
|
182
|
+
isDevToolsOpened(windowId: string): boolean;
|
|
183
|
+
closeDevTools(windowId: string): void;
|
|
184
|
+
quit(): void;
|
|
185
|
+
getWindowSize(): {
|
|
186
|
+
width: number;
|
|
187
|
+
height: number;
|
|
188
|
+
};
|
|
189
|
+
send(windowId: string, name: string, data?: unknown): void;
|
|
190
|
+
setSkipTaskbar(windowId: string, bool: boolean): void;
|
|
191
|
+
get mainWindow(): BrowserWindow | null;
|
|
192
|
+
getWindowCount(): number;
|
|
193
|
+
getAllWindowKeys(): string[];
|
|
194
|
+
getAllWindows(): BrowserWindow[];
|
|
195
|
+
getWindowNames(): Map<string, string>;
|
|
196
|
+
getNameByWindowId(windowId: string): string | undefined;
|
|
197
|
+
getWindowByNameId(name: string): string | undefined;
|
|
198
|
+
getWindowByName(name: string): BrowserWindow | undefined;
|
|
199
|
+
hasByName(proposedName: string): boolean;
|
|
200
|
+
deleteByName(proposedName: string): boolean;
|
|
201
|
+
getWindowById(windowId: string): BrowserWindow | undefined;
|
|
202
|
+
hasById(windowId: string): boolean;
|
|
203
|
+
deleteById(windowId: string): boolean;
|
|
204
|
+
getWindowId(window: BrowserWindow): string | undefined;
|
|
205
|
+
updateWindowName(windowId: string, newName: string): void;
|
|
206
|
+
getTargetWindow(windowId?: string): BrowserWindow | undefined;
|
|
207
|
+
getValidWindow(windowId?: string): BrowserWindow | undefined;
|
|
208
|
+
getCurrentWindow(): BrowserWindow | undefined;
|
|
209
|
+
saveWindowContext(windowId: string, context: any): Promise<void>;
|
|
210
|
+
loadWindowContext(windowId: string): Promise<any>;
|
|
211
|
+
clearWindowContext(windowId: string): Promise<void>;
|
|
212
|
+
startCleanupProtection(intervalMs?: number): void;
|
|
213
|
+
stopCleanupProtection(): void;
|
|
214
|
+
}
|