electron-infra-kit 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # Electron Infra Kit
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/electron-infra-kit.svg)](https://www.npmjs.com/package/electron-infra-kit)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![npm downloads](https://img.shields.io/npm/dm/electron-infra-kit.svg)](https://www.npmjs.com/package/electron-infra-kit)
5
+ [![CI](https://github.com/chunhaofen/electron-infra-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/chunhaofen/electron-infra-kit/actions/workflows/ci.yml)
6
+ [![License](https://img.shields.io/npm/l/electron-infra-kit.svg)](https://github.com/chunhaofen/electron-infra-kit.git/blob/main/LICENSE)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
5
8
 
6
- A comprehensive infrastructure kit for Electron applications, featuring a robust window manager with state persistence, inter-window communication, and full TypeScript support.
9
+ English | [简体中文](./README.zh-CN.md)
10
+
11
+ A comprehensive infrastructure kit for Electron applications, providing window management, IPC routing, and state synchronization capabilities.
7
12
 
8
13
  ## ✨ Features
9
14
 
@@ -62,6 +67,7 @@ app.whenReady().then(async () => {
62
67
 
63
68
  - **[Quick Start Guide](./QUICKSTART.md)** - Get up and running in 5 minutes
64
69
  - **[Complete Example](./guides/COOKBOOK.md)** - Full working example with all features
70
+ - **[Migration Guide](./IMPROVEMENTS.md)** - Upgrade from older versions
65
71
 
66
72
  ### Core Concepts
67
73
 
@@ -84,6 +90,54 @@ app.whenReady().then(async () => {
84
90
 
85
91
  ## 💡 Key Concepts
86
92
 
93
+ ### Architecture Design
94
+
95
+ ```mermaid
96
+ %%{init: {'theme':'base','flowchart':{'curve':'basis','nodeSpacing':70,'rankSpacing':120,'diagramPadding':20,'htmlLabels':true}, 'themeVariables': { 'primaryColor':'#667eea','primaryTextColor':'#fff','primaryBorderColor':'#764ba2','lineColor':'#a78bfa','secondaryColor':'#4facfe','tertiaryColor':'#43e97b'}}}%%
97
+ graph LR
98
+ classDef userNode fill:#667eea,stroke:#764ba2,stroke-width:3px,color:#fff,rx:12,ry:12
99
+ classDef entryNode fill:#f093fb,stroke:#f5576c,stroke-width:3px,color:#fff,rx:12,ry:12
100
+ classDef coreNode fill:#4facfe,stroke:#00c2fe,stroke-width:2px,color:#fff,rx:10,ry:10
101
+ classDef internalNode fill:#43e97b,stroke:#38f9d7,stroke-width:2px,color:#fff,rx:10,ry:10
102
+ classDef electronNode fill:#fa709a,stroke:#fee140,stroke-width:2px,color:#fff,rx:10,ry:10
103
+ classDef groupStyle fill:#f8fafc,stroke:#cbd5e1,stroke-width:2px,rx:10,ry:10
104
+
105
+ Dev["👨‍💻 Developer"]:::userNode
106
+ Entry["🛠️ createElectronToolkit"]:::entryNode
107
+
108
+ subgraph Core["🎯 Core Layer"]
109
+ WM["🪟 WindowManager"]:::coreNode
110
+ MB["📨 MessageBus"]:::coreNode
111
+ IR["🔌 IpcRouter"]:::coreNode
112
+ end
113
+
114
+ subgraph Internal["⚙️ Support Layer"]
115
+ WS["💾 WindowStore"]:::internalNode
116
+ PE["🧩 PluginExecutor"]:::internalNode
117
+ end
118
+
119
+ subgraph Electron["🖥️ Runtime Layer"]
120
+ EWin["Electron Windows"]:::electronNode
121
+ EIPC["Electron IPC"]:::electronNode
122
+ end
123
+
124
+ Dev --> Entry
125
+ Entry --> WM
126
+ Entry --> MB
127
+ Entry --> IR
128
+
129
+ WM -.-> WS
130
+ WM -.-> PE
131
+ WM -.-> IR
132
+ MB -.-> WM
133
+
134
+ WM --> EWin
135
+ MB --> EWin
136
+ IR --> EIPC
137
+
138
+ class Core,Internal,Electron groupStyle
139
+ ```
140
+
87
141
  ### Window Manager
88
142
 
89
143
  <details>
package/README.zh-CN.md CHANGED
@@ -1,8 +1,8 @@
1
- # Electron Infra Kit
1
+ # Electron Infra Kit
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/electron-infra-kit.svg)](https://www.npmjs.com/package/electron-infra-kit)
4
4
  [![npm downloads](https://img.shields.io/npm/dm/electron-infra-kit.svg)](https://www.npmjs.com/package/electron-infra-kit)
5
- [![CI](https://github.com/chunhaofen/electron-infra-kit.git/actions/workflows/ci.yml/badge.svg)](https://github.com/chunhaofen/electron-infra-kit.git/actions/workflows/ci.yml)
5
+ [![CI](https://github.com/chunhaofen/electron-infra-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/chunhaofen/electron-infra-kit/actions/workflows/ci.yml)
6
6
  [![License](https://img.shields.io/npm/l/electron-infra-kit.svg)](https://github.com/chunhaofen/electron-infra-kit.git/blob/main/LICENSE)
7
7
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
8
8
 
@@ -90,6 +90,56 @@ app.whenReady().then(async () => {
90
90
 
91
91
  ## 💡 核心概念
92
92
 
93
+
94
+ ### 架构设计
95
+
96
+ ```mermaid
97
+ %%{init: {'theme':'base','flowchart':{'curve':'basis','nodeSpacing':70,'rankSpacing':120,'diagramPadding':20,'htmlLabels':true}, 'themeVariables': { 'primaryColor':'#667eea','primaryTextColor':'#fff','primaryBorderColor':'#764ba2','lineColor':'#a78bfa','secondaryColor':'#4facfe','tertiaryColor':'#43e97b'}}}%%
98
+ graph LR
99
+ classDef userNode fill:#667eea,stroke:#764ba2,stroke-width:3px,color:#fff,rx:12,ry:12
100
+ classDef entryNode fill:#f093fb,stroke:#f5576c,stroke-width:3px,color:#fff,rx:12,ry:12
101
+ classDef coreNode fill:#4facfe,stroke:#00c2fe,stroke-width:2px,color:#fff,rx:10,ry:10
102
+ classDef internalNode fill:#43e97b,stroke:#38f9d7,stroke-width:2px,color:#fff,rx:10,ry:10
103
+ classDef electronNode fill:#fa709a,stroke:#fee140,stroke-width:2px,color:#fff,rx:10,ry:10
104
+ classDef groupStyle fill:#f8fafc,stroke:#cbd5e1,stroke-width:2px,rx:10,ry:10
105
+
106
+ Dev["👨‍💻 开发者"]:::userNode
107
+ Entry["🛠️ createElectronToolkit"]:::entryNode
108
+
109
+ subgraph Core["🎯 核心层"]
110
+ WM["🪟 WindowManager"]:::coreNode
111
+ MB["📨 MessageBus"]:::coreNode
112
+ IR["🔌 IpcRouter"]:::coreNode
113
+ end
114
+
115
+ subgraph Internal["⚙️ 支撑层"]
116
+ WS["💾 WindowStore"]:::internalNode
117
+ PE["🧩 PluginExecutor"]:::internalNode
118
+ end
119
+
120
+ subgraph Electron["🖥️ 运行时层"]
121
+ EWin["Electron Windows"]:::electronNode
122
+ EIPC["Electron IPC"]:::electronNode
123
+ end
124
+
125
+ Dev --> Entry
126
+ Entry --> WM
127
+ Entry --> MB
128
+ Entry --> IR
129
+
130
+ WM -.-> WS
131
+ WM -.-> PE
132
+ WM -.-> IR
133
+ MB -.-> WM
134
+
135
+ WM --> EWin
136
+ MB --> EWin
137
+ IR --> EIPC
138
+
139
+ class Core,Internal,Electron groupStyle
140
+ ```
141
+
142
+
93
143
  ### 窗口管理器
94
144
 
95
145
  <details>
@@ -1,4 +1,4 @@
1
- 'use strict';var WindowManager=require('../window/WindowManager.js'),IpcRouter=require('../ipc/IpcRouter.js'),MessageBus=require('../message-bus/MessageBus.js'),index=require('../../infrastructure/debug/index.js'),ElectronLogger=require('../../infrastructure/logger/ElectronLogger.js');/**
1
+ 'use strict';var index=require('../../infrastructure/logger/index.js'),WindowManager=require('../window/WindowManager.js'),IpcRouter=require('../ipc/IpcRouter.js'),MessageBus=require('../message-bus/MessageBus.js'),index$1=require('../../infrastructure/debug/index.js');/**
2
2
  * Lifecycle Manager
3
3
  * 生命周期管理器
4
4
  *
@@ -19,7 +19,8 @@ class LifecycleManager {
19
19
  */
20
20
  constructor(config = {}) {
21
21
  this.config = config;
22
- this.logger = config.logger || new ElectronLogger.ElectronLogger({ appName: 'LifecycleManager' });
22
+ const logger = config.logger || index.getSharedLogger(config.loggerOptions);
23
+ this.logger = logger;
23
24
  if (config.autoStart) {
24
25
  this.startup().catch((err) => {
25
26
  this.logger.error(`Auto-startup failed: ${err}`);
@@ -39,17 +40,18 @@ class LifecycleManager {
39
40
  this.logger.info('Starting up Electron Toolkit services...');
40
41
  // 1. Initialize IpcRouter (Foundation for communication)
41
42
  // 1. 初始化 IpcRouter (通信基础)
42
- this.ipcRouter = this.config.ipcRouter || new IpcRouter({ logger: this.config.logger });
43
+ this.ipcRouter = this.config.ipcRouter || new IpcRouter({ logger: this.logger });
43
44
  this.logger.info('IpcRouter initialized');
44
45
  // 2. Initialize MessageBus (Cross-window communication)
45
46
  // 2. 初始化 MessageBus (跨窗口通信)
46
- this.messageBus = this.config.messageBus || new MessageBus.MessageBus({ logger: this.config.logger });
47
+ this.messageBus = this.config.messageBus || new MessageBus.MessageBus({ logger: this.logger });
47
48
  // 3. Initialize WindowManager (Core window management)
48
49
  // 3. 初始化 WindowManager (核心窗口管理)
49
50
  this.windowManager =
50
51
  this.config.windowManager ||
51
52
  new WindowManager({
52
53
  ...this.config,
54
+ logger: this.logger,
53
55
  ipcRouter: this.ipcRouter,
54
56
  messageBus: this.messageBus,
55
57
  });
@@ -63,11 +65,11 @@ class LifecycleManager {
63
65
  // 4. Setup Debug Mode if enabled
64
66
  // 4. 如果启用,设置调试模式
65
67
  if (this.config.isDevelopment || process.env.NODE_ENV === 'development') {
66
- index.DebugHelper.enableDebugMode();
67
- index.DebugHelper.register('windowManager', this.windowManager);
68
- index.DebugHelper.register('ipcRouter', this.ipcRouter);
69
- index.DebugHelper.register('messageBus', this.messageBus);
70
- index.DebugHelper.register('lifecycleManager', this);
68
+ index$1.DebugHelper.enableDebugMode();
69
+ index$1.DebugHelper.register('windowManager', this.windowManager);
70
+ index$1.DebugHelper.register('ipcRouter', this.ipcRouter);
71
+ index$1.DebugHelper.register('messageBus', this.messageBus);
72
+ index$1.DebugHelper.register('lifecycleManager', this);
71
73
  this.logger.info('Debug mode enabled');
72
74
  }
73
75
  this.isStarted = true;
@@ -1 +1 @@
1
- {"version":3,"file":"LifecycleManager.js","sources":["../../../src/core/lifecycle/LifecycleManager.ts"],"sourcesContent":["import { Logger, ILogger } from '@/infrastructure/logger';\nimport WindowManager from '@/core/window/WindowManager';\nimport IpcRouter from '@/core/ipc/IpcRouter';\nimport { MessageBus } from '@/core/message-bus/MessageBus';\nimport { WindowManagerConfig } from '@/core/window/window-manager.type';\nimport { DebugHelper } from '@/infrastructure/debug';\n\n/**\n * Lifecycle Configuration\n * 生命周期配置\n */\nexport interface LifecycleConfig extends WindowManagerConfig {\n /**\n * Whether to automatically start on instantiation (default: false)\n * 是否在实例化时自动启动 (默认: false)\n */\n autoStart?: boolean;\n\n /**\n * Existing IpcRouter instance\n * 现有的 IpcRouter 实例\n */\n ipcRouter?: IpcRouter;\n\n /**\n * Existing WindowManager instance\n * 现有的 WindowManager 实例\n */\n windowManager?: WindowManager;\n\n /**\n * Existing MessageBus instance\n * 现有的 MessageBus 实例\n */\n messageBus?: MessageBus;\n}\n\n/**\n * Lifecycle Manager\n * 生命周期管理器\n *\n * Orchestrates the startup and shutdown of the Electron Toolkit modules.\n * 编排 Electron Toolkit 模块的启动和关闭。\n */\nexport class LifecycleManager {\n public windowManager?: WindowManager;\n public ipcRouter?: IpcRouter;\n public messageBus?: MessageBus;\n private logger: ILogger;\n private isStarted = false;\n private config: LifecycleConfig;\n\n /**\n * Create LifecycleManager instance\n * 创建 LifecycleManager 实例\n * @param config - Configuration object\n */\n constructor(config: LifecycleConfig = {}) {\n this.config = config;\n this.logger = config.logger || new Logger({ appName: 'LifecycleManager' });\n\n if (config.autoStart) {\n this.startup().catch((err) => {\n this.logger.error(`Auto-startup failed: ${err}`);\n });\n }\n }\n\n /**\n * Start up all services\n * 启动所有服务\n */\n async startup(): Promise<void> {\n if (this.isStarted) {\n this.logger.warn('LifecycleManager already started');\n return;\n }\n\n try {\n this.logger.info('Starting up Electron Toolkit services...');\n\n // 1. Initialize IpcRouter (Foundation for communication)\n // 1. 初始化 IpcRouter (通信基础)\n this.ipcRouter = this.config.ipcRouter || new IpcRouter({ logger: this.config.logger });\n this.logger.info('IpcRouter initialized');\n\n // 2. Initialize MessageBus (Cross-window communication)\n // 2. 初始化 MessageBus (跨窗口通信)\n this.messageBus = this.config.messageBus || new MessageBus({ logger: this.config.logger });\n\n // 3. Initialize WindowManager (Core window management)\n // 3. 初始化 WindowManager (核心窗口管理)\n this.windowManager =\n this.config.windowManager ||\n new WindowManager({\n ...this.config,\n ipcRouter: this.ipcRouter,\n messageBus: this.messageBus,\n });\n // Wait for WindowManager initialization (plugins, etc.)\n await this.windowManager.ready();\n this.logger.info('WindowManager initialized');\n\n // 4. Connect MessageBus to WindowManager\n // 4. 连接 MessageBus 到 WindowManager\n this.messageBus.autoRegisterWindows(this.windowManager);\n this.logger.info('MessageBus initialized');\n\n // 4. Setup Debug Mode if enabled\n // 4. 如果启用,设置调试模式\n if (this.config.isDevelopment || process.env.NODE_ENV === 'development') {\n DebugHelper.enableDebugMode();\n DebugHelper.register('windowManager', this.windowManager);\n DebugHelper.register('ipcRouter', this.ipcRouter);\n DebugHelper.register('messageBus', this.messageBus);\n DebugHelper.register('lifecycleManager', this);\n this.logger.info('Debug mode enabled');\n }\n\n this.isStarted = true;\n this.logger.info('Startup completed successfully');\n } catch (error) {\n this.logger.error(`Startup failed: ${error}`);\n await this.shutdown(); // Cleanup partial initialization\n throw error;\n }\n }\n\n /**\n * Shut down all services gracefully\n * 优雅地关闭所有服务\n */\n async shutdown(): Promise<void> {\n this.logger.info('Shutting down Electron Toolkit services...');\n\n // Shutdown in reverse order of initialization\n // 按初始化的逆序关闭\n\n // 1. Dispose MessageBus\n if (this.messageBus) {\n try {\n this.messageBus.dispose();\n this.logger.info('MessageBus disposed');\n } catch (e) {\n this.logger.warn(`MessageBus dispose error: ${e}`);\n }\n this.messageBus = undefined;\n }\n\n // 2. Dispose WindowManager (closes all windows)\n if (this.windowManager) {\n try {\n if (typeof this.windowManager.dispose === 'function') {\n await this.windowManager.dispose();\n this.logger.info('WindowManager disposed');\n } else {\n // Fallback if dispose is not implemented\n this.windowManager.stopCleanupProtection();\n // Ideally we should close all windows here, but we rely on WindowManager's dispose\n }\n } catch (e) {\n this.logger.warn(`WindowManager dispose error: ${e}`);\n }\n this.windowManager = undefined;\n }\n\n // 3. Dispose IpcRouter\n if (this.ipcRouter) {\n try {\n this.ipcRouter.dispose();\n this.logger.info('IpcRouter disposed');\n } catch (e) {\n this.logger.warn(`IpcRouter dispose error: ${e}`);\n }\n this.ipcRouter = undefined;\n }\n\n this.isStarted = false;\n this.logger.info('Shutdown completed');\n }\n\n /**\n * Get initialization status\n * 获取初始化状态\n */\n public get started(): boolean {\n return this.isStarted;\n }\n}\n"],"names":["Logger","MessageBus","DebugHelper"],"mappings":"8RAqCA;;;;;;AAMG;MACU,gBAAgB,CAAA;AACpB,IAAA,aAAa;AACb,IAAA,SAAS;AACT,IAAA,UAAU;AACT,IAAA,MAAM;IACN,SAAS,GAAG,KAAK;AACjB,IAAA,MAAM;AAEd;;;;AAIG;AACH,IAAA,WAAA,CAAY,SAA0B,EAAE,EAAA;AACtC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;AACpB,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAIA,6BAAM,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE1E,QAAA,IAAI,MAAM,CAAC,SAAS,EAAE;YACpB,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,KAAI;gBAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA,qBAAA,EAAwB,GAAG,CAAA,CAAE,CAAC;AAClD,YAAA,CAAC,CAAC;QACJ;IACF;AAEA;;;AAGG;AACH,IAAA,MAAM,OAAO,GAAA;AACX,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAClB,YAAA,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AC,wBAAwB,CAAC;gBAC5C;qBAAO;;AAEL,oBAAA,IAAI,CAAC,aAAa,CAAC,qBAAqB,EAAE;;gBAE5C;YACF;YAAE,OAAO,CAAC,EAAE;gBACV,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA,6BAAA,EAAgC,CAAC,CAAA,CAAE,CAAC;YACvD;AACA,YAAA,IAAI,CAAC,aAAa,GAAG,SAAS;QAChC;;AAGA,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAClB,YAAA,IAAI;AACF,gBAAA,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;AACxB,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;YACxC;YAAE,OAAO,CAAC,EAAE;gBACV,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA,yBAAA,EAA4B,CAAC,CAAA,CAAE,CAAC;YACnD;AACA,YAAA,IAAI,CAAC,SAAS,GAAG,SAAS;QAC5B;AAEA,QAAA,IAAI,CAAC,SAAS,GAAG,KAAK;AACtB,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;IACxC;AAEA;;;AAGG;AACH,IAAA,IAAW,OAAO,GAAA;QAChB,OAAO,IAAI,CAAC,SAAS;IACvB;AACD"}
1
+ {"version":3,"file":"LifecycleManager.js","sources":["../../../src/core/lifecycle/LifecycleManager.ts"],"sourcesContent":["import { ILogger, getSharedLogger } from '@/infrastructure/logger';\nimport WindowManager from '@/core/window/WindowManager';\nimport IpcRouter from '@/core/ipc/IpcRouter';\nimport { MessageBus } from '@/core/message-bus/MessageBus';\nimport { WindowManagerConfig } from '@/core/window/window-manager.type';\nimport { DebugHelper } from '@/infrastructure/debug';\n\n/**\n * Lifecycle Configuration\n * 生命周期配置\n */\nexport interface LifecycleConfig extends WindowManagerConfig {\n /**\n * Whether to automatically start on instantiation (default: false)\n * 是否在实例化时自动启动 (默认: false)\n */\n autoStart?: boolean;\n\n /**\n * Existing IpcRouter instance\n * 现有的 IpcRouter 实例\n */\n ipcRouter?: IpcRouter;\n\n /**\n * Existing WindowManager instance\n * 现有的 WindowManager 实例\n */\n windowManager?: WindowManager;\n\n /**\n * Existing MessageBus instance\n * 现有的 MessageBus 实例\n */\n messageBus?: MessageBus;\n}\n\n/**\n * Lifecycle Manager\n * 生命周期管理器\n *\n * Orchestrates the startup and shutdown of the Electron Toolkit modules.\n * 编排 Electron Toolkit 模块的启动和关闭。\n */\nexport class LifecycleManager {\n public windowManager?: WindowManager;\n public ipcRouter?: IpcRouter;\n public messageBus?: MessageBus;\n private logger: ILogger;\n private isStarted = false;\n private config: LifecycleConfig;\n\n /**\n * Create LifecycleManager instance\n * 创建 LifecycleManager 实例\n * @param config - Configuration object\n */\n constructor(config: LifecycleConfig = {}) {\n this.config = config;\n const logger = config.logger || getSharedLogger(config.loggerOptions);\n this.logger = logger;\n\n if (config.autoStart) {\n this.startup().catch((err) => {\n this.logger.error(`Auto-startup failed: ${err}`);\n });\n }\n }\n\n /**\n * Start up all services\n * 启动所有服务\n */\n async startup(): Promise<void> {\n if (this.isStarted) {\n this.logger.warn('LifecycleManager already started');\n return;\n }\n\n try {\n this.logger.info('Starting up Electron Toolkit services...');\n\n // 1. Initialize IpcRouter (Foundation for communication)\n // 1. 初始化 IpcRouter (通信基础)\n this.ipcRouter = this.config.ipcRouter || new IpcRouter({ logger: this.logger });\n this.logger.info('IpcRouter initialized');\n\n // 2. Initialize MessageBus (Cross-window communication)\n // 2. 初始化 MessageBus (跨窗口通信)\n this.messageBus = this.config.messageBus || new MessageBus({ logger: this.logger });\n\n // 3. Initialize WindowManager (Core window management)\n // 3. 初始化 WindowManager (核心窗口管理)\n this.windowManager =\n this.config.windowManager ||\n new WindowManager({\n ...this.config,\n logger: this.logger,\n ipcRouter: this.ipcRouter,\n messageBus: this.messageBus,\n });\n // Wait for WindowManager initialization (plugins, etc.)\n await this.windowManager.ready();\n this.logger.info('WindowManager initialized');\n\n // 4. Connect MessageBus to WindowManager\n // 4. 连接 MessageBus 到 WindowManager\n this.messageBus.autoRegisterWindows(this.windowManager);\n this.logger.info('MessageBus initialized');\n\n // 4. Setup Debug Mode if enabled\n // 4. 如果启用,设置调试模式\n if (this.config.isDevelopment || process.env.NODE_ENV === 'development') {\n DebugHelper.enableDebugMode();\n DebugHelper.register('windowManager', this.windowManager);\n DebugHelper.register('ipcRouter', this.ipcRouter);\n DebugHelper.register('messageBus', this.messageBus);\n DebugHelper.register('lifecycleManager', this);\n this.logger.info('Debug mode enabled');\n }\n\n this.isStarted = true;\n this.logger.info('Startup completed successfully');\n } catch (error) {\n this.logger.error(`Startup failed: ${error}`);\n await this.shutdown(); // Cleanup partial initialization\n throw error;\n }\n }\n\n /**\n * Shut down all services gracefully\n * 优雅地关闭所有服务\n */\n async shutdown(): Promise<void> {\n this.logger.info('Shutting down Electron Toolkit services...');\n\n // Shutdown in reverse order of initialization\n // 按初始化的逆序关闭\n\n // 1. Dispose MessageBus\n if (this.messageBus) {\n try {\n this.messageBus.dispose();\n this.logger.info('MessageBus disposed');\n } catch (e) {\n this.logger.warn(`MessageBus dispose error: ${e}`);\n }\n this.messageBus = undefined;\n }\n\n // 2. Dispose WindowManager (closes all windows)\n if (this.windowManager) {\n try {\n if (typeof this.windowManager.dispose === 'function') {\n await this.windowManager.dispose();\n this.logger.info('WindowManager disposed');\n } else {\n // Fallback if dispose is not implemented\n this.windowManager.stopCleanupProtection();\n // Ideally we should close all windows here, but we rely on WindowManager's dispose\n }\n } catch (e) {\n this.logger.warn(`WindowManager dispose error: ${e}`);\n }\n this.windowManager = undefined;\n }\n\n // 3. Dispose IpcRouter\n if (this.ipcRouter) {\n try {\n this.ipcRouter.dispose();\n this.logger.info('IpcRouter disposed');\n } catch (e) {\n this.logger.warn(`IpcRouter dispose error: ${e}`);\n }\n this.ipcRouter = undefined;\n }\n\n this.isStarted = false;\n this.logger.info('Shutdown completed');\n }\n\n /**\n * Get initialization status\n * 获取初始化状态\n */\n public get started():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ACxC;YAAE,OAAO,CAAC,EAAE;gBACV,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA,yBAAA,EAA4B,CAAC,CAAA,CAAE,CAAC;YACnD;AACA,YAAA,IAAI,CAAC,SAAS,GAAG,SAAS;QAC5B;AAEA,QAAA,IAAI,CAAC,SAAS,GAAG,KAAK;AACtB,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;IACxC;AAEA;;;AAGG;AACH,IAAA,IAAW,OAAO,GAAA;QAChB,OAAO,IAAI,CAAC,SAAS;IACvB;AACD"}
@@ -1,4 +1,4 @@
1
- import WindowManager from'../window/WindowManager.mjs';import IpcRouter from'../ipc/IpcRouter.mjs';import {MessageBus}from'../message-bus/MessageBus.mjs';import {DebugHelper}from'../../infrastructure/debug/index.mjs';import {ElectronLogger}from'../../infrastructure/logger/ElectronLogger.mjs';/**
1
+ import {getSharedLogger}from'../../infrastructure/logger/index.mjs';import WindowManager from'../window/WindowManager.mjs';import IpcRouter from'../ipc/IpcRouter.mjs';import {MessageBus}from'../message-bus/MessageBus.mjs';import {DebugHelper}from'../../infrastructure/debug/index.mjs';/**
2
2
  * Lifecycle Manager
3
3
  * 生命周期管理器
4
4
  *
@@ -19,7 +19,8 @@ class LifecycleManager {
19
19
  */
20
20
  constructor(config = {}) {
21
21
  this.config = config;
22
- this.logger = config.logger || new ElectronLogger({ appName: 'LifecycleManager' });
22
+ const logger = config.logger || getSharedLogger(config.loggerOptions);
23
+ this.logger = logger;
23
24
  if (config.autoStart) {
24
25
  this.startup().catch((err) => {
25
26
  this.logger.error(`Auto-startup failed: ${err}`);
@@ -39,17 +40,18 @@ class LifecycleManager {
39
40
  this.logger.info('Starting up Electron Toolkit services...');
40
41
  // 1. Initialize IpcRouter (Foundation for communication)
41
42
  // 1. 初始化 IpcRouter (通信基础)
42
- this.ipcRouter = this.config.ipcRouter || new IpcRouter({ logger: this.config.logger });
43
+ this.ipcRouter = this.config.ipcRouter || new IpcRouter({ logger: this.logger });
43
44
  this.logger.info('IpcRouter initialized');
44
45
  // 2. Initialize MessageBus (Cross-window communication)
45
46
  // 2. 初始化 MessageBus (跨窗口通信)
46
- this.messageBus = this.config.messageBus || new MessageBus({ logger: this.config.logger });
47
+ this.messageBus = this.config.messageBus || new MessageBus({ logger: this.logger });
47
48
  // 3. Initialize WindowManager (Core window management)
48
49
  // 3. 初始化 WindowManager (核心窗口管理)
49
50
  this.windowManager =
50
51
  this.config.windowManager ||
51
52
  new WindowManager({
52
53
  ...this.config,
54
+ logger: this.logger,
53
55
  ipcRouter: this.ipcRouter,
54
56
  messageBus: this.messageBus,
55
57
  });
@@ -1 +1 @@
1
- {"version":3,"file":"LifecycleManager.mjs","sources":["../../../src/core/lifecycle/LifecycleManager.ts"],"sourcesContent":["import { Logger, ILogger } from '@/infrastructure/logger';\nimport WindowManager from '@/core/window/WindowManager';\nimport IpcRouter from '@/core/ipc/IpcRouter';\nimport { MessageBus } from '@/core/message-bus/MessageBus';\nimport { WindowManagerConfig } from '@/core/window/window-manager.type';\nimport { DebugHelper } from '@/infrastructure/debug';\n\n/**\n * Lifecycle Configuration\n * 生命周期配置\n */\nexport interface LifecycleConfig extends WindowManagerConfig {\n /**\n * Whether to automatically start on instantiation (default: false)\n * 是否在实例化时自动启动 (默认: false)\n */\n autoStart?: boolean;\n\n /**\n * Existing IpcRouter instance\n * 现有的 IpcRouter 实例\n */\n ipcRouter?: IpcRouter;\n\n /**\n * Existing WindowManager instance\n * 现有的 WindowManager 实例\n */\n windowManager?: WindowManager;\n\n /**\n * Existing MessageBus instance\n * 现有的 MessageBus 实例\n */\n messageBus?: MessageBus;\n}\n\n/**\n * Lifecycle Manager\n * 生命周期管理器\n *\n * Orchestrates the startup and shutdown of the Electron Toolkit modules.\n * 编排 Electron Toolkit 模块的启动和关闭。\n */\nexport class LifecycleManager {\n public windowManager?: WindowManager;\n public ipcRouter?: IpcRouter;\n public messageBus?: MessageBus;\n private logger: ILogger;\n private isStarted = false;\n private config: LifecycleConfig;\n\n /**\n * Create LifecycleManager instance\n * 创建 LifecycleManager 实例\n * @param config - Configuration object\n */\n constructor(config: LifecycleConfig = {}) {\n this.config = config;\n this.logger = config.logger || new Logger({ appName: 'LifecycleManager' });\n\n if (config.autoStart) {\n this.startup().catch((err) => {\n this.logger.error(`Auto-startup failed: ${err}`);\n });\n }\n }\n\n /**\n * Start up all services\n * 启动所有服务\n */\n async startup(): Promise<void> {\n if (this.isStarted) {\n this.logger.warn('LifecycleManager already started');\n return;\n }\n\n try {\n this.logger.info('Starting up Electron Toolkit services...');\n\n // 1. Initialize IpcRouter (Foundation for communication)\n // 1. 初始化 IpcRouter (通信基础)\n this.ipcRouter = this.config.ipcRouter || new IpcRouter({ logger: this.config.logger });\n this.logger.info('IpcRouter initialized');\n\n // 2. Initialize MessageBus (Cross-window communication)\n // 2. 初始化 MessageBus (跨窗口通信)\n this.messageBus = this.config.messageBus || new MessageBus({ logger: this.config.logger });\n\n // 3. Initialize WindowManager (Core window management)\n // 3. 初始化 WindowManager (核心窗口管理)\n this.windowManager =\n this.config.windowManager ||\n new WindowManager({\n ...this.config,\n ipcRouter: this.ipcRouter,\n messageBus: this.messageBus,\n });\n // Wait for WindowManager initialization (plugins, etc.)\n await this.windowManager.ready();\n this.logger.info('WindowManager initialized');\n\n // 4. Connect MessageBus to WindowManager\n // 4. 连接 MessageBus 到 WindowManager\n this.messageBus.autoRegisterWindows(this.windowManager);\n this.logger.info('MessageBus initialized');\n\n // 4. Setup Debug Mode if enabled\n // 4. 如果启用,设置调试模式\n if (this.config.isDevelopment || process.env.NODE_ENV === 'development') {\n DebugHelper.enableDebugMode();\n DebugHelper.register('windowManager', this.windowManager);\n DebugHelper.register('ipcRouter', this.ipcRouter);\n DebugHelper.register('messageBus', this.messageBus);\n DebugHelper.register('lifecycleManager', this);\n this.logger.info('Debug mode enabled');\n }\n\n this.isStarted = true;\n this.logger.info('Startup completed successfully');\n } catch (error) {\n this.logger.error(`Startup failed: ${error}`);\n await this.shutdown(); // Cleanup partial initialization\n throw error;\n }\n }\n\n /**\n * Shut down all services gracefully\n * 优雅地关闭所有服务\n */\n async shutdown(): Promise<void> {\n this.logger.info('Shutting down Electron Toolkit services...');\n\n // Shutdown in reverse order of initialization\n // 按初始化的逆序关闭\n\n // 1. Dispose MessageBus\n if (this.messageBus) {\n try {\n this.messageBus.dispose();\n this.logger.info('MessageBus disposed');\n } catch (e) {\n this.logger.warn(`MessageBus dispose error: ${e}`);\n }\n this.messageBus = undefined;\n }\n\n // 2. Dispose WindowManager (closes all windows)\n if (this.windowManager) {\n try {\n if (typeof this.windowManager.dispose === 'function') {\n await this.windowManager.dispose();\n this.logger.info('WindowManager disposed');\n } else {\n // Fallback if dispose is not implemented\n this.windowManager.stopCleanupProtection();\n // Ideally we should close all windows here, but we rely on WindowManager's dispose\n }\n } catch (e) {\n this.logger.warn(`WindowManager dispose error: ${e}`);\n }\n this.windowManager = undefined;\n }\n\n // 3. Dispose IpcRouter\n if (this.ipcRouter) {\n try {\n this.ipcRouter.dispose();\n this.logger.info('IpcRouter disposed');\n } catch (e) {\n this.logger.warn(`IpcRouter dispose error: ${e}`);\n }\n this.ipcRouter = undefined;\n }\n\n this.isStarted = false;\n this.logger.info('Shutdown completed');\n }\n\n /**\n * Get initialization status\n * 获取初始化状态\n */\n public get started(): boolean {\n return this.isStarted;\n }\n}\n"],"names":["Logger"],"mappings":"qSAqCA;;;;;;AAMG;MACU,gBAAgB,CAAA;AACpB,IAAA,aAAa;AACb,IAAA,SAAS;AACT,IAAA,UAAU;AACT,IAAA,MAAM;IACN,SAAS,GAAG,KAAK;AACjB,IAAA,MAAM;AAEd;;;;AAIG;AACH,IAAA,WAAA,CAAY,SAA0B,EAAE,EAAA;AACtC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;AACpB,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAIA,cAAM,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAA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A,0BAAA,EAA6B,CAAC,CAAA,CAAE,CAAC;YACpD;AACA,YAAA,IAAI,CAAC,UAAU,GAAG,SAAS;QAC7B;;AAGA,QAAA,IAAI,IAAI,CAAC,aAAa,EAAE;AACtB,YAAA,IAAI;gBACF,IAAI,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,KAAK,UAAU,EAAE;AACpD,oBAAA,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE;AAClC,oBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC;gBAC5C;qBAAO;;AAEL,oBAAA,IAAI,CAAC,aAAa,CAAC,qBAAqB,EAAE;;gBAE5C;YACF;YAAE,OAAO,CAAC,EAAE;gBACV,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA,6BAAA,EAAgC,CAAC,CAAA,CAAE,CAAC;YACvD;AACA,YAAA,IAAI,CAAC,aAAa,GAAG,SAAS;QAChC;;AAGA,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAClB,YAAA,IAAI;AACF,gBAAA,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;AACxB,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;YACxC;YAAE,OAAO,CAAC,EAAE;gBACV,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA,yBAAA,EAA4B,CAAC,CAAA,CAAE,CAAC;YACnD;AACA,YAAA,IAAI,CAAC,SAAS,GAAG,SAAS;QAC5B;AAEA,QAAA,IAAI,CAAC,SAAS,GAAG,KAAK;AACtB,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;IACxC;AAEA;;;AAGG;AACH,IAAA,IAAW,OAAO,GAAA;QAChB,OAAO,IAAI,CAAC,SAAS;IACvB;AACD"}
1
+ {"version":3,"file":"LifecycleManager.mjs","sources":["../../../src/core/lifecycle/LifecycleManager.ts"],"sourcesContent":["import { ILogger, getSharedLogger } from '@/infrastructure/logger';\nimport WindowManager from '@/core/window/WindowManager';\nimport IpcRouter from '@/core/ipc/IpcRouter';\nimport { MessageBus } from '@/core/message-bus/MessageBus';\nimport { WindowManagerConfig } from '@/core/window/window-manager.type';\nimport { DebugHelper } from '@/infrastructure/debug';\n\n/**\n * Lifecycle Configuration\n * 生命周期配置\n */\nexport interface LifecycleConfig extends WindowManagerConfig {\n /**\n * Whether to automatically start on instantiation (default: false)\n * 是否在实例化时自动启动 (默认: false)\n */\n autoStart?: boolean;\n\n /**\n * Existing IpcRouter instance\n * 现有的 IpcRouter 实例\n */\n ipcRouter?: IpcRouter;\n\n /**\n * Existing WindowManager instance\n * 现有的 WindowManager 实例\n */\n windowManager?: WindowManager;\n\n /**\n * Existing MessageBus instance\n * 现有的 MessageBus 实例\n */\n messageBus?: MessageBus;\n}\n\n/**\n * Lifecycle Manager\n * 生命周期管理器\n *\n * Orchestrates the startup and shutdown of the Electron Toolkit modules.\n * 编排 Electron Toolkit 模块的启动和关闭。\n */\nexport class LifecycleManager {\n public windowManager?: WindowManager;\n public ipcRouter?: IpcRouter;\n public messageBus?: MessageBus;\n private logger: ILogger;\n private isStarted = false;\n private config: LifecycleConfig;\n\n /**\n * Create LifecycleManager instance\n * 创建 LifecycleManager 实例\n * @param config - Configuration object\n */\n constructor(config: LifecycleConfig = {}) {\n this.config = config;\n const logger = config.logger || getSharedLogger(config.loggerOptions);\n this.logger = logger;\n\n if (config.autoStart) {\n this.startup().catch((err) => {\n this.logger.error(`Auto-startup failed: ${err}`);\n });\n }\n }\n\n /**\n * Start up all services\n * 启动所有服务\n */\n async startup(): Promise<void> {\n if (this.isStarted) {\n this.logger.warn('LifecycleManager already started');\n return;\n }\n\n try {\n this.logger.info('Starting up Electron Toolkit services...');\n\n // 1. Initialize IpcRouter (Foundation for communication)\n // 1. 初始化 IpcRouter (通信基础)\n this.ipcRouter = this.config.ipcRouter || new IpcRouter({ logger: this.logger });\n this.logger.info('IpcRouter initialized');\n\n // 2. Initialize MessageBus (Cross-window communication)\n // 2. 初始化 MessageBus (跨窗口通信)\n this.messageBus = this.config.messageBus || new MessageBus({ logger: this.logger });\n\n // 3. Initialize WindowManager (Core window management)\n // 3. 初始化 WindowManager (核心窗口管理)\n this.windowManager =\n this.config.windowManager ||\n new WindowManager({\n ...this.config,\n logger: this.logger,\n ipcRouter: this.ipcRouter,\n messageBus: this.messageBus,\n });\n // Wait for WindowManager initialization (plugins, etc.)\n await this.windowManager.ready();\n this.logger.info('WindowManager initialized');\n\n // 4. Connect MessageBus to WindowManager\n // 4. 连接 MessageBus 到 WindowManager\n this.messageBus.autoRegisterWindows(this.windowManager);\n this.logger.info('MessageBus initialized');\n\n // 4. Setup Debug Mode if enabled\n // 4. 如果启用,设置调试模式\n if (this.config.isDevelopment || process.env.NODE_ENV === 'development') {\n DebugHelper.enableDebugMode();\n DebugHelper.register('windowManager', this.windowManager);\n DebugHelper.register('ipcRouter', this.ipcRouter);\n DebugHelper.register('messageBus', this.messageBus);\n DebugHelper.register('lifecycleManager', this);\n this.logger.info('Debug mode enabled');\n }\n\n this.isStarted = true;\n this.logger.info('Startup completed successfully');\n } catch (error) {\n this.logger.error(`Startup failed: ${error}`);\n await this.shutdown(); // Cleanup partial initialization\n throw error;\n }\n }\n\n /**\n * Shut down all services gracefully\n * 优雅地关闭所有服务\n */\n async shutdown(): Promise<void> {\n this.logger.info('Shutting down Electron Toolkit services...');\n\n // Shutdown in reverse order of initialization\n // 按初始化的逆序关闭\n\n // 1. Dispose MessageBus\n if (this.messageBus) {\n try {\n this.messageBus.dispose();\n this.logger.info('MessageBus disposed');\n } catch (e) {\n this.logger.warn(`MessageBus dispose error: ${e}`);\n }\n this.messageBus = undefined;\n }\n\n // 2. Dispose WindowManager (closes all windows)\n if (this.windowManager) {\n try {\n if (typeof this.windowManager.dispose === 'function') {\n await this.windowManager.dispose();\n this.logger.info('WindowManager disposed');\n } else {\n // Fallback if dispose is not implemented\n this.windowManager.stopCleanupProtection();\n // Ideally we should close all windows here, but we rely on WindowManager's dispose\n }\n } catch (e) {\n this.logger.warn(`WindowManager dispose error: ${e}`);\n }\n this.windowManager = undefined;\n }\n\n // 3. Dispose IpcRouter\n if (this.ipcRouter) {\n try {\n this.ipcRouter.dispose();\n this.logger.info('IpcRouter disposed');\n } catch (e) {\n this.logger.warn(`IpcRouter dispose error: ${e}`);\n }\n this.ipcRouter = undefined;\n }\n\n this.isStarted = false;\n this.logger.info('Shutdown completed');\n }\n\n /**\n * Get initialization status\n * 获取初始化状态\n */\n public get started(): boolean {\n return this.isStarted;\n }\n}\n"],"names":[],"mappings":"6RAqCA;;;;;;AAMG;MACU,gBAAgB,CAAA;AACpB,IAAA,aAAa;AACb,IAAA,SAAS;AACT,IAAA,UAAU;AACT,IAAA,MAAM;IACN,SAAS,GAAG,KAAK;AACjB,IAAA,MAAM;AAEd;;;;AAIG;AACH,IAAA,WAAA,CAAY,SAA0B,EAAE,EAAA;AACtC,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;AACpB,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,eAAe,CAAC,MAAM,CAAC,aAAa,CAAC;AACrE,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;AAEpB,QAAA,IAAI,MAAM,CAAC,SAAS,EAAE;YACpB,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,KAAI;gBAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA,qBAAA,EAAwB,GAAG,CAAA,CAAE,CAAC;AAClD,YAAA,CAAC,CAAC;QACJ;IACF;AAEA;;;AAGG;AACH,IAAA,MAAM,OAAO,GAAA;AACX,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAClB,YAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC;YACpD;QACF;AAEA,QAAA,IAAI;AACF,YAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC;;;YAI5D,IA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IAAI,CAAC,CAAA,6BAAA,EAAgC,CAAC,CAAA,CAAE,CAAC;YACvD;AACA,YAAA,IAAI,CAAC,aAAa,GAAG,SAAS;QAChC;;AAGA,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAClB,YAAA,IAAI;AACF,gBAAA,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;AACxB,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;YACxC;YAAE,OAAO,CAAC,EAAE;gBACV,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA,yBAAA,EAA4B,CAAC,CAAA,CAAE,CAAC;YACnD;AACA,YAAA,IAAI,CAAC,SAAS,GAAG,SAAS;QAC5B;AAEA,QAAA,IAAI,CAAC,SAAS,GAAG,KAAK;AACtB,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC;IACxC;AAEA;;;AAGG;AACH,IAAA,IAAW,OAAO,GAAA;QAChB,OAAO,IAAI,CAAC,SAAS;IACvB;AACD"}
@@ -60,12 +60,12 @@ class WindowCreator {
60
60
  }
61
61
  // Create new window instance
62
62
  // 创建新窗口实例
63
- const options = this.winId
64
- ? {
65
- windowId: this.winId,
66
- ...(this.extraOptions?.(this.data.data) || {}),
67
- }
68
- : this.data.data;
63
+ const base = this.data.data || {};
64
+ const options = {
65
+ ...base,
66
+ ...(this.extraOptions?.(base) || {}),
67
+ ...(this.winId ? { windowId: this.winId } : {}),
68
+ };
69
69
  this.winId = await this.creator(options);
70
70
  isNew = true;
71
71
  return { winId: this.winId, isNew };
@@ -149,12 +149,12 @@ class WindowCreator {
149
149
  const { isNew } = await this.createWindow();
150
150
  // Load content if it's a new window
151
151
  if (isNew) {
152
- const options = this.winId
153
- ? {
154
- windowId: this.winId,
155
- ...(this.extraOptions?.(this.data.data) || {}),
156
- }
157
- : this.data.data;
152
+ const base = this.data.data || {};
153
+ const options = {
154
+ ...base,
155
+ ...(this.extraOptions?.(base) || {}),
156
+ windowId: this.winId,
157
+ };
158
158
  await this.loadContent(this.winId, options);
159
159
  }
160
160
  this.showWindow(this.winId, isNew);
@@ -1 +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,IAA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AAC,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"}
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 base = this.data.data || ({} as any);\n const options = {\n ...(base as any),\n ...(this.extraOptions?.(base) || {}),\n ...(this.winId ? { windowId: this.winId } : {}),\n };\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 base = this.data.data || ({} as any);\n const options = {\n ...(base as any),\n ...(this.extraOptions?.(base) || {}),\n windowId: this.winId,\n };\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,OA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AI,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"}
@@ -60,12 +60,12 @@ class WindowCreator {
60
60
  }
61
61
  // Create new window instance
62
62
  // 创建新窗口实例
63
- const options = this.winId
64
- ? {
65
- windowId: this.winId,
66
- ...(this.extraOptions?.(this.data.data) || {}),
67
- }
68
- : this.data.data;
63
+ const base = this.data.data || {};
64
+ const options = {
65
+ ...base,
66
+ ...(this.extraOptions?.(base) || {}),
67
+ ...(this.winId ? { windowId: this.winId } : {}),
68
+ };
69
69
  this.winId = await this.creator(options);
70
70
  isNew = true;
71
71
  return { winId: this.winId, isNew };
@@ -149,12 +149,12 @@ class WindowCreator {
149
149
  const { isNew } = await this.createWindow();
150
150
  // Load content if it's a new window
151
151
  if (isNew) {
152
- const options = this.winId
153
- ? {
154
- windowId: this.winId,
155
- ...(this.extraOptions?.(this.data.data) || {}),
156
- }
157
- : this.data.data;
152
+ const base = this.data.data || {};
153
+ const options = {
154
+ ...base,
155
+ ...(this.extraOptions?.(base) || {}),
156
+ windowId: this.winId,
157
+ };
158
158
  await this.loadContent(this.winId, options);
159
159
  }
160
160
  this.showWindow(this.winId, isNew);
@@ -1 +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,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,cAAM,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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CAAC;QACJ;AAAO,aAAA,IAAI,OAAO,CAAC,QAAQ,EAAE;AAC3B,YAAA,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAI;AACzC,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA,qBAAA,EAAwB,OAAO,CAAC,QAAQ,gBAAgB,KAAK,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"}
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 base = this.data.data || ({} as any);\n const options = {\n ...(base as any),\n ...(this.extraOptions?.(base) || {}),\n ...(this.winId ? { windowId: this.winId } : {}),\n };\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 base = this.data.data || ({} as any);\n const options = {\n ...(base as any),\n ...(this.extraOptions?.(base) || {}),\n windowId: this.winId,\n };\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,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,cAAM,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,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1,7 @@
1
1
  import { BrowserWindow, BrowserWindowConstructorOptions } from 'electron';
2
2
  import type WindowManager from './WindowManager';
3
3
  import type { ILogger } from '@/infrastructure/logger';
4
+ import type { LoggerOptions } from '@/infrastructure/logger';
4
5
  import type StateKeeper from '@/internal/utils/StateKeeper';
5
6
  import type { IIpcTransport } from '@/core/ipc/transport/ipc.type';
6
7
  import type IpcRouter from '@/core/ipc/IpcRouter';
@@ -269,6 +270,11 @@ export interface WindowManagerConfig {
269
270
  * 日志实例
270
271
  */
271
272
  logger?: ILogger;
273
+ /**
274
+ * Logger configuration options
275
+ * 日志配置选项
276
+ */
277
+ loggerOptions?: LoggerOptions;
272
278
  /**
273
279
  * IpcRouter instance for dependency injection
274
280
  * 用于依赖注入的 IpcRouter 实例
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ export * from './core/window';
17
17
  export * from './core/ipc';
18
18
  export * from './core/message-bus';
19
19
  export * from './core/lifecycle/LifecycleManager';
20
- export { Logger, type LoggerOptions } from './infrastructure/logger';
20
+ export { Logger, type LoggerOptions, getSharedLogger, setSharedLogger, } from './infrastructure/logger';
21
21
  export * from './preload';
22
22
  export * from './infrastructure/config';
23
23
  export * as Types from './types';
package/dist/index.js CHANGED
@@ -1,33 +1,35 @@
1
- 'use strict';var WindowManager=require('./core/window/WindowManager.js'),IpcRouter=require('./core/ipc/IpcRouter.js'),MessageBus=require('./core/message-bus/MessageBus.js'),index=require('./infrastructure/debug/index.js'),LifecycleManager=require('./core/lifecycle/LifecycleManager.js'),index$1=require('./preload/index.js'),types=require('./types.js'),index$2=require('./infrastructure/errors/index.js'),WindowStore=require('./core/window/WindowStore.js'),WindowCreator=require('./core/window/WindowCreator.js'),IpcHandler=require('./core/ipc/IpcHandler.js'),ElectronLogger=require('./infrastructure/logger/ElectronLogger.js'),EnhancedDebugHelper=require('./infrastructure/debug/EnhancedDebugHelper.js'),windowManager_schema=require('./core/window/window-manager.schema.js'),IpcSetup=require('./core/window/IpcSetup.js'),WindowError=require('./core/error/WindowError.js'),MessageBusClient=require('./core/message-bus/MessageBusClient.js'),preload=require('./core/message-bus/preload.js'),messageBus_type=require('./core/message-bus/message-bus.type.js'),ConfigManager=require('./infrastructure/config/ConfigManager.js'),ErrorCodes=require('./infrastructure/errors/ErrorCodes.js'),StandardError=require('./infrastructure/errors/StandardError.js');/**
1
+ 'use strict';var WindowManager=require('./core/window/WindowManager.js'),IpcRouter=require('./core/ipc/IpcRouter.js'),MessageBus=require('./core/message-bus/MessageBus.js'),index$1=require('./infrastructure/debug/index.js'),index=require('./infrastructure/logger/index.js'),LifecycleManager=require('./core/lifecycle/LifecycleManager.js'),index$2=require('./preload/index.js'),types=require('./types.js'),index$3=require('./infrastructure/errors/index.js'),WindowStore=require('./core/window/WindowStore.js'),WindowCreator=require('./core/window/WindowCreator.js'),IpcHandler=require('./core/ipc/IpcHandler.js'),ElectronLogger=require('./infrastructure/logger/ElectronLogger.js'),EnhancedDebugHelper=require('./infrastructure/debug/EnhancedDebugHelper.js'),windowManager_schema=require('./core/window/window-manager.schema.js'),IpcSetup=require('./core/window/IpcSetup.js'),WindowError=require('./core/error/WindowError.js'),MessageBusClient=require('./core/message-bus/MessageBusClient.js'),preload=require('./core/message-bus/preload.js'),messageBus_type=require('./core/message-bus/message-bus.type.js'),ConfigManager=require('./infrastructure/config/ConfigManager.js'),ErrorCodes=require('./infrastructure/errors/ErrorCodes.js'),StandardError=require('./infrastructure/errors/StandardError.js');/**
2
2
  * Quick Start Helper
3
3
  * 快速开始助手
4
4
  * @param config - WindowManager configuration
5
5
  * @returns Object containing initialized instances
6
6
  */
7
7
  function createElectronToolkit(config = {}) {
8
+ const logger = config.logger || index.getSharedLogger(config.loggerOptions);
8
9
  // Create IpcRouter
9
- const ipcRouter = new IpcRouter({ logger: config.logger });
10
+ const ipcRouter = new IpcRouter({ logger });
10
11
  // Create WindowManager with ipcRouter integrated
11
12
  const windowManager = new WindowManager({
12
13
  ...config,
14
+ logger,
13
15
  ipcRouter,
14
16
  });
15
17
  // Create MessageBus
16
- const messageBus = new MessageBus.MessageBus({ logger: config.logger });
18
+ const messageBus = new MessageBus.MessageBus({ logger });
17
19
  // Automatically integrate MessageBus with WindowManager
18
20
  // 自动集成 MessageBus 和 WindowManager
19
21
  messageBus.autoRegisterWindows(windowManager);
20
22
  // Setup Debug Mode
21
23
  // 设置调试模式
22
24
  if (config.isDevelopment || process.env.NODE_ENV === 'development') {
23
- index.DebugHelper.enableDebugMode();
24
- index.DebugHelper.register('windowManager', windowManager);
25
- index.DebugHelper.register('ipcRouter', ipcRouter);
26
- index.DebugHelper.register('messageBus', messageBus);
25
+ index$1.DebugHelper.enableDebugMode();
26
+ index$1.DebugHelper.register('windowManager', windowManager);
27
+ index$1.DebugHelper.register('ipcRouter', ipcRouter);
28
+ index$1.DebugHelper.register('messageBus', messageBus);
27
29
  }
28
30
  return {
29
31
  windowManager,
30
32
  ipcRouter,
31
33
  messageBus,
32
34
  };
33
- }exports.WindowManager=WindowManager;exports.IpcRouter=IpcRouter;exports.MessageBus=MessageBus.MessageBus;exports.DebugHelper=index.DebugHelper;exports.LifecycleManager=LifecycleManager.LifecycleManager;exports.IpcRendererBridge=index$1.IpcRendererBridge;exports.ipcRendererBridge=index$1.ipcRendererBridge;exports.Types=types;exports.ElectronToolkitError=index$2.ElectronToolkitError;exports.IpcHandlerError=index$2.IpcHandlerError;exports.WindowNotFoundError=index$2.WindowNotFoundError;exports.WindowStore=WindowStore;exports.WindowCreator=WindowCreator;exports.IpcHandler=IpcHandler;exports.Logger=ElectronLogger.ElectronLogger;exports.EnhancedDebugHelper=EnhancedDebugHelper.EnhancedDebugHelper;exports.debugHelper=EnhancedDebugHelper.debugHelper;exports.validateWindowManagerConfig=windowManager_schema.validateWindowManagerConfig;exports.IpcSetup=IpcSetup.IpcSetup;exports.WindowError=WindowError.WindowError;Object.defineProperty(exports,"WindowErrorCode",{enumerable:true,get:function(){return WindowError.WindowErrorCode}});exports.MessageBusClient=MessageBusClient.MessageBusClient;exports.setupMessageBus=preload.setupMessageBus;Object.defineProperty(exports,"MessageProtocolType",{enumerable:true,get:function(){return messageBus_type.MessageProtocolType}});exports.ConfigManager=ConfigManager.ConfigManager;Object.defineProperty(exports,"ErrorCategory",{enumerable:true,get:function(){return ErrorCodes.ErrorCategory}});Object.defineProperty(exports,"IpcErrorCode",{enumerable:true,get:function(){return ErrorCodes.IpcErrorCode}});Object.defineProperty(exports,"MessageBusErrorCode",{enumerable:true,get:function(){return ErrorCodes.MessageBusErrorCode}});Object.defineProperty(exports,"WindowManagerErrorCode",{enumerable:true,get:function(){return ErrorCodes.WindowManagerErrorCode}});exports.NotFoundError=StandardError.NotFoundError;exports.PermissionError=StandardError.PermissionError;exports.StandardError=StandardError.StandardError;exports.ValidationError=StandardError.ValidationError;exports.createElectronToolkit=createElectronToolkit;//# sourceMappingURL=index.js.map
35
+ }exports.WindowManager=WindowManager;exports.IpcRouter=IpcRouter;exports.MessageBus=MessageBus.MessageBus;exports.DebugHelper=index$1.DebugHelper;exports.getSharedLogger=index.getSharedLogger;exports.setSharedLogger=index.setSharedLogger;exports.LifecycleManager=LifecycleManager.LifecycleManager;exports.IpcRendererBridge=index$2.IpcRendererBridge;exports.ipcRendererBridge=index$2.ipcRendererBridge;exports.Types=types;exports.ElectronToolkitError=index$3.ElectronToolkitError;exports.IpcHandlerError=index$3.IpcHandlerError;exports.WindowNotFoundError=index$3.WindowNotFoundError;exports.WindowStore=WindowStore;exports.WindowCreator=WindowCreator;exports.IpcHandler=IpcHandler;exports.Logger=ElectronLogger.ElectronLogger;exports.EnhancedDebugHelper=EnhancedDebugHelper.EnhancedDebugHelper;exports.debugHelper=EnhancedDebugHelper.debugHelper;exports.validateWindowManagerConfig=windowManager_schema.validateWindowManagerConfig;exports.IpcSetup=IpcSetup.IpcSetup;exports.WindowError=WindowError.WindowError;Object.defineProperty(exports,"WindowErrorCode",{enumerable:true,get:function(){return WindowError.WindowErrorCode}});exports.MessageBusClient=MessageBusClient.MessageBusClient;exports.setupMessageBus=preload.setupMessageBus;Object.defineProperty(exports,"MessageProtocolType",{enumerable:true,get:function(){return messageBus_type.MessageProtocolType}});exports.ConfigManager=ConfigManager.ConfigManager;Object.defineProperty(exports,"ErrorCategory",{enumerable:true,get:function(){return ErrorCodes.ErrorCategory}});Object.defineProperty(exports,"IpcErrorCode",{enumerable:true,get:function(){return ErrorCodes.IpcErrorCode}});Object.defineProperty(exports,"MessageBusErrorCode",{enumerable:true,get:function(){return ErrorCodes.MessageBusErrorCode}});Object.defineProperty(exports,"WindowManagerErrorCode",{enumerable:true,get:function(){return ErrorCodes.WindowManagerErrorCode}});exports.NotFoundError=StandardError.NotFoundError;exports.PermissionError=StandardError.PermissionError;exports.StandardError=StandardError.StandardError;exports.ValidationError=StandardError.ValidationError;exports.createElectronToolkit=createElectronToolkit;//# sourceMappingURL=index.js.map