@noxfly/noxus 3.0.0-dev.0 → 3.0.0-dev.10

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.
Files changed (59) hide show
  1. package/README.md +132 -16
  2. package/dist/child.d.mts +118 -4
  3. package/dist/child.d.ts +118 -4
  4. package/dist/child.js +402 -859
  5. package/dist/child.js.map +1 -0
  6. package/dist/child.mjs +389 -847
  7. package/dist/child.mjs.map +1 -0
  8. package/dist/main.d.mts +517 -25
  9. package/dist/main.d.ts +517 -25
  10. package/dist/main.js +1088 -988
  11. package/dist/main.js.map +1 -0
  12. package/dist/main.mjs +983 -884
  13. package/dist/main.mjs.map +1 -0
  14. package/dist/preload.d.mts +28 -0
  15. package/dist/preload.d.ts +28 -0
  16. package/dist/preload.js +95 -0
  17. package/dist/preload.js.map +1 -0
  18. package/dist/preload.mjs +70 -0
  19. package/dist/preload.mjs.map +1 -0
  20. package/dist/renderer.d.mts +186 -23
  21. package/dist/renderer.d.ts +186 -23
  22. package/dist/renderer.js +170 -170
  23. package/dist/renderer.js.map +1 -0
  24. package/dist/renderer.mjs +159 -157
  25. package/dist/renderer.mjs.map +1 -0
  26. package/package.json +35 -21
  27. package/.editorconfig +0 -16
  28. package/.github/copilot-instructions.md +0 -32
  29. package/.vscode/settings.json +0 -3
  30. package/eslint.config.js +0 -109
  31. package/scripts/postbuild.js +0 -31
  32. package/src/DI/app-injector.ts +0 -151
  33. package/src/DI/injector-explorer.ts +0 -143
  34. package/src/DI/token.ts +0 -53
  35. package/src/app.ts +0 -217
  36. package/src/bootstrap.ts +0 -108
  37. package/src/decorators/controller.decorator.ts +0 -58
  38. package/src/decorators/guards.decorator.ts +0 -15
  39. package/src/decorators/injectable.decorator.ts +0 -81
  40. package/src/decorators/method.decorator.ts +0 -66
  41. package/src/decorators/middleware.decorator.ts +0 -15
  42. package/src/exceptions.ts +0 -57
  43. package/src/index.ts +0 -13
  44. package/src/main.ts +0 -26
  45. package/src/non-electron-process.ts +0 -22
  46. package/src/preload-bridge.ts +0 -75
  47. package/src/renderer-client.ts +0 -338
  48. package/src/renderer-events.ts +0 -110
  49. package/src/request.ts +0 -97
  50. package/src/router.ts +0 -353
  51. package/src/routes.ts +0 -78
  52. package/src/socket.ts +0 -73
  53. package/src/utils/forward-ref.ts +0 -31
  54. package/src/utils/logger.ts +0 -430
  55. package/src/utils/radix-tree.ts +0 -210
  56. package/src/utils/types.ts +0 -21
  57. package/src/window/window-manager.ts +0 -255
  58. package/tsconfig.json +0 -29
  59. package/tsup.config.ts +0 -34
@@ -1,255 +0,0 @@
1
- /**
2
- * @copyright 2025 NoxFly
3
- * @license MIT
4
- * @author NoxFly
5
- */
6
-
7
- import { BrowserWindow, screen } 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 & { animationDuration?: number } = {},
118
- ): Promise<BrowserWindow> {
119
- const { animationDuration = 600, ...bwOptions } = options;
120
-
121
- const win = new BrowserWindow({
122
- width: 600,
123
- height: 600,
124
- center: true,
125
- frame: false,
126
- show: true,
127
- ...bwOptions,
128
- });
129
-
130
- this._register(win, true);
131
-
132
- Logger.log(`[WindowManager] Splash window #${win.id} created`);
133
-
134
- await this._expandToWorkArea(win, animationDuration);
135
-
136
- return win;
137
- }
138
-
139
- // -------------------------------------------------------------------------
140
- // Accessors
141
- // -------------------------------------------------------------------------
142
-
143
- /** Returns all currently open windows. */
144
- public getAll(): BrowserWindow[] {
145
- return [...this._windows.values()];
146
- }
147
-
148
- /** Returns the window designated as main, or undefined. */
149
- public getMain(): BrowserWindow | undefined {
150
- return this._mainWindowId !== undefined
151
- ? this._windows.get(this._mainWindowId)
152
- : undefined;
153
- }
154
-
155
- /** Returns a window by its Electron id, or undefined. */
156
- public getById(id: number): BrowserWindow | undefined {
157
- return this._windows.get(id);
158
- }
159
-
160
- /** Returns the number of open windows. */
161
- public get count(): number {
162
- return this._windows.size;
163
- }
164
-
165
- // -------------------------------------------------------------------------
166
- // Actions
167
- // -------------------------------------------------------------------------
168
-
169
- /** Closes and destroys a window by id. */
170
- public close(id: number): void {
171
- const win = this._windows.get(id);
172
- if (!win) {
173
- Logger.warn(`[WindowManager] Window #${id} not found`);
174
- return;
175
- }
176
- win.destroy();
177
- }
178
-
179
- /** Closes all windows. */
180
- public closeAll(): void {
181
- for (const win of this._windows.values()) {
182
- win.destroy();
183
- }
184
- }
185
-
186
- /**
187
- * Sends a message to a specific window via webContents.send.
188
- * @param id Target window id.
189
- * @param channel IPC channel name.
190
- * @param args Payload.
191
- */
192
- public send(id: number, channel: string, ...args: unknown[]): void {
193
- const win = this._windows.get(id);
194
- if (!win || win.isDestroyed()) {
195
- Logger.warn(`[WindowManager] Cannot send to window #${id}: not found or destroyed`);
196
- return;
197
- }
198
- win.webContents.send(channel, ...args);
199
- }
200
-
201
- /**
202
- * Broadcasts a message to all open windows.
203
- */
204
- public broadcast(channel: string, ...args: unknown[]): void {
205
- for (const win of this._windows.values()) {
206
- if (!win.isDestroyed()) win.webContents.send(channel, ...args);
207
- }
208
- }
209
-
210
- // -------------------------------------------------------------------------
211
- // Private
212
- // -------------------------------------------------------------------------
213
-
214
- private _register(win: BrowserWindow, isMain: boolean): void {
215
- this._windows.set(win.id, win);
216
-
217
- if (isMain && this._mainWindowId === undefined) {
218
- this._mainWindowId = win.id;
219
- }
220
-
221
- win.once('closed', () => {
222
- this._windows.delete(win.id);
223
- if (this._mainWindowId === win.id) this._mainWindowId = undefined;
224
- Logger.log(`[WindowManager] Window #${win.id} closed`);
225
- });
226
- }
227
-
228
- /**
229
- * Animates the window to the full work area of the primary display.
230
- * Resolves only after the animation is complete, so that content loaded
231
- * afterward gets the correct surface size (no viewbox freeze).
232
- */
233
- private _expandToWorkArea(win: BrowserWindow, animationDuration: number): Promise<void> {
234
- return new Promise((resolve) => {
235
- const { x, y, width, height } = screen.getPrimaryDisplay().workArea;
236
-
237
- win.setBounds({ x, y, width, height }, true);
238
-
239
- // Wait for the animation to finish before resolving.
240
- // We listen to the 'resize' event which fires once the OS
241
- // animation completes, with a safety timeout as fallback.
242
- let resolved = false;
243
-
244
- const done = (): void => {
245
- if (resolved) return;
246
- resolved = true;
247
- win.removeListener('resize', done);
248
- resolve();
249
- };
250
-
251
- win.once('resize', done);
252
- setTimeout(done, animationDuration + 100); // safety fallback
253
- });
254
- }
255
- }
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,34 +0,0 @@
1
- import { defineConfig } from "tsup";
2
-
3
- const copyrights = `
4
- /**
5
- * @copyright 2025 NoxFly
6
- * @license MIT
7
- * @author NoxFly
8
- */
9
- `.trim();
10
-
11
- export default defineConfig({
12
- entry: {
13
- renderer: "src/index.ts",
14
- main: "src/main.ts",
15
- child: "src/non-electron-process.ts",
16
- },
17
- keepNames: true,
18
- minifyIdentifiers: false,
19
- name: "noxus",
20
- format: ["cjs", "esm"],
21
- dts: true,
22
- sourcemap: true,
23
- clean: true,
24
- outDir: "dist",
25
- external: ["electron"],
26
- target: "es2020",
27
- minify: false,
28
- splitting: false,
29
- shims: false,
30
- treeshake: false,
31
- banner: {
32
- js: copyrights,
33
- },
34
- });