@noxfly/noxus 1.1.9 → 1.2.0
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/.vscode/settings.json +3 -0
- package/README.md +69 -9
- package/dist/index-5OkVPHfI.d.mts +268 -0
- package/dist/index-5OkVPHfI.d.ts +268 -0
- package/dist/{noxus.d.mts → main.d.mts} +21 -209
- package/dist/{noxus.d.ts → main.d.ts} +21 -209
- package/dist/{noxus.js → main.js} +336 -67
- package/dist/{noxus.mjs → main.mjs} +325 -61
- package/dist/renderer.d.mts +1 -0
- package/dist/renderer.d.ts +1 -0
- package/dist/renderer.js +265 -0
- package/dist/renderer.mjs +236 -0
- package/package.json +73 -48
- package/scripts/postbuild.js +10 -5
- package/src/app.ts +37 -41
- package/src/decorators/method.decorator.ts +6 -1
- package/src/index.ts +1 -13
- package/src/main.ts +25 -0
- package/src/renderer-events.ts +110 -0
- package/src/request.ts +46 -5
- package/src/router.ts +133 -3
- package/src/socket.ts +68 -0
- package/tsup.config.ts +2 -1
|
@@ -25,9 +25,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
26
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
27
27
|
|
|
28
|
-
// src/
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
28
|
+
// src/main.ts
|
|
29
|
+
var main_exports = {};
|
|
30
|
+
__export(main_exports, {
|
|
31
31
|
AppInjector: () => AppInjector,
|
|
32
32
|
Authorize: () => Authorize,
|
|
33
33
|
BadGatewayException: () => BadGatewayException,
|
|
@@ -56,11 +56,14 @@ __export(src_exports, {
|
|
|
56
56
|
NotFoundException: () => NotFoundException,
|
|
57
57
|
NotImplementedException: () => NotImplementedException,
|
|
58
58
|
NoxApp: () => NoxApp,
|
|
59
|
+
NoxSocket: () => NoxSocket,
|
|
59
60
|
Patch: () => Patch,
|
|
60
61
|
PaymentRequiredException: () => PaymentRequiredException,
|
|
61
62
|
Post: () => Post,
|
|
62
63
|
Put: () => Put,
|
|
64
|
+
RENDERER_EVENT_TYPE: () => RENDERER_EVENT_TYPE,
|
|
63
65
|
ROUTE_METADATA_KEY: () => ROUTE_METADATA_KEY,
|
|
66
|
+
RendererEventRegistry: () => RendererEventRegistry,
|
|
64
67
|
Request: () => Request,
|
|
65
68
|
RequestTimeoutException: () => RequestTimeoutException,
|
|
66
69
|
ResponseException: () => ResponseException,
|
|
@@ -73,6 +76,7 @@ __export(src_exports, {
|
|
|
73
76
|
UseMiddlewares: () => UseMiddlewares,
|
|
74
77
|
VariantAlsoNegotiatesException: () => VariantAlsoNegotiatesException,
|
|
75
78
|
bootstrapApplication: () => bootstrapApplication,
|
|
79
|
+
createRendererEventMessage: () => createRendererEventMessage,
|
|
76
80
|
getControllerMetadata: () => getControllerMetadata,
|
|
77
81
|
getGuardForController: () => getGuardForController,
|
|
78
82
|
getGuardForControllerAction: () => getGuardForControllerAction,
|
|
@@ -81,9 +85,10 @@ __export(src_exports, {
|
|
|
81
85
|
getMiddlewaresForControllerAction: () => getMiddlewaresForControllerAction,
|
|
82
86
|
getModuleMetadata: () => getModuleMetadata,
|
|
83
87
|
getRouteMetadata: () => getRouteMetadata,
|
|
84
|
-
inject: () => inject
|
|
88
|
+
inject: () => inject,
|
|
89
|
+
isRendererEventMessage: () => isRendererEventMessage
|
|
85
90
|
});
|
|
86
|
-
module.exports = __toCommonJS(
|
|
91
|
+
module.exports = __toCommonJS(main_exports);
|
|
87
92
|
|
|
88
93
|
// src/DI/app-injector.ts
|
|
89
94
|
var import_reflect_metadata = require("reflect-metadata");
|
|
@@ -359,7 +364,7 @@ __name(inject, "inject");
|
|
|
359
364
|
var RootInjector = new AppInjector("root");
|
|
360
365
|
|
|
361
366
|
// src/router.ts
|
|
362
|
-
var
|
|
367
|
+
var import_reflect_metadata3 = require("reflect-metadata");
|
|
363
368
|
|
|
364
369
|
// src/decorators/guards.decorator.ts
|
|
365
370
|
function Authorize(...guardClasses) {
|
|
@@ -699,6 +704,45 @@ function getMiddlewaresForControllerAction(controllerName, actionName) {
|
|
|
699
704
|
__name(getMiddlewaresForControllerAction, "getMiddlewaresForControllerAction");
|
|
700
705
|
var middlewares = /* @__PURE__ */ new Map();
|
|
701
706
|
|
|
707
|
+
// src/request.ts
|
|
708
|
+
var import_reflect_metadata2 = require("reflect-metadata");
|
|
709
|
+
var _Request = class _Request {
|
|
710
|
+
constructor(event, id, method, path, body) {
|
|
711
|
+
__publicField(this, "event");
|
|
712
|
+
__publicField(this, "id");
|
|
713
|
+
__publicField(this, "method");
|
|
714
|
+
__publicField(this, "path");
|
|
715
|
+
__publicField(this, "body");
|
|
716
|
+
__publicField(this, "context", RootInjector.createScope());
|
|
717
|
+
__publicField(this, "params", {});
|
|
718
|
+
this.event = event;
|
|
719
|
+
this.id = id;
|
|
720
|
+
this.method = method;
|
|
721
|
+
this.path = path;
|
|
722
|
+
this.body = body;
|
|
723
|
+
this.path = path.replace(/^\/|\/$/g, "");
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
__name(_Request, "Request");
|
|
727
|
+
var Request = _Request;
|
|
728
|
+
var RENDERER_EVENT_TYPE = "noxus:event";
|
|
729
|
+
function createRendererEventMessage(event, payload) {
|
|
730
|
+
return {
|
|
731
|
+
type: RENDERER_EVENT_TYPE,
|
|
732
|
+
event,
|
|
733
|
+
payload
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
__name(createRendererEventMessage, "createRendererEventMessage");
|
|
737
|
+
function isRendererEventMessage(value) {
|
|
738
|
+
if (value === null || typeof value !== "object") {
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
const possibleMessage = value;
|
|
742
|
+
return possibleMessage.type === RENDERER_EVENT_TYPE && typeof possibleMessage.event === "string";
|
|
743
|
+
}
|
|
744
|
+
__name(isRendererEventMessage, "isRendererEventMessage");
|
|
745
|
+
|
|
702
746
|
// src/utils/radix-tree.ts
|
|
703
747
|
var _a;
|
|
704
748
|
var RadixNode = (_a = class {
|
|
@@ -864,6 +908,17 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
864
908
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
865
909
|
}
|
|
866
910
|
__name(_ts_decorate, "_ts_decorate");
|
|
911
|
+
var ATOMIC_HTTP_METHODS = /* @__PURE__ */ new Set([
|
|
912
|
+
"GET",
|
|
913
|
+
"POST",
|
|
914
|
+
"PUT",
|
|
915
|
+
"PATCH",
|
|
916
|
+
"DELETE"
|
|
917
|
+
]);
|
|
918
|
+
function isAtomicHttpMethod(method) {
|
|
919
|
+
return typeof method === "string" && ATOMIC_HTTP_METHODS.has(method);
|
|
920
|
+
}
|
|
921
|
+
__name(isAtomicHttpMethod, "isAtomicHttpMethod");
|
|
867
922
|
var _Router = class _Router {
|
|
868
923
|
constructor() {
|
|
869
924
|
__publicField(this, "routes", new RadixTree());
|
|
@@ -932,6 +987,12 @@ var _Router = class _Router {
|
|
|
932
987
|
* @param channelSenderId - The ID of the sender channel to shut down.
|
|
933
988
|
*/
|
|
934
989
|
async handle(request) {
|
|
990
|
+
if (request.method === "BATCH") {
|
|
991
|
+
return this.handleBatch(request);
|
|
992
|
+
}
|
|
993
|
+
return this.handleAtomic(request);
|
|
994
|
+
}
|
|
995
|
+
async handleAtomic(request) {
|
|
935
996
|
Logger.comment(`> ${request.method} /${request.path}`);
|
|
936
997
|
const t0 = performance.now();
|
|
937
998
|
const response = {
|
|
@@ -975,6 +1036,94 @@ var _Router = class _Router {
|
|
|
975
1036
|
return response;
|
|
976
1037
|
}
|
|
977
1038
|
}
|
|
1039
|
+
async handleBatch(request) {
|
|
1040
|
+
Logger.comment(`> ${request.method} /${request.path}`);
|
|
1041
|
+
const t0 = performance.now();
|
|
1042
|
+
const response = {
|
|
1043
|
+
requestId: request.id,
|
|
1044
|
+
status: 200,
|
|
1045
|
+
body: {
|
|
1046
|
+
responses: []
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
try {
|
|
1050
|
+
const payload = this.normalizeBatchPayload(request.body);
|
|
1051
|
+
const batchResponses = [];
|
|
1052
|
+
for (const [index, item] of payload.requests.entries()) {
|
|
1053
|
+
const subRequestId = item.requestId ?? `${request.id}:${index}`;
|
|
1054
|
+
const atomicRequest = new Request(request.event, subRequestId, item.method, item.path, item.body);
|
|
1055
|
+
batchResponses.push(await this.handleAtomic(atomicRequest));
|
|
1056
|
+
}
|
|
1057
|
+
response.body.responses = batchResponses;
|
|
1058
|
+
} catch (error) {
|
|
1059
|
+
response.body = void 0;
|
|
1060
|
+
if (error instanceof ResponseException) {
|
|
1061
|
+
response.status = error.status;
|
|
1062
|
+
response.error = error.message;
|
|
1063
|
+
response.stack = error.stack;
|
|
1064
|
+
} else if (error instanceof Error) {
|
|
1065
|
+
response.status = 500;
|
|
1066
|
+
response.error = error.message || "Internal Server Error";
|
|
1067
|
+
response.stack = error.stack || "No stack trace available";
|
|
1068
|
+
} else {
|
|
1069
|
+
response.status = 500;
|
|
1070
|
+
response.error = "Unknown error occurred";
|
|
1071
|
+
response.stack = "No stack trace available";
|
|
1072
|
+
}
|
|
1073
|
+
} finally {
|
|
1074
|
+
const t1 = performance.now();
|
|
1075
|
+
const message = `< ${response.status} ${request.method} /${request.path} ${Logger.colors.yellow}${Math.round(t1 - t0)}ms${Logger.colors.initial}`;
|
|
1076
|
+
if (response.status < 400) Logger.log(message);
|
|
1077
|
+
else if (response.status < 500) Logger.warn(message);
|
|
1078
|
+
else Logger.error(message);
|
|
1079
|
+
if (response.error !== void 0) {
|
|
1080
|
+
Logger.error(response.error);
|
|
1081
|
+
if (response.stack !== void 0) {
|
|
1082
|
+
Logger.errorStack(response.stack);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
return response;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
normalizeBatchPayload(body) {
|
|
1089
|
+
if (body === null || typeof body !== "object") {
|
|
1090
|
+
throw new BadRequestException("Batch payload must be an object containing a requests array.");
|
|
1091
|
+
}
|
|
1092
|
+
const possiblePayload = body;
|
|
1093
|
+
const { requests } = possiblePayload;
|
|
1094
|
+
if (!Array.isArray(requests)) {
|
|
1095
|
+
throw new BadRequestException("Batch payload must define a requests array.");
|
|
1096
|
+
}
|
|
1097
|
+
const normalizedRequests = requests.map((entry, index) => this.normalizeBatchItem(entry, index));
|
|
1098
|
+
return {
|
|
1099
|
+
requests: normalizedRequests
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
normalizeBatchItem(entry, index) {
|
|
1103
|
+
if (entry === null || typeof entry !== "object") {
|
|
1104
|
+
throw new BadRequestException(`Batch request at index ${index} must be an object.`);
|
|
1105
|
+
}
|
|
1106
|
+
const { requestId, path, method, body } = entry;
|
|
1107
|
+
if (requestId !== void 0 && typeof requestId !== "string") {
|
|
1108
|
+
throw new BadRequestException(`Batch request at index ${index} has an invalid requestId.`);
|
|
1109
|
+
}
|
|
1110
|
+
if (typeof path !== "string" || path.length === 0) {
|
|
1111
|
+
throw new BadRequestException(`Batch request at index ${index} must define a non-empty path.`);
|
|
1112
|
+
}
|
|
1113
|
+
if (typeof method !== "string") {
|
|
1114
|
+
throw new BadRequestException(`Batch request at index ${index} must define an HTTP method.`);
|
|
1115
|
+
}
|
|
1116
|
+
const normalizedMethod = method.toUpperCase();
|
|
1117
|
+
if (!isAtomicHttpMethod(normalizedMethod)) {
|
|
1118
|
+
throw new BadRequestException(`Batch request at index ${index} uses the unsupported method ${method}.`);
|
|
1119
|
+
}
|
|
1120
|
+
return {
|
|
1121
|
+
requestId,
|
|
1122
|
+
path,
|
|
1123
|
+
method: normalizedMethod,
|
|
1124
|
+
body
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
978
1127
|
/**
|
|
979
1128
|
* Finds the route definition for a given request.
|
|
980
1129
|
* This method searches the routing tree for a matching route based on the request's path and method.
|
|
@@ -1112,46 +1261,106 @@ Router = _ts_decorate([
|
|
|
1112
1261
|
// src/app.ts
|
|
1113
1262
|
var import_main = require("electron/main");
|
|
1114
1263
|
|
|
1115
|
-
// src/
|
|
1116
|
-
|
|
1117
|
-
var
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
__publicField(this, "
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
this.
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
this.
|
|
1264
|
+
// src/socket.ts
|
|
1265
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
1266
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1267
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1268
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1269
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1270
|
+
}
|
|
1271
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
1272
|
+
var _NoxSocket = class _NoxSocket {
|
|
1273
|
+
constructor() {
|
|
1274
|
+
__publicField(this, "messagePorts", /* @__PURE__ */ new Map());
|
|
1275
|
+
}
|
|
1276
|
+
register(senderId, channel) {
|
|
1277
|
+
this.messagePorts.set(senderId, channel);
|
|
1278
|
+
}
|
|
1279
|
+
get(senderId) {
|
|
1280
|
+
return this.messagePorts.get(senderId);
|
|
1281
|
+
}
|
|
1282
|
+
unregister(senderId) {
|
|
1283
|
+
this.messagePorts.delete(senderId);
|
|
1284
|
+
}
|
|
1285
|
+
getSenderIds() {
|
|
1286
|
+
return [
|
|
1287
|
+
...this.messagePorts.keys()
|
|
1288
|
+
];
|
|
1289
|
+
}
|
|
1290
|
+
emit(eventName, payload, targetSenderIds) {
|
|
1291
|
+
const normalizedEvent = eventName.trim();
|
|
1292
|
+
if (normalizedEvent.length === 0) {
|
|
1293
|
+
throw new Error("Renderer event name must be a non-empty string.");
|
|
1294
|
+
}
|
|
1295
|
+
const recipients = targetSenderIds ?? this.getSenderIds();
|
|
1296
|
+
let delivered = 0;
|
|
1297
|
+
for (const senderId of recipients) {
|
|
1298
|
+
const channel = this.messagePorts.get(senderId);
|
|
1299
|
+
if (!channel) {
|
|
1300
|
+
Logger.warn(`No message channel found for sender ID: ${senderId} while emitting "${normalizedEvent}".`);
|
|
1301
|
+
continue;
|
|
1302
|
+
}
|
|
1303
|
+
try {
|
|
1304
|
+
channel.port1.postMessage(createRendererEventMessage(normalizedEvent, payload));
|
|
1305
|
+
delivered++;
|
|
1306
|
+
} catch (error) {
|
|
1307
|
+
Logger.error(`[Noxus] Failed to emit "${normalizedEvent}" to sender ${senderId}.`, error);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
return delivered;
|
|
1311
|
+
}
|
|
1312
|
+
emitToRenderer(senderId, eventName, payload) {
|
|
1313
|
+
return this.emit(eventName, payload, [
|
|
1314
|
+
senderId
|
|
1315
|
+
]) > 0;
|
|
1132
1316
|
}
|
|
1133
1317
|
};
|
|
1134
|
-
__name(
|
|
1135
|
-
var
|
|
1318
|
+
__name(_NoxSocket, "NoxSocket");
|
|
1319
|
+
var NoxSocket = _NoxSocket;
|
|
1320
|
+
NoxSocket = _ts_decorate2([
|
|
1321
|
+
Injectable("singleton")
|
|
1322
|
+
], NoxSocket);
|
|
1136
1323
|
|
|
1137
1324
|
// src/app.ts
|
|
1138
|
-
function
|
|
1325
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
1139
1326
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1140
1327
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1141
1328
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1142
1329
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1143
1330
|
}
|
|
1144
|
-
__name(
|
|
1331
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
1145
1332
|
function _ts_metadata(k, v) {
|
|
1146
1333
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1147
1334
|
}
|
|
1148
1335
|
__name(_ts_metadata, "_ts_metadata");
|
|
1149
1336
|
var _NoxApp = class _NoxApp {
|
|
1150
|
-
constructor(router) {
|
|
1337
|
+
constructor(router, socket) {
|
|
1151
1338
|
__publicField(this, "router");
|
|
1152
|
-
__publicField(this, "
|
|
1339
|
+
__publicField(this, "socket");
|
|
1153
1340
|
__publicField(this, "app");
|
|
1341
|
+
__publicField(this, "onRendererMessage", /* @__PURE__ */ __name(async (event) => {
|
|
1342
|
+
const { senderId, requestId, path, method, body } = event.data;
|
|
1343
|
+
const channel = this.socket.get(senderId);
|
|
1344
|
+
if (!channel) {
|
|
1345
|
+
Logger.error(`No message channel found for sender ID: ${senderId}`);
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
try {
|
|
1349
|
+
const request = new Request(event, requestId, method, path, body);
|
|
1350
|
+
const response = await this.router.handle(request);
|
|
1351
|
+
channel.port1.postMessage(response);
|
|
1352
|
+
} catch (err) {
|
|
1353
|
+
const response = {
|
|
1354
|
+
requestId,
|
|
1355
|
+
status: 500,
|
|
1356
|
+
body: null,
|
|
1357
|
+
error: err.message || "Internal Server Error"
|
|
1358
|
+
};
|
|
1359
|
+
channel.port1.postMessage(response);
|
|
1360
|
+
}
|
|
1361
|
+
}, "onRendererMessage"));
|
|
1154
1362
|
this.router = router;
|
|
1363
|
+
this.socket = socket;
|
|
1155
1364
|
}
|
|
1156
1365
|
/**
|
|
1157
1366
|
* Initializes the NoxApp instance.
|
|
@@ -1173,44 +1382,19 @@ var _NoxApp = class _NoxApp {
|
|
|
1173
1382
|
*/
|
|
1174
1383
|
giveTheRendererAPort(event) {
|
|
1175
1384
|
const senderId = event.sender.id;
|
|
1176
|
-
if (this.
|
|
1385
|
+
if (this.socket.get(senderId)) {
|
|
1177
1386
|
this.shutdownChannel(senderId);
|
|
1178
1387
|
}
|
|
1179
1388
|
const channel = new import_main.MessageChannelMain();
|
|
1180
|
-
|
|
1181
|
-
channel.port1.on("message", this.onRendererMessage.bind(this));
|
|
1389
|
+
channel.port1.on("message", this.onRendererMessage);
|
|
1182
1390
|
channel.port1.start();
|
|
1391
|
+
this.socket.register(senderId, channel);
|
|
1183
1392
|
event.sender.postMessage("port", {
|
|
1184
1393
|
senderId
|
|
1185
1394
|
}, [
|
|
1186
1395
|
channel.port2
|
|
1187
1396
|
]);
|
|
1188
1397
|
}
|
|
1189
|
-
/**
|
|
1190
|
-
* Electron specific message handling.
|
|
1191
|
-
* Replaces HTTP calls by using Electron's IPC mechanism.
|
|
1192
|
-
*/
|
|
1193
|
-
async onRendererMessage(event) {
|
|
1194
|
-
const { senderId, requestId, path, method, body } = event.data;
|
|
1195
|
-
const channel = this.messagePorts.get(senderId);
|
|
1196
|
-
if (!channel) {
|
|
1197
|
-
Logger.error(`No message channel found for sender ID: ${senderId}`);
|
|
1198
|
-
return;
|
|
1199
|
-
}
|
|
1200
|
-
try {
|
|
1201
|
-
const request = new Request(event, requestId, method, path, body);
|
|
1202
|
-
const response = await this.router.handle(request);
|
|
1203
|
-
channel.port1.postMessage(response);
|
|
1204
|
-
} catch (err) {
|
|
1205
|
-
const response = {
|
|
1206
|
-
requestId,
|
|
1207
|
-
status: 500,
|
|
1208
|
-
body: null,
|
|
1209
|
-
error: err.message || "Internal Server Error"
|
|
1210
|
-
};
|
|
1211
|
-
channel.port1.postMessage(response);
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
1398
|
/**
|
|
1215
1399
|
* MacOS specific behavior.
|
|
1216
1400
|
*/
|
|
@@ -1227,25 +1411,24 @@ var _NoxApp = class _NoxApp {
|
|
|
1227
1411
|
* @param remove - Whether to remove the channel from the messagePorts map.
|
|
1228
1412
|
*/
|
|
1229
1413
|
shutdownChannel(channelSenderId) {
|
|
1230
|
-
const channel = this.
|
|
1414
|
+
const channel = this.socket.get(channelSenderId);
|
|
1231
1415
|
if (!channel) {
|
|
1232
1416
|
Logger.warn(`No message channel found for sender ID: ${channelSenderId}`);
|
|
1233
1417
|
return;
|
|
1234
1418
|
}
|
|
1235
|
-
channel.port1.off("message", this.onRendererMessage
|
|
1419
|
+
channel.port1.off("message", this.onRendererMessage);
|
|
1236
1420
|
channel.port1.close();
|
|
1237
1421
|
channel.port2.close();
|
|
1238
|
-
this.
|
|
1422
|
+
this.socket.unregister(channelSenderId);
|
|
1239
1423
|
}
|
|
1240
1424
|
/**
|
|
1241
1425
|
* Handles the application shutdown process.
|
|
1242
1426
|
* This method is called when all windows are closed, and it cleans up the message channels
|
|
1243
1427
|
*/
|
|
1244
1428
|
async onAllWindowsClosed() {
|
|
1245
|
-
this.
|
|
1429
|
+
for (const senderId of this.socket.getSenderIds()) {
|
|
1246
1430
|
this.shutdownChannel(senderId);
|
|
1247
|
-
}
|
|
1248
|
-
this.messagePorts.clear();
|
|
1431
|
+
}
|
|
1249
1432
|
Logger.info("All windows closed, shutting down application...");
|
|
1250
1433
|
await this.app?.dispose();
|
|
1251
1434
|
if (process.platform !== "darwin") {
|
|
@@ -1284,11 +1467,12 @@ var _NoxApp = class _NoxApp {
|
|
|
1284
1467
|
};
|
|
1285
1468
|
__name(_NoxApp, "NoxApp");
|
|
1286
1469
|
var NoxApp = _NoxApp;
|
|
1287
|
-
NoxApp =
|
|
1470
|
+
NoxApp = _ts_decorate3([
|
|
1288
1471
|
Injectable("singleton"),
|
|
1289
1472
|
_ts_metadata("design:type", Function),
|
|
1290
1473
|
_ts_metadata("design:paramtypes", [
|
|
1291
|
-
typeof Router === "undefined" ? Object : Router
|
|
1474
|
+
typeof Router === "undefined" ? Object : Router,
|
|
1475
|
+
typeof NoxSocket === "undefined" ? Object : NoxSocket
|
|
1292
1476
|
])
|
|
1293
1477
|
], NoxApp);
|
|
1294
1478
|
|
|
@@ -1304,6 +1488,86 @@ async function bootstrapApplication(rootModule) {
|
|
|
1304
1488
|
return noxApp;
|
|
1305
1489
|
}
|
|
1306
1490
|
__name(bootstrapApplication, "bootstrapApplication");
|
|
1491
|
+
|
|
1492
|
+
// src/renderer-events.ts
|
|
1493
|
+
var _RendererEventRegistry = class _RendererEventRegistry {
|
|
1494
|
+
constructor() {
|
|
1495
|
+
__publicField(this, "listeners", /* @__PURE__ */ new Map());
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
*
|
|
1499
|
+
*/
|
|
1500
|
+
subscribe(eventName, handler) {
|
|
1501
|
+
const normalizedEventName = eventName.trim();
|
|
1502
|
+
if (normalizedEventName.length === 0) {
|
|
1503
|
+
throw new Error("Renderer event name must be a non-empty string.");
|
|
1504
|
+
}
|
|
1505
|
+
const handlers = this.listeners.get(normalizedEventName) ?? /* @__PURE__ */ new Set();
|
|
1506
|
+
handlers.add(handler);
|
|
1507
|
+
this.listeners.set(normalizedEventName, handlers);
|
|
1508
|
+
return {
|
|
1509
|
+
unsubscribe: /* @__PURE__ */ __name(() => this.unsubscribe(normalizedEventName, handler), "unsubscribe")
|
|
1510
|
+
};
|
|
1511
|
+
}
|
|
1512
|
+
/**
|
|
1513
|
+
*
|
|
1514
|
+
*/
|
|
1515
|
+
unsubscribe(eventName, handler) {
|
|
1516
|
+
const handlers = this.listeners.get(eventName);
|
|
1517
|
+
if (!handlers) {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
handlers.delete(handler);
|
|
1521
|
+
if (handlers.size === 0) {
|
|
1522
|
+
this.listeners.delete(eventName);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
*
|
|
1527
|
+
*/
|
|
1528
|
+
clear(eventName) {
|
|
1529
|
+
if (eventName) {
|
|
1530
|
+
this.listeners.delete(eventName);
|
|
1531
|
+
return;
|
|
1532
|
+
}
|
|
1533
|
+
this.listeners.clear();
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
*
|
|
1537
|
+
*/
|
|
1538
|
+
dispatch(message) {
|
|
1539
|
+
const handlers = this.listeners.get(message.event);
|
|
1540
|
+
if (!handlers || handlers.size === 0) {
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
handlers.forEach((handler) => {
|
|
1544
|
+
try {
|
|
1545
|
+
handler(message.payload);
|
|
1546
|
+
} catch (error) {
|
|
1547
|
+
console.error(`[Noxus] Renderer event handler for "${message.event}" threw an error.`, error);
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
*
|
|
1553
|
+
*/
|
|
1554
|
+
tryDispatchFromMessageEvent(event) {
|
|
1555
|
+
if (!isRendererEventMessage(event.data)) {
|
|
1556
|
+
return false;
|
|
1557
|
+
}
|
|
1558
|
+
this.dispatch(event.data);
|
|
1559
|
+
return true;
|
|
1560
|
+
}
|
|
1561
|
+
/**
|
|
1562
|
+
*
|
|
1563
|
+
*/
|
|
1564
|
+
hasHandlers(eventName) {
|
|
1565
|
+
const handlers = this.listeners.get(eventName);
|
|
1566
|
+
return !!handlers && handlers.size > 0;
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
__name(_RendererEventRegistry, "RendererEventRegistry");
|
|
1570
|
+
var RendererEventRegistry = _RendererEventRegistry;
|
|
1307
1571
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1308
1572
|
0 && (module.exports = {
|
|
1309
1573
|
AppInjector,
|
|
@@ -1334,11 +1598,14 @@ __name(bootstrapApplication, "bootstrapApplication");
|
|
|
1334
1598
|
NotFoundException,
|
|
1335
1599
|
NotImplementedException,
|
|
1336
1600
|
NoxApp,
|
|
1601
|
+
NoxSocket,
|
|
1337
1602
|
Patch,
|
|
1338
1603
|
PaymentRequiredException,
|
|
1339
1604
|
Post,
|
|
1340
1605
|
Put,
|
|
1606
|
+
RENDERER_EVENT_TYPE,
|
|
1341
1607
|
ROUTE_METADATA_KEY,
|
|
1608
|
+
RendererEventRegistry,
|
|
1342
1609
|
Request,
|
|
1343
1610
|
RequestTimeoutException,
|
|
1344
1611
|
ResponseException,
|
|
@@ -1351,6 +1618,7 @@ __name(bootstrapApplication, "bootstrapApplication");
|
|
|
1351
1618
|
UseMiddlewares,
|
|
1352
1619
|
VariantAlsoNegotiatesException,
|
|
1353
1620
|
bootstrapApplication,
|
|
1621
|
+
createRendererEventMessage,
|
|
1354
1622
|
getControllerMetadata,
|
|
1355
1623
|
getGuardForController,
|
|
1356
1624
|
getGuardForControllerAction,
|
|
@@ -1359,11 +1627,12 @@ __name(bootstrapApplication, "bootstrapApplication");
|
|
|
1359
1627
|
getMiddlewaresForControllerAction,
|
|
1360
1628
|
getModuleMetadata,
|
|
1361
1629
|
getRouteMetadata,
|
|
1362
|
-
inject
|
|
1630
|
+
inject,
|
|
1631
|
+
isRendererEventMessage
|
|
1363
1632
|
});
|
|
1364
1633
|
/**
|
|
1365
1634
|
* @copyright 2025 NoxFly
|
|
1366
1635
|
* @license MIT
|
|
1367
1636
|
* @author NoxFly
|
|
1368
1637
|
*/
|
|
1369
|
-
//# sourceMappingURL=
|
|
1638
|
+
//# sourceMappingURL=main.js.map
|