@noxfly/noxus 3.0.0-dev.3 → 3.0.0-dev.5
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 +114 -7
- package/dist/child.d.mts +7 -1
- package/dist/child.d.ts +7 -1
- package/dist/child.js +402 -862
- package/dist/child.js.map +1 -0
- package/dist/child.mjs +389 -850
- package/dist/child.mjs.map +1 -0
- package/dist/main.d.mts +171 -125
- package/dist/main.d.ts +171 -125
- package/dist/main.js +967 -886
- package/dist/main.js.map +1 -0
- package/dist/main.mjs +914 -834
- package/dist/main.mjs.map +1 -0
- package/dist/preload.js.map +1 -0
- package/dist/preload.mjs.map +1 -0
- package/dist/renderer.d.mts +17 -2
- package/dist/renderer.d.ts +17 -2
- package/dist/renderer.js +161 -118
- package/dist/renderer.js.map +1 -0
- package/dist/renderer.mjs +150 -106
- package/dist/renderer.mjs.map +1 -0
- package/package.json +10 -9
- package/.editorconfig +0 -16
- package/.github/copilot-instructions.md +0 -32
- package/.vscode/settings.json +0 -3
- package/eslint.config.js +0 -109
- package/scripts/postbuild.js +0 -31
- package/src/DI/app-injector.ts +0 -160
- package/src/DI/injector-explorer.ts +0 -143
- package/src/DI/token.ts +0 -53
- package/src/decorators/controller.decorator.ts +0 -58
- package/src/decorators/guards.decorator.ts +0 -15
- package/src/decorators/injectable.decorator.ts +0 -81
- package/src/decorators/method.decorator.ts +0 -66
- package/src/decorators/middleware.decorator.ts +0 -15
- package/src/index.ts +0 -10
- package/src/internal/app.ts +0 -217
- package/src/internal/bootstrap.ts +0 -109
- package/src/internal/exceptions.ts +0 -57
- package/src/internal/preload-bridge.ts +0 -75
- package/src/internal/renderer-client.ts +0 -338
- package/src/internal/renderer-events.ts +0 -110
- package/src/internal/request.ts +0 -97
- package/src/internal/router.ts +0 -353
- package/src/internal/routes.ts +0 -78
- package/src/internal/socket.ts +0 -73
- package/src/main.ts +0 -26
- package/src/non-electron-process.ts +0 -22
- package/src/preload.ts +0 -10
- package/src/renderer.ts +0 -13
- package/src/utils/forward-ref.ts +0 -31
- package/src/utils/logger.ts +0 -430
- package/src/utils/radix-tree.ts +0 -210
- package/src/utils/types.ts +0 -21
- package/src/window/window-manager.ts +0 -268
- package/tsconfig.json +0 -29
- package/tsup.config.ts +0 -50
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2025 NoxFly
|
|
3
|
-
* @license MIT
|
|
4
|
-
* @author NoxFly
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { BrowserWindow } from 'electron/main';
|
|
8
|
-
import { Injectable } from '../decorators/injectable.decorator';
|
|
9
|
-
import { Logger } from '../utils/logger';
|
|
10
|
-
|
|
11
|
-
export interface WindowConfig extends Electron.BrowserWindowConstructorOptions {
|
|
12
|
-
/**
|
|
13
|
-
* If true, the window expands to fill the work area after creation
|
|
14
|
-
* using an animated setBounds. The content is loaded only after
|
|
15
|
-
* the animation completes, preventing the viewbox freeze issue.
|
|
16
|
-
* @default false
|
|
17
|
-
*/
|
|
18
|
-
expandToWorkArea?: boolean;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Duration in ms to wait for the setBounds animation to complete
|
|
22
|
-
* before loading content. Only used when expandToWorkArea is true.
|
|
23
|
-
* @default 600
|
|
24
|
-
*/
|
|
25
|
-
expandAnimationDuration?: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface WindowRecord {
|
|
29
|
-
window: BrowserWindow;
|
|
30
|
-
id: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* WindowManager is a singleton service that centralizes BrowserWindow lifecycle.
|
|
35
|
-
*
|
|
36
|
-
* Features:
|
|
37
|
-
* - Creates and tracks all application windows.
|
|
38
|
-
* - Handles the animated expand-to-work-area pattern correctly,
|
|
39
|
-
* loading content only after the animation ends to avoid the viewbox freeze.
|
|
40
|
-
* - Provides convenience methods to get windows by id, get the main window, etc.
|
|
41
|
-
* - Automatically removes windows from the registry on close.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* // In your IApp.onReady():
|
|
45
|
-
* const wm = inject(WindowManager);
|
|
46
|
-
*
|
|
47
|
-
* const win = await wm.create({
|
|
48
|
-
* width: 600, height: 600, center: true,
|
|
49
|
-
* expandToWorkArea: true,
|
|
50
|
-
* webPreferences: { preload: path.join(__dirname, 'preload.js') },
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* win.loadFile('index.html');
|
|
54
|
-
*/
|
|
55
|
-
@Injectable({ lifetime: 'singleton' })
|
|
56
|
-
export class WindowManager {
|
|
57
|
-
private readonly _windows = new Map<number, BrowserWindow>();
|
|
58
|
-
private _mainWindowId: number | undefined;
|
|
59
|
-
|
|
60
|
-
// -------------------------------------------------------------------------
|
|
61
|
-
// Creation
|
|
62
|
-
// -------------------------------------------------------------------------
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Creates a BrowserWindow, optionally performs an animated expand to the
|
|
66
|
-
* work area, and registers it in the manager.
|
|
67
|
-
*
|
|
68
|
-
* If expandToWorkArea is true:
|
|
69
|
-
* 1. The window is created at the given initial size (defaults to 600×600, centered).
|
|
70
|
-
* 2. An animated setBounds expands it to the full work area.
|
|
71
|
-
* 3. The returned promise resolves only after the animation, so callers
|
|
72
|
-
* can safely call win.loadFile() without the viewbox freeze.
|
|
73
|
-
*
|
|
74
|
-
* @param config Window configuration.
|
|
75
|
-
* @param isMain Mark this window as the main window (accessible via getMain()).
|
|
76
|
-
*/
|
|
77
|
-
public async create(config: WindowConfig, isMain = false): Promise<BrowserWindow> {
|
|
78
|
-
const {
|
|
79
|
-
expandToWorkArea = false,
|
|
80
|
-
expandAnimationDuration = 600,
|
|
81
|
-
...bwOptions
|
|
82
|
-
} = config;
|
|
83
|
-
|
|
84
|
-
// show: false by default during creation — we control visibility
|
|
85
|
-
const win = new BrowserWindow({ show: false, ...bwOptions });
|
|
86
|
-
|
|
87
|
-
this._register(win, isMain);
|
|
88
|
-
|
|
89
|
-
if (expandToWorkArea) {
|
|
90
|
-
await this._expandToWorkArea(win, expandAnimationDuration);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
win.once('ready-to-show', () => win.show());
|
|
94
|
-
|
|
95
|
-
Logger.log(`[WindowManager] Created window #${win.id}${isMain ? ' (main)' : ''}`);
|
|
96
|
-
|
|
97
|
-
return win;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Creates the initial "splash" window that is shown immediately after
|
|
102
|
-
* app.whenReady(). It is displayed instantly (show: true, no preload
|
|
103
|
-
* loading) and then expanded to the work area with animation.
|
|
104
|
-
*
|
|
105
|
-
* After the animation completes you can call win.loadFile() without
|
|
106
|
-
* experiencing the viewbox freeze.
|
|
107
|
-
*
|
|
108
|
-
* This is the recommended way to get pixels on screen as fast as possible.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* const win = await wm.createSplash({
|
|
112
|
-
* webPreferences: { preload: path.join(__dirname, 'preload.js') }
|
|
113
|
-
* });
|
|
114
|
-
* win.loadFile('index.html');
|
|
115
|
-
*/
|
|
116
|
-
public async createSplash(
|
|
117
|
-
options: Electron.BrowserWindowConstructorOptions & {
|
|
118
|
-
animationDuration?: number;
|
|
119
|
-
expandToWorkArea?: boolean;
|
|
120
|
-
} = {},
|
|
121
|
-
): Promise<BrowserWindow> {
|
|
122
|
-
const {
|
|
123
|
-
animationDuration = 10,
|
|
124
|
-
expandToWorkArea = true,
|
|
125
|
-
...bwOptions
|
|
126
|
-
} = options;
|
|
127
|
-
|
|
128
|
-
const win = new BrowserWindow({
|
|
129
|
-
width: 600,
|
|
130
|
-
height: 600,
|
|
131
|
-
center: true,
|
|
132
|
-
show: true,
|
|
133
|
-
...bwOptions,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
this._register(win, true);
|
|
137
|
-
|
|
138
|
-
Logger.log(`[WindowManager] Splash window #${win.id} created`);
|
|
139
|
-
|
|
140
|
-
if(expandToWorkArea) {
|
|
141
|
-
await (() => new Promise((r) => setTimeout(r, 500)))();
|
|
142
|
-
await this._expandToWorkArea(win, animationDuration);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return win;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// -------------------------------------------------------------------------
|
|
149
|
-
// Accessors
|
|
150
|
-
// -------------------------------------------------------------------------
|
|
151
|
-
|
|
152
|
-
/** Returns all currently open windows. */
|
|
153
|
-
public getAll(): BrowserWindow[] {
|
|
154
|
-
return [...this._windows.values()];
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** Returns the window designated as main, or undefined. */
|
|
158
|
-
public getMain(): BrowserWindow | undefined {
|
|
159
|
-
return this._mainWindowId !== undefined
|
|
160
|
-
? this._windows.get(this._mainWindowId)
|
|
161
|
-
: undefined;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/** Returns a window by its Electron id, or undefined. */
|
|
165
|
-
public getById(id: number): BrowserWindow | undefined {
|
|
166
|
-
return this._windows.get(id);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** Returns the number of open windows. */
|
|
170
|
-
public get count(): number {
|
|
171
|
-
return this._windows.size;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// -------------------------------------------------------------------------
|
|
175
|
-
// Actions
|
|
176
|
-
// -------------------------------------------------------------------------
|
|
177
|
-
|
|
178
|
-
/** Closes and destroys a window by id. */
|
|
179
|
-
public close(id: number): void {
|
|
180
|
-
const win = this._windows.get(id);
|
|
181
|
-
if (!win) {
|
|
182
|
-
Logger.warn(`[WindowManager] Window #${id} not found`);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
win.destroy();
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** Closes all windows. */
|
|
189
|
-
public closeAll(): void {
|
|
190
|
-
for (const win of this._windows.values()) {
|
|
191
|
-
win.destroy();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Sends a message to a specific window via webContents.send.
|
|
197
|
-
* @param id Target window id.
|
|
198
|
-
* @param channel IPC channel name.
|
|
199
|
-
* @param args Payload.
|
|
200
|
-
*/
|
|
201
|
-
public send(id: number, channel: string, ...args: unknown[]): void {
|
|
202
|
-
const win = this._windows.get(id);
|
|
203
|
-
if (!win || win.isDestroyed()) {
|
|
204
|
-
Logger.warn(`[WindowManager] Cannot send to window #${id}: not found or destroyed`);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
win.webContents.send(channel, ...args);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Broadcasts a message to all open windows.
|
|
212
|
-
*/
|
|
213
|
-
public broadcast(channel: string, ...args: unknown[]): void {
|
|
214
|
-
for (const win of this._windows.values()) {
|
|
215
|
-
if (!win.isDestroyed()) {
|
|
216
|
-
win.webContents.send(channel, ...args);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// -------------------------------------------------------------------------
|
|
222
|
-
// Private
|
|
223
|
-
// -------------------------------------------------------------------------
|
|
224
|
-
|
|
225
|
-
private _register(win: BrowserWindow, isMain: boolean): void {
|
|
226
|
-
this._windows.set(win.id, win);
|
|
227
|
-
|
|
228
|
-
if (isMain && this._mainWindowId === undefined) {
|
|
229
|
-
this._mainWindowId = win.id;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
win.once('closed', () => {
|
|
233
|
-
this._windows.delete(win.id);
|
|
234
|
-
if (this._mainWindowId === win.id) {
|
|
235
|
-
this._mainWindowId = undefined;
|
|
236
|
-
}
|
|
237
|
-
Logger.log(`[WindowManager] Window #${win.id} closed`);
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Animates the window to the full work area of the primary display.
|
|
243
|
-
* Resolves only after the animation is complete, so that content loaded
|
|
244
|
-
* afterward gets the correct surface size (no viewbox freeze).
|
|
245
|
-
*/
|
|
246
|
-
private _expandToWorkArea(win: BrowserWindow, animationDuration: number): Promise<void> {
|
|
247
|
-
return new Promise((resolve) => {
|
|
248
|
-
win.maximize();
|
|
249
|
-
|
|
250
|
-
// Wait for the animation to finish before resolving.
|
|
251
|
-
// We listen to the 'resize' event which fires once the OS
|
|
252
|
-
// animation completes, with a safety timeout as fallback.
|
|
253
|
-
let resolved = false;
|
|
254
|
-
|
|
255
|
-
const done = (): void => {
|
|
256
|
-
if (resolved) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
resolved = true;
|
|
260
|
-
win.removeListener('resize', done);
|
|
261
|
-
resolve();
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
win.once('resize', done);
|
|
265
|
-
setTimeout(done, animationDuration);
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compileOnSave": false,
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"baseUrl": "./",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"target": "ES2020",
|
|
8
|
-
"module": "CommonJS",
|
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
"strict": true,
|
|
11
|
-
"noImplicitOverride": true,
|
|
12
|
-
"noImplicitReturns": true,
|
|
13
|
-
"noFallthroughCasesInSwitch": true,
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"experimentalDecorators": true,
|
|
16
|
-
"emitDecoratorMetadata": false,
|
|
17
|
-
"importHelpers": false,
|
|
18
|
-
"esModuleInterop": true,
|
|
19
|
-
"useDefineForClassFields": false,
|
|
20
|
-
"noPropertyAccessFromIndexSignature": false,
|
|
21
|
-
"noUncheckedIndexedAccess": true,
|
|
22
|
-
"skipLibCheck": true
|
|
23
|
-
},
|
|
24
|
-
"include": [
|
|
25
|
-
"src/**/*.ts",
|
|
26
|
-
"src/**/*.d.ts",
|
|
27
|
-
"node_modules/electron/electron.d.ts"
|
|
28
|
-
]
|
|
29
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { defineConfig, Options } from "tsup";
|
|
2
|
-
|
|
3
|
-
const copyrights = `
|
|
4
|
-
/**
|
|
5
|
-
* @copyright 2025 NoxFly
|
|
6
|
-
* @license MIT
|
|
7
|
-
* @author NoxFly
|
|
8
|
-
*/
|
|
9
|
-
`.trim();
|
|
10
|
-
|
|
11
|
-
const options: Options = {
|
|
12
|
-
keepNames: true,
|
|
13
|
-
minifyIdentifiers: false,
|
|
14
|
-
name: "noxus",
|
|
15
|
-
format: ["cjs", "esm"],
|
|
16
|
-
dts: true,
|
|
17
|
-
sourcemap: true,
|
|
18
|
-
clean: false, // ← false dans le base config
|
|
19
|
-
outDir: "dist",
|
|
20
|
-
external: ["electron"],
|
|
21
|
-
target: "es2020",
|
|
22
|
-
minify: false,
|
|
23
|
-
splitting: false,
|
|
24
|
-
shims: false,
|
|
25
|
-
treeshake: false,
|
|
26
|
-
banner: { js: copyrights },
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default defineConfig([
|
|
30
|
-
{
|
|
31
|
-
entry: { main: 'src/main.ts' },
|
|
32
|
-
external: ['electron', 'electron/main'],
|
|
33
|
-
clean: true, // ← true uniquement ici
|
|
34
|
-
...options,
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
entry: { renderer: 'src/renderer.ts' },
|
|
38
|
-
external: ['electron', 'electron/renderer'],
|
|
39
|
-
...options,
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
entry: { preload: 'src/preload.ts' },
|
|
43
|
-
external: ['electron', 'electron/renderer'],
|
|
44
|
-
...options,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
entry: { child: 'src/non-electron-process.ts' },
|
|
48
|
-
...options,
|
|
49
|
-
},
|
|
50
|
-
]);
|