@devisfuture/electron-modular 1.2.17 → 1.2.19
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 +29 -3
- package/dist/index.d.ts +213 -28
- package/dist/index.js +2 -28
- package/package.json +7 -3
- package/dist/@core/bootstrap/bootstrap.d.ts +0 -2
- package/dist/@core/bootstrap/bootstrap.js +0 -41
- package/dist/@core/bootstrap/initialize-ipc/handlers.d.ts +0 -3
- package/dist/@core/bootstrap/initialize-ipc/handlers.js +0 -47
- package/dist/@core/bootstrap/initialize-ipc/window-creator.d.ts +0 -3
- package/dist/@core/bootstrap/initialize-ipc/window-creator.js +0 -28
- package/dist/@core/bootstrap/initialize-ipc/window-event-listeners.d.ts +0 -3
- package/dist/@core/bootstrap/initialize-ipc/window-event-listeners.js +0 -61
- package/dist/@core/bootstrap/initialize-ipc/window-instance-creator.d.ts +0 -3
- package/dist/@core/bootstrap/initialize-ipc/window-instance-creator.js +0 -10
- package/dist/@core/bootstrap/initialize-module.d.ts +0 -3
- package/dist/@core/bootstrap/initialize-module.js +0 -20
- package/dist/@core/bootstrap/instantiate-module.d.ts +0 -2
- package/dist/@core/bootstrap/instantiate-module.js +0 -9
- package/dist/@core/bootstrap/register-imports.d.ts +0 -3
- package/dist/@core/bootstrap/register-imports.js +0 -16
- package/dist/@core/bootstrap/register-ipc-handlers.d.ts +0 -3
- package/dist/@core/bootstrap/register-ipc-handlers.js +0 -9
- package/dist/@core/bootstrap/register-lazy-module.d.ts +0 -3
- package/dist/@core/bootstrap/register-lazy-module.js +0 -48
- package/dist/@core/bootstrap/register-providers.d.ts +0 -3
- package/dist/@core/bootstrap/register-providers.js +0 -21
- package/dist/@core/bootstrap/register-windows.d.ts +0 -3
- package/dist/@core/bootstrap/register-windows.js +0 -15
- package/dist/@core/bootstrap/settings.d.ts +0 -11
- package/dist/@core/bootstrap/settings.js +0 -13
- package/dist/@core/bootstrap/validate-lazy-constraints.d.ts +0 -3
- package/dist/@core/bootstrap/validate-lazy-constraints.js +0 -18
- package/dist/@core/container.d.ts +0 -26
- package/dist/@core/container.js +0 -154
- package/dist/@core/control-window/cache.d.ts +0 -1
- package/dist/@core/control-window/cache.js +0 -1
- package/dist/@core/control-window/create.d.ts +0 -3
- package/dist/@core/control-window/create.js +0 -62
- package/dist/@core/control-window/destroy.d.ts +0 -1
- package/dist/@core/control-window/destroy.js +0 -9
- package/dist/@core/control-window/receive.d.ts +0 -2
- package/dist/@core/control-window/receive.js +0 -8
- package/dist/@core/control-window/types.d.ts +0 -14
- package/dist/@core/control-window/types.js +0 -1
- package/dist/@core/decorators/inject.d.ts +0 -6
- package/dist/@core/decorators/inject.js +0 -15
- package/dist/@core/decorators/injectable.d.ts +0 -2
- package/dist/@core/decorators/injectable.js +0 -6
- package/dist/@core/decorators/ipc-handler.d.ts +0 -2
- package/dist/@core/decorators/ipc-handler.js +0 -6
- package/dist/@core/decorators/rg-module.d.ts +0 -3
- package/dist/@core/decorators/rg-module.js +0 -6
- package/dist/@core/decorators/window-manager.d.ts +0 -3
- package/dist/@core/decorators/window-manager.js +0 -6
- package/dist/@core/errors/index.d.ts +0 -34
- package/dist/@core/errors/index.js +0 -56
- package/dist/@core/types/constructor.d.ts +0 -1
- package/dist/@core/types/constructor.js +0 -1
- package/dist/@core/types/index.d.ts +0 -8
- package/dist/@core/types/index.js +0 -1
- package/dist/@core/types/ipc-handler.d.ts +0 -7
- package/dist/@core/types/ipc-handler.js +0 -1
- package/dist/@core/types/lazy.d.ts +0 -11
- package/dist/@core/types/lazy.js +0 -1
- package/dist/@core/types/module-metadata.d.ts +0 -12
- package/dist/@core/types/module-metadata.js +0 -1
- package/dist/@core/types/provider.d.ts +0 -21
- package/dist/@core/types/provider.js +0 -1
- package/dist/@core/types/window-factory.d.ts +0 -6
- package/dist/@core/types/window-factory.js +0 -1
- package/dist/@core/types/window-manager.d.ts +0 -10
- package/dist/@core/types/window-manager.js +0 -1
- package/dist/@core/types/window-metadata.d.ts +0 -6
- package/dist/@core/types/window-metadata.js +0 -1
- package/dist/@core/utils/dependency-tokens.d.ts +0 -4
- package/dist/@core/utils/dependency-tokens.js +0 -23
- package/dist/config.d.ts +0 -4
- package/dist/config.js +0 -4
- package/dist/reflect-metadata.d.ts +0 -11
- package/dist/reflect-metadata.js +0 -66
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { EagerModuleCannotImportLazyModuleError } from "../errors/index.js";
|
|
2
|
-
import { initializeModule } from "./initialize-module.js";
|
|
3
|
-
export const registerImports = async (moduleClass, metadata) => {
|
|
4
|
-
if (!metadata.imports) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
for (const importedModuleClass of metadata.imports) {
|
|
8
|
-
const importedModuleMetadata = Reflect.getMetadata("RgModule", importedModuleClass);
|
|
9
|
-
if (importedModuleMetadata?.lazy?.enabled && !metadata.lazy?.enabled) {
|
|
10
|
-
throw new EagerModuleCannotImportLazyModuleError(moduleClass.name, importedModuleClass.name);
|
|
11
|
-
}
|
|
12
|
-
if (importedModuleMetadata) {
|
|
13
|
-
await initializeModule(importedModuleClass, importedModuleMetadata);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ipcMain } from "electron";
|
|
2
|
-
import { initializeModule } from "./initialize-module.js";
|
|
3
|
-
import { instantiateModule } from "./instantiate-module.js";
|
|
4
|
-
import { container } from "../container.js";
|
|
5
|
-
import { initializeIpcHandlers } from "./initialize-ipc/handlers.js";
|
|
6
|
-
import { InvalidLazyTriggerError } from "../errors/index.js";
|
|
7
|
-
const getValidLazyTrigger = (moduleClass, metadata) => {
|
|
8
|
-
const trigger = metadata.lazy?.trigger;
|
|
9
|
-
if (typeof trigger !== "string" || trigger.trim().length === 0) {
|
|
10
|
-
throw new InvalidLazyTriggerError(moduleClass.name);
|
|
11
|
-
}
|
|
12
|
-
return trigger.trim();
|
|
13
|
-
};
|
|
14
|
-
export const registerLazyModule = (moduleClass, metadata) => {
|
|
15
|
-
const trigger = getValidLazyTrigger(moduleClass, metadata);
|
|
16
|
-
let initPromise = null;
|
|
17
|
-
ipcMain.handle(trigger, async () => {
|
|
18
|
-
if (initPromise) {
|
|
19
|
-
return initPromise;
|
|
20
|
-
}
|
|
21
|
-
initPromise = (async () => {
|
|
22
|
-
try {
|
|
23
|
-
await initializeModule(moduleClass, metadata);
|
|
24
|
-
await instantiateModule(moduleClass);
|
|
25
|
-
await container.resolve(moduleClass, moduleClass);
|
|
26
|
-
if (metadata.windows?.length && !metadata.ipc?.length) {
|
|
27
|
-
console.warn(`Warning: Window(s) declared in module "${moduleClass.name}" but no IPC handlers found to manage them.`);
|
|
28
|
-
}
|
|
29
|
-
await initializeIpcHandlers(moduleClass, metadata);
|
|
30
|
-
return {
|
|
31
|
-
initialized: true,
|
|
32
|
-
name: trigger,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
initPromise = null;
|
|
37
|
-
return {
|
|
38
|
-
initialized: false,
|
|
39
|
-
name: trigger,
|
|
40
|
-
error: {
|
|
41
|
-
message: error instanceof Error ? error.message : String(error),
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
})();
|
|
46
|
-
return initPromise;
|
|
47
|
-
});
|
|
48
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { InvalidProviderError } from "../errors/index.js";
|
|
2
|
-
import { container } from "../container.js";
|
|
3
|
-
const isProviderObject = (provider) => {
|
|
4
|
-
return (typeof provider === "object" && provider !== null && "provide" in provider);
|
|
5
|
-
};
|
|
6
|
-
export const registerProviders = async (moduleClass, metadata) => {
|
|
7
|
-
if (!metadata.providers) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
for (const provider of metadata.providers) {
|
|
11
|
-
if (typeof provider === "function") {
|
|
12
|
-
container.addProvider(moduleClass, provider);
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
if (isProviderObject(provider)) {
|
|
16
|
-
container.addProvider(moduleClass, provider.provide, provider);
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
throw new InvalidProviderError(moduleClass.name);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { container } from "../container.js";
|
|
2
|
-
export const registerWindows = async (moduleClass, metadata) => {
|
|
3
|
-
if (!metadata.windows) {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
for (const windowClass of metadata.windows) {
|
|
7
|
-
const windowMetadataValue = Reflect.getMetadata("WindowManager", windowClass);
|
|
8
|
-
if (windowMetadataValue?.hash) {
|
|
9
|
-
container.addProvider(moduleClass, windowMetadataValue.hash, {
|
|
10
|
-
metadata: windowMetadataValue,
|
|
11
|
-
windowClass,
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type TFolderSettings = {
|
|
2
|
-
distRenderer: string;
|
|
3
|
-
distMain: string;
|
|
4
|
-
};
|
|
5
|
-
export type TSettings = {
|
|
6
|
-
cspConnectSources?: string[];
|
|
7
|
-
localhostPort: string;
|
|
8
|
-
folders: TFolderSettings;
|
|
9
|
-
};
|
|
10
|
-
export declare const initSettings: (options: TSettings) => void;
|
|
11
|
-
export declare const getSettings: () => TSettings;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SettingsNotInitializedError } from "../errors/index.js";
|
|
2
|
-
const KEY = "settings";
|
|
3
|
-
const settings = new Map();
|
|
4
|
-
export const initSettings = (options) => {
|
|
5
|
-
settings.set(KEY, options);
|
|
6
|
-
};
|
|
7
|
-
export const getSettings = () => {
|
|
8
|
-
const cachedSettings = settings.get(KEY);
|
|
9
|
-
if (!cachedSettings) {
|
|
10
|
-
throw new SettingsNotInitializedError();
|
|
11
|
-
}
|
|
12
|
-
return cachedSettings;
|
|
13
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { LazyModuleCannotImportLazyModuleError, LazyModuleExportsNotAllowedError, } from "../errors/index.js";
|
|
2
|
-
export const validateLazyConstraints = (moduleClass, metadata) => {
|
|
3
|
-
if (!metadata.lazy?.enabled) {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
if ((metadata.exports?.length ?? 0) > 0) {
|
|
7
|
-
throw new LazyModuleExportsNotAllowedError(moduleClass.name);
|
|
8
|
-
}
|
|
9
|
-
if (!metadata.imports?.length) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
for (const importedModuleClass of metadata.imports) {
|
|
13
|
-
const importedModuleMetadata = Reflect.getMetadata("RgModule", importedModuleClass);
|
|
14
|
-
if (importedModuleMetadata?.lazy?.enabled) {
|
|
15
|
-
throw new LazyModuleCannotImportLazyModuleError(moduleClass.name, importedModuleClass.name);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Constructor } from "./types/constructor.js";
|
|
2
|
-
import type { RgModuleMetadata } from "./types/module-metadata.js";
|
|
3
|
-
import type { TProviderToken } from "./types/provider.js";
|
|
4
|
-
export declare class Container {
|
|
5
|
-
private readonly modules;
|
|
6
|
-
private readonly moduleMetadata;
|
|
7
|
-
private readonly instances;
|
|
8
|
-
private readonly resolutionCache;
|
|
9
|
-
addModule(moduleClass: Constructor, metadata: Pick<RgModuleMetadata, "exports" | "providers">): boolean;
|
|
10
|
-
setModuleMetadata(moduleClass: Constructor, metadata: RgModuleMetadata): void;
|
|
11
|
-
hasModule(moduleClass: Constructor): boolean;
|
|
12
|
-
private getCacheKey;
|
|
13
|
-
addProvider(moduleClass: Constructor, provider: TProviderToken, instance?: unknown): void;
|
|
14
|
-
getProvider<T = unknown>(moduleClass: Constructor, token: TProviderToken): T | undefined;
|
|
15
|
-
getModuleExports(moduleClass: Constructor): Set<TProviderToken>;
|
|
16
|
-
getModuleMetadata(moduleClass: Constructor): RgModuleMetadata | undefined;
|
|
17
|
-
registerInstance(token: TProviderToken, instance: unknown): void;
|
|
18
|
-
resolve<T>(moduleClass: Constructor, token: TProviderToken): Promise<T | undefined>;
|
|
19
|
-
private resolveFromImports;
|
|
20
|
-
private instantiateProvider;
|
|
21
|
-
private instantiateFactoryProvider;
|
|
22
|
-
private instantiateClassProvider;
|
|
23
|
-
private instantiateClassConstructor;
|
|
24
|
-
private resolveDependencies;
|
|
25
|
-
}
|
|
26
|
-
export declare const container: Container;
|
package/dist/@core/container.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { getDependencyTokens } from "./utils/dependency-tokens.js";
|
|
2
|
-
import { ModuleNotRegisteredError, ProviderNotFoundError, } from "./errors/index.js";
|
|
3
|
-
export class Container {
|
|
4
|
-
modules = new Map();
|
|
5
|
-
moduleMetadata = new Map();
|
|
6
|
-
instances = new Map();
|
|
7
|
-
resolutionCache = new Map();
|
|
8
|
-
addModule(moduleClass, metadata) {
|
|
9
|
-
if (this.modules.has(moduleClass)) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
this.modules.set(moduleClass, {
|
|
13
|
-
providers: new Map(),
|
|
14
|
-
exports: new Set(metadata.exports ?? []),
|
|
15
|
-
});
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
setModuleMetadata(moduleClass, metadata) {
|
|
19
|
-
this.moduleMetadata.set(moduleClass, metadata);
|
|
20
|
-
}
|
|
21
|
-
hasModule(moduleClass) {
|
|
22
|
-
return this.modules.has(moduleClass);
|
|
23
|
-
}
|
|
24
|
-
getCacheKey(moduleClass, token) {
|
|
25
|
-
const tokenKey = typeof token === "string" || typeof token === "symbol"
|
|
26
|
-
? String(token)
|
|
27
|
-
: token.name;
|
|
28
|
-
return `${moduleClass.name}:${tokenKey}`;
|
|
29
|
-
}
|
|
30
|
-
addProvider(moduleClass, provider, instance) {
|
|
31
|
-
const moduleData = this.modules.get(moduleClass);
|
|
32
|
-
if (!moduleData) {
|
|
33
|
-
throw new ModuleNotRegisteredError(moduleClass.name);
|
|
34
|
-
}
|
|
35
|
-
moduleData.providers.set(provider, instance ?? provider);
|
|
36
|
-
}
|
|
37
|
-
getProvider(moduleClass, token) {
|
|
38
|
-
const moduleData = this.modules.get(moduleClass);
|
|
39
|
-
if (!moduleData) {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
return moduleData.providers.get(token);
|
|
43
|
-
}
|
|
44
|
-
getModuleExports(moduleClass) {
|
|
45
|
-
const moduleData = this.modules.get(moduleClass);
|
|
46
|
-
return moduleData?.exports ?? new Set();
|
|
47
|
-
}
|
|
48
|
-
getModuleMetadata(moduleClass) {
|
|
49
|
-
return this.moduleMetadata.get(moduleClass);
|
|
50
|
-
}
|
|
51
|
-
registerInstance(token, instance) {
|
|
52
|
-
this.instances.set(token, instance);
|
|
53
|
-
}
|
|
54
|
-
async resolve(moduleClass, token) {
|
|
55
|
-
const cacheKey = this.getCacheKey(moduleClass, token);
|
|
56
|
-
if (this.resolutionCache.has(cacheKey)) {
|
|
57
|
-
return this.resolutionCache.get(cacheKey);
|
|
58
|
-
}
|
|
59
|
-
if (this.instances.has(token)) {
|
|
60
|
-
const instance = this.instances.get(token);
|
|
61
|
-
this.resolutionCache.set(cacheKey, instance);
|
|
62
|
-
return instance;
|
|
63
|
-
}
|
|
64
|
-
const provider = this.getProvider(moduleClass, token);
|
|
65
|
-
if (!provider) {
|
|
66
|
-
const resolvedFromImports = await this.resolveFromImports(moduleClass, token);
|
|
67
|
-
if (resolvedFromImports !== undefined) {
|
|
68
|
-
this.resolutionCache.set(cacheKey, resolvedFromImports);
|
|
69
|
-
return resolvedFromImports;
|
|
70
|
-
}
|
|
71
|
-
if (token !== moduleClass) {
|
|
72
|
-
throw new ProviderNotFoundError(String(token), moduleClass.name);
|
|
73
|
-
}
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
const instance = await this.instantiateProvider(moduleClass, token, provider);
|
|
77
|
-
if (instance !== undefined) {
|
|
78
|
-
this.resolutionCache.set(cacheKey, instance);
|
|
79
|
-
}
|
|
80
|
-
return instance;
|
|
81
|
-
}
|
|
82
|
-
async resolveFromImports(moduleClass, token) {
|
|
83
|
-
const moduleMetadata = this.getModuleMetadata(moduleClass);
|
|
84
|
-
if (!moduleMetadata?.imports) {
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
for (const importedModuleClass of moduleMetadata.imports) {
|
|
88
|
-
const exportedProviders = this.getModuleExports(importedModuleClass);
|
|
89
|
-
if (exportedProviders.has(token)) {
|
|
90
|
-
const exportedProvider = this.getProvider(importedModuleClass, token);
|
|
91
|
-
if (exportedProvider !== undefined) {
|
|
92
|
-
return this.resolve(importedModuleClass, token);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
async instantiateProvider(moduleClass, token, provider) {
|
|
99
|
-
const isObj = typeof provider === "object" &&
|
|
100
|
-
provider !== null &&
|
|
101
|
-
"provide" in provider;
|
|
102
|
-
if (isObj &&
|
|
103
|
-
"useFactory" in provider &&
|
|
104
|
-
typeof provider.useFactory === "function") {
|
|
105
|
-
return this.instantiateFactoryProvider(moduleClass, token, provider);
|
|
106
|
-
}
|
|
107
|
-
if (isObj &&
|
|
108
|
-
"useClass" in provider &&
|
|
109
|
-
typeof provider.useClass === "function") {
|
|
110
|
-
return this.instantiateClassProvider(moduleClass, token, provider);
|
|
111
|
-
}
|
|
112
|
-
if (isObj && "useValue" in provider) {
|
|
113
|
-
const val = provider.useValue;
|
|
114
|
-
this.instances.set(token, val);
|
|
115
|
-
return val;
|
|
116
|
-
}
|
|
117
|
-
if (isObj && "useExisting" in provider) {
|
|
118
|
-
const instance = await this.resolve(moduleClass, provider.useExisting);
|
|
119
|
-
if (instance !== undefined) {
|
|
120
|
-
this.instances.set(token, instance);
|
|
121
|
-
}
|
|
122
|
-
return instance;
|
|
123
|
-
}
|
|
124
|
-
if (typeof provider === "function") {
|
|
125
|
-
return this.instantiateClassConstructor(moduleClass, token, provider);
|
|
126
|
-
}
|
|
127
|
-
return provider;
|
|
128
|
-
}
|
|
129
|
-
async instantiateFactoryProvider(moduleClass, token, provider) {
|
|
130
|
-
const dependencies = provider.inject ?? [];
|
|
131
|
-
const resolvedDependencies = await this.resolveDependencies(moduleClass, dependencies);
|
|
132
|
-
const instance = provider.useFactory(...resolvedDependencies);
|
|
133
|
-
this.instances.set(token, instance);
|
|
134
|
-
return instance;
|
|
135
|
-
}
|
|
136
|
-
async instantiateClassProvider(moduleClass, token, provider) {
|
|
137
|
-
const dependencies = provider.inject ?? getDependencyTokens(provider.useClass);
|
|
138
|
-
const resolvedDependencies = await this.resolveDependencies(moduleClass, dependencies);
|
|
139
|
-
const instance = new provider.useClass(...resolvedDependencies);
|
|
140
|
-
this.instances.set(token, instance);
|
|
141
|
-
return instance;
|
|
142
|
-
}
|
|
143
|
-
async instantiateClassConstructor(moduleClass, token, providerClass) {
|
|
144
|
-
const dependencies = getDependencyTokens(providerClass);
|
|
145
|
-
const resolvedDependencies = await this.resolveDependencies(moduleClass, dependencies);
|
|
146
|
-
const instance = new providerClass(...resolvedDependencies);
|
|
147
|
-
this.instances.set(token, instance);
|
|
148
|
-
return instance;
|
|
149
|
-
}
|
|
150
|
-
async resolveDependencies(moduleClass, dependencies) {
|
|
151
|
-
return Promise.all(dependencies.map((dep) => this.resolve(moduleClass, dep)));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
export const container = new Container();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const cacheWindows: Map<string, Electron.CrossProcessExports.BrowserWindow>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const cacheWindows = new Map();
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { BrowserWindow, session, app } from "electron";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { cacheWindows } from "./cache.js";
|
|
4
|
-
import { getWindow } from "./receive.js";
|
|
5
|
-
import { getSettings } from "../bootstrap/settings.js";
|
|
6
|
-
const setupCSP = (sources, dev) => {
|
|
7
|
-
const connectSrc = sources.length > 0 ? ` ${sources.join(" ")}` : "";
|
|
8
|
-
const csp = `default-src 'self'; connect-src 'self'${connectSrc}; img-src * data:; style-src 'self' 'unsafe-inline'; script-src 'self' ${dev ? "'unsafe-inline'" : ""};`
|
|
9
|
-
.replace(/\s{2,}/g, " ")
|
|
10
|
-
.trim();
|
|
11
|
-
session.defaultSession.webRequest.onHeadersReceived((d, cb) => {
|
|
12
|
-
cb({
|
|
13
|
-
responseHeaders: {
|
|
14
|
-
...d.responseHeaders,
|
|
15
|
-
"Content-Security-Policy": [csp],
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
export const createWindow = ({ hash, options, isCache, loadURL, }) => {
|
|
21
|
-
const settings = getSettings();
|
|
22
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
23
|
-
const ui = path.join(app.getAppPath(), `/${settings.folders.distRenderer}/index.html`);
|
|
24
|
-
const preload = path.join(app.getAppPath(), isDev ? "." : "..", `/${settings.folders.distMain}/preload.cjs`);
|
|
25
|
-
if (!settings.localhostPort)
|
|
26
|
-
console.warn('Warning: You have to add an environment variable for example called "process.env.LOCALHOST_ELECTRON_SERVER_PORT"!');
|
|
27
|
-
if (hash && isCache) {
|
|
28
|
-
const existing = getWindow(hash);
|
|
29
|
-
if (existing) {
|
|
30
|
-
existing.show();
|
|
31
|
-
return existing;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const win = new BrowserWindow({
|
|
35
|
-
...options,
|
|
36
|
-
webPreferences: {
|
|
37
|
-
preload,
|
|
38
|
-
contextIsolation: true,
|
|
39
|
-
nodeIntegration: false,
|
|
40
|
-
...options?.webPreferences,
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
if (isCache && !loadURL && settings.cspConnectSources)
|
|
44
|
-
setupCSP(settings.cspConnectSources, isDev);
|
|
45
|
-
if (loadURL) {
|
|
46
|
-
win.loadURL(loadURL);
|
|
47
|
-
}
|
|
48
|
-
else if (isDev) {
|
|
49
|
-
win.loadURL(`http://localhost:${settings.localhostPort}${hash ? `#${hash}` : ""}`);
|
|
50
|
-
}
|
|
51
|
-
else if (hash) {
|
|
52
|
-
win.loadFile(ui, { hash });
|
|
53
|
-
}
|
|
54
|
-
if (hash && isCache) {
|
|
55
|
-
cacheWindows.set(hash, win);
|
|
56
|
-
win.on("close", (e) => {
|
|
57
|
-
e.preventDefault();
|
|
58
|
-
win.hide();
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return win;
|
|
62
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const destroyWindows: () => void;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { BrowserWindow, type BrowserWindowConstructorOptions } from "electron";
|
|
2
|
-
export type TParamsRoute = {
|
|
3
|
-
[key: string]: string;
|
|
4
|
-
};
|
|
5
|
-
export type TParamsCreateWindow<N = string> = {
|
|
6
|
-
hash?: N;
|
|
7
|
-
isCache?: boolean;
|
|
8
|
-
paramsRoute?: TParamsRoute;
|
|
9
|
-
options?: BrowserWindowConstructorOptions;
|
|
10
|
-
loadURL?: string;
|
|
11
|
-
};
|
|
12
|
-
export type TCache = {
|
|
13
|
-
[key in string]: BrowserWindow;
|
|
14
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { BrowserWindow } from "electron";
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import "../../reflect-metadata.js";
|
|
2
|
-
import type { TProviderToken } from "../types/provider.js";
|
|
3
|
-
type TInjectTokensMetadata = Record<number, TProviderToken>;
|
|
4
|
-
export declare const Inject: (token: TProviderToken) => ParameterDecorator;
|
|
5
|
-
export declare const getInjectedTokens: (target: Function) => TInjectTokensMetadata;
|
|
6
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import "../../reflect-metadata.js";
|
|
2
|
-
const INJECT_TOKENS_METADATA_KEY = "RgInjectTokens";
|
|
3
|
-
export const Inject = (token) => {
|
|
4
|
-
return (target, propertyKey, parameterIndex) => {
|
|
5
|
-
if (propertyKey !== undefined) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const existingTokens = Reflect.getMetadata(INJECT_TOKENS_METADATA_KEY, target) ?? {};
|
|
9
|
-
existingTokens[parameterIndex] = token;
|
|
10
|
-
Reflect.defineMetadata(INJECT_TOKENS_METADATA_KEY, existingTokens, target);
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export const getInjectedTokens = (target) => {
|
|
14
|
-
return (Reflect.getMetadata(INJECT_TOKENS_METADATA_KEY, target) ?? {});
|
|
15
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
declare class BaseError extends Error {
|
|
2
|
-
constructor(msg: string, name: string);
|
|
3
|
-
}
|
|
4
|
-
export declare class ModuleNotRegisteredError extends BaseError {
|
|
5
|
-
constructor(m: string);
|
|
6
|
-
}
|
|
7
|
-
export declare class ProviderNotFoundError extends BaseError {
|
|
8
|
-
constructor(t: string, m: string);
|
|
9
|
-
}
|
|
10
|
-
export declare class ModuleDecoratorMissingError extends BaseError {
|
|
11
|
-
constructor(m: string);
|
|
12
|
-
}
|
|
13
|
-
export declare class InvalidProviderError extends BaseError {
|
|
14
|
-
constructor(m: string);
|
|
15
|
-
}
|
|
16
|
-
export declare class SettingsNotInitializedError extends BaseError {
|
|
17
|
-
constructor();
|
|
18
|
-
}
|
|
19
|
-
export declare class InvalidLazyTriggerError extends BaseError {
|
|
20
|
-
constructor(moduleName: string);
|
|
21
|
-
}
|
|
22
|
-
export declare class DuplicateLazyTriggerError extends BaseError {
|
|
23
|
-
constructor(trigger: string, firstModule: string, secondModule: string);
|
|
24
|
-
}
|
|
25
|
-
export declare class LazyModuleExportsNotAllowedError extends BaseError {
|
|
26
|
-
constructor(moduleName: string);
|
|
27
|
-
}
|
|
28
|
-
export declare class LazyModuleCannotImportLazyModuleError extends BaseError {
|
|
29
|
-
constructor(moduleName: string, importedModuleName: string);
|
|
30
|
-
}
|
|
31
|
-
export declare class EagerModuleCannotImportLazyModuleError extends BaseError {
|
|
32
|
-
constructor(moduleName: string, importedModuleName: string);
|
|
33
|
-
}
|
|
34
|
-
export {};
|