@noxfly/noxus 3.0.0-dev.0 → 3.0.0-dev.2
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 +14 -11
- package/dist/child.d.mts +112 -4
- package/dist/child.d.ts +112 -4
- package/dist/child.js +33 -30
- package/dist/child.mjs +33 -30
- package/dist/main.d.mts +450 -6
- package/dist/main.d.ts +450 -6
- package/dist/main.js +232 -229
- package/dist/main.mjs +234 -231
- package/dist/preload.d.mts +28 -0
- package/dist/preload.d.ts +28 -0
- package/dist/preload.js +95 -0
- package/dist/preload.mjs +70 -0
- package/dist/renderer.d.mts +159 -22
- package/dist/renderer.d.ts +159 -22
- package/dist/renderer.js +14 -58
- package/dist/renderer.mjs +10 -53
- package/package.json +26 -13
- package/src/DI/app-injector.ts +10 -1
- package/src/DI/injector-explorer.ts +2 -2
- package/src/decorators/guards.decorator.ts +1 -1
- package/src/decorators/middleware.decorator.ts +1 -1
- package/src/index.ts +2 -5
- package/src/{app.ts → internal/app.ts} +8 -8
- package/src/{bootstrap.ts → internal/bootstrap.ts} +5 -4
- package/src/{request.ts → internal/request.ts} +2 -2
- package/src/{router.ts → internal/router.ts} +9 -9
- package/src/{routes.ts → internal/routes.ts} +2 -2
- package/src/{socket.ts → internal/socket.ts} +2 -2
- package/src/main.ts +7 -7
- package/src/non-electron-process.ts +1 -1
- package/src/preload.ts +10 -0
- package/src/renderer.ts +13 -0
- package/tsup.config.ts +27 -11
- /package/src/{exceptions.ts → internal/exceptions.ts} +0 -0
- /package/src/{preload-bridge.ts → internal/preload-bridge.ts} +0 -0
- /package/src/{renderer-client.ts → internal/renderer-client.ts} +0 -0
- /package/src/{renderer-events.ts → internal/renderer-events.ts} +0 -0
package/dist/main.mjs
CHANGED
|
@@ -122,6 +122,9 @@ var init_app_injector = __esm({
|
|
|
122
122
|
return this._resolveForwardRef(target);
|
|
123
123
|
}
|
|
124
124
|
const k = keyOf(target);
|
|
125
|
+
if (this.singletons.has(k)) {
|
|
126
|
+
return this.singletons.get(k);
|
|
127
|
+
}
|
|
125
128
|
const binding = this.bindings.get(k);
|
|
126
129
|
if (!binding) {
|
|
127
130
|
const name = target instanceof Token ? target.description : target.name ?? "unknown";
|
|
@@ -622,10 +625,172 @@ var init_method_decorator = __esm({
|
|
|
622
625
|
}
|
|
623
626
|
});
|
|
624
627
|
|
|
625
|
-
// src/
|
|
628
|
+
// src/utils/radix-tree.ts
|
|
629
|
+
var _RadixNode, RadixNode, _RadixTree, RadixTree;
|
|
630
|
+
var init_radix_tree = __esm({
|
|
631
|
+
"src/utils/radix-tree.ts"() {
|
|
632
|
+
"use strict";
|
|
633
|
+
_RadixNode = class _RadixNode {
|
|
634
|
+
/**
|
|
635
|
+
* Creates a new RadixNode.
|
|
636
|
+
* @param segment - The segment of the path this node represents.
|
|
637
|
+
*/
|
|
638
|
+
constructor(segment) {
|
|
639
|
+
this.children = [];
|
|
640
|
+
this.segment = segment;
|
|
641
|
+
this.isParam = segment.startsWith(":");
|
|
642
|
+
if (this.isParam) {
|
|
643
|
+
this.paramName = segment.slice(1);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Matches a child node against a given segment.
|
|
648
|
+
* This method checks if the segment matches any of the children nodes.
|
|
649
|
+
* @param segment - The segment to match against the children of this node.
|
|
650
|
+
* @returns A child node that matches the segment, or undefined if no match is found.
|
|
651
|
+
*/
|
|
652
|
+
matchChild(segment) {
|
|
653
|
+
for (const child of this.children) {
|
|
654
|
+
if (child.isParam || segment.startsWith(child.segment))
|
|
655
|
+
return child;
|
|
656
|
+
}
|
|
657
|
+
return void 0;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Finds a child node that matches the segment exactly.
|
|
661
|
+
* This method checks if there is a child node that matches the segment exactly.
|
|
662
|
+
* @param segment - The segment to find an exact match for among the children of this node.
|
|
663
|
+
* @returns A child node that matches the segment exactly, or undefined if no match is found.
|
|
664
|
+
*/
|
|
665
|
+
findExactChild(segment) {
|
|
666
|
+
return this.children.find((c) => c.segment === segment);
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Adds a child node to this node's children.
|
|
670
|
+
* This method adds a new child node to the list of children for this node.
|
|
671
|
+
* @param node - The child node to add to this node's children.
|
|
672
|
+
*/
|
|
673
|
+
addChild(node) {
|
|
674
|
+
this.children.push(node);
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
__name(_RadixNode, "RadixNode");
|
|
678
|
+
RadixNode = _RadixNode;
|
|
679
|
+
_RadixTree = class _RadixTree {
|
|
680
|
+
constructor() {
|
|
681
|
+
this.root = new RadixNode("");
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Inserts a path and its associated value into the Radix Tree.
|
|
685
|
+
* This method normalizes the path and inserts it into the tree, associating it with
|
|
686
|
+
* @param path - The path to insert into the tree.
|
|
687
|
+
* @param value - The value to associate with the path.
|
|
688
|
+
*/
|
|
689
|
+
insert(path2, value) {
|
|
690
|
+
const segments = this.normalize(path2);
|
|
691
|
+
this.insertRecursive(this.root, segments, value);
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Recursively inserts a path into the Radix Tree.
|
|
695
|
+
* This method traverses the tree and inserts the segments of the path, creating new nodes
|
|
696
|
+
* @param node - The node to start inserting from.
|
|
697
|
+
* @param segments - The segments of the path to insert.
|
|
698
|
+
* @param value - The value to associate with the path.
|
|
699
|
+
*/
|
|
700
|
+
insertRecursive(node, segments, value) {
|
|
701
|
+
if (segments.length === 0) {
|
|
702
|
+
node.value = value;
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
const segment = segments[0] ?? "";
|
|
706
|
+
let child = node.children.find(
|
|
707
|
+
(c) => c.isParam === segment.startsWith(":") && (c.isParam || c.segment === segment)
|
|
708
|
+
);
|
|
709
|
+
if (!child) {
|
|
710
|
+
child = new RadixNode(segment);
|
|
711
|
+
node.addChild(child);
|
|
712
|
+
}
|
|
713
|
+
this.insertRecursive(child, segments.slice(1), value);
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Searches for a path in the Radix Tree.
|
|
717
|
+
* This method normalizes the path and searches for it in the tree, returning the node
|
|
718
|
+
* @param path - The path to search for in the Radix Tree.
|
|
719
|
+
* @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
|
|
720
|
+
*/
|
|
721
|
+
search(path2) {
|
|
722
|
+
const segments = this.normalize(path2);
|
|
723
|
+
return this.searchRecursive(this.root, segments, {});
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Recursively searches for a path in the Radix Tree.
|
|
727
|
+
* This method traverses the tree and searches for the segments of the path, collecting parameters
|
|
728
|
+
* @param node - The node to start searching from.
|
|
729
|
+
* @param segments - The segments of the path to search for.
|
|
730
|
+
* @param params - The parameters collected during the search.
|
|
731
|
+
* @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
|
|
732
|
+
*/
|
|
733
|
+
searchRecursive(node, segments, params) {
|
|
734
|
+
if (segments.length === 0) {
|
|
735
|
+
if (node.value !== void 0) {
|
|
736
|
+
return {
|
|
737
|
+
node,
|
|
738
|
+
params
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
return void 0;
|
|
742
|
+
}
|
|
743
|
+
const [segment, ...rest] = segments;
|
|
744
|
+
for (const child of node.children) {
|
|
745
|
+
if (child.isParam) {
|
|
746
|
+
const paramName = child.paramName;
|
|
747
|
+
const childParams = {
|
|
748
|
+
...params,
|
|
749
|
+
[paramName]: segment ?? ""
|
|
750
|
+
};
|
|
751
|
+
if (rest.length === 0) {
|
|
752
|
+
return {
|
|
753
|
+
node: child,
|
|
754
|
+
params: childParams
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
const result = this.searchRecursive(child, rest, childParams);
|
|
758
|
+
if (result)
|
|
759
|
+
return result;
|
|
760
|
+
} else if (segment === child.segment) {
|
|
761
|
+
if (rest.length === 0) {
|
|
762
|
+
return {
|
|
763
|
+
node: child,
|
|
764
|
+
params
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
const result = this.searchRecursive(child, rest, params);
|
|
768
|
+
if (result)
|
|
769
|
+
return result;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
return void 0;
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Normalizes a path into an array of segments.
|
|
776
|
+
* This method removes leading and trailing slashes, splits the path by slashes, and
|
|
777
|
+
* @param path - The path to normalize.
|
|
778
|
+
* @returns An array of normalized path segments.
|
|
779
|
+
*/
|
|
780
|
+
normalize(path2) {
|
|
781
|
+
const segments = path2.replace(/^\/+|\/+$/g, "").split("/").filter(Boolean);
|
|
782
|
+
return ["", ...segments];
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
__name(_RadixTree, "RadixTree");
|
|
786
|
+
RadixTree = _RadixTree;
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
// src/internal/exceptions.ts
|
|
626
791
|
var _ResponseException, ResponseException, _BadRequestException, BadRequestException, _UnauthorizedException, UnauthorizedException, _PaymentRequiredException, PaymentRequiredException, _ForbiddenException, ForbiddenException, _NotFoundException, NotFoundException, _MethodNotAllowedException, MethodNotAllowedException, _NotAcceptableException, NotAcceptableException, _RequestTimeoutException, RequestTimeoutException, _ConflictException, ConflictException, _UpgradeRequiredException, UpgradeRequiredException, _TooManyRequestsException, TooManyRequestsException, _InternalServerException, InternalServerException, _NotImplementedException, NotImplementedException, _BadGatewayException, BadGatewayException, _ServiceUnavailableException, ServiceUnavailableException, _GatewayTimeoutException, GatewayTimeoutException, _HttpVersionNotSupportedException, HttpVersionNotSupportedException, _VariantAlsoNegotiatesException, VariantAlsoNegotiatesException, _InsufficientStorageException, InsufficientStorageException, _LoopDetectedException, LoopDetectedException, _NotExtendedException, NotExtendedException, _NetworkAuthenticationRequiredException, NetworkAuthenticationRequiredException, _NetworkConnectTimeoutException, NetworkConnectTimeoutException;
|
|
627
792
|
var init_exceptions = __esm({
|
|
628
|
-
"src/exceptions.ts"() {
|
|
793
|
+
"src/internal/exceptions.ts"() {
|
|
629
794
|
"use strict";
|
|
630
795
|
_ResponseException = class _ResponseException extends Error {
|
|
631
796
|
constructor(statusOrMessage, message) {
|
|
@@ -832,7 +997,7 @@ var init_exceptions = __esm({
|
|
|
832
997
|
}
|
|
833
998
|
});
|
|
834
999
|
|
|
835
|
-
// src/request.ts
|
|
1000
|
+
// src/internal/request.ts
|
|
836
1001
|
function createRendererEventMessage(event, payload) {
|
|
837
1002
|
return {
|
|
838
1003
|
type: RENDERER_EVENT_TYPE,
|
|
@@ -849,7 +1014,7 @@ function isRendererEventMessage(value) {
|
|
|
849
1014
|
}
|
|
850
1015
|
var _Request, Request, RENDERER_EVENT_TYPE;
|
|
851
1016
|
var init_request = __esm({
|
|
852
|
-
"src/request.ts"() {
|
|
1017
|
+
"src/internal/request.ts"() {
|
|
853
1018
|
"use strict";
|
|
854
1019
|
init_app_injector();
|
|
855
1020
|
_Request = class _Request {
|
|
@@ -873,185 +1038,23 @@ var init_request = __esm({
|
|
|
873
1038
|
}
|
|
874
1039
|
});
|
|
875
1040
|
|
|
876
|
-
// src/
|
|
877
|
-
var _RadixNode, RadixNode, _RadixTree, RadixTree;
|
|
878
|
-
var init_radix_tree = __esm({
|
|
879
|
-
"src/utils/radix-tree.ts"() {
|
|
880
|
-
"use strict";
|
|
881
|
-
_RadixNode = class _RadixNode {
|
|
882
|
-
/**
|
|
883
|
-
* Creates a new RadixNode.
|
|
884
|
-
* @param segment - The segment of the path this node represents.
|
|
885
|
-
*/
|
|
886
|
-
constructor(segment) {
|
|
887
|
-
this.children = [];
|
|
888
|
-
this.segment = segment;
|
|
889
|
-
this.isParam = segment.startsWith(":");
|
|
890
|
-
if (this.isParam) {
|
|
891
|
-
this.paramName = segment.slice(1);
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
/**
|
|
895
|
-
* Matches a child node against a given segment.
|
|
896
|
-
* This method checks if the segment matches any of the children nodes.
|
|
897
|
-
* @param segment - The segment to match against the children of this node.
|
|
898
|
-
* @returns A child node that matches the segment, or undefined if no match is found.
|
|
899
|
-
*/
|
|
900
|
-
matchChild(segment) {
|
|
901
|
-
for (const child of this.children) {
|
|
902
|
-
if (child.isParam || segment.startsWith(child.segment))
|
|
903
|
-
return child;
|
|
904
|
-
}
|
|
905
|
-
return void 0;
|
|
906
|
-
}
|
|
907
|
-
/**
|
|
908
|
-
* Finds a child node that matches the segment exactly.
|
|
909
|
-
* This method checks if there is a child node that matches the segment exactly.
|
|
910
|
-
* @param segment - The segment to find an exact match for among the children of this node.
|
|
911
|
-
* @returns A child node that matches the segment exactly, or undefined if no match is found.
|
|
912
|
-
*/
|
|
913
|
-
findExactChild(segment) {
|
|
914
|
-
return this.children.find((c) => c.segment === segment);
|
|
915
|
-
}
|
|
916
|
-
/**
|
|
917
|
-
* Adds a child node to this node's children.
|
|
918
|
-
* This method adds a new child node to the list of children for this node.
|
|
919
|
-
* @param node - The child node to add to this node's children.
|
|
920
|
-
*/
|
|
921
|
-
addChild(node) {
|
|
922
|
-
this.children.push(node);
|
|
923
|
-
}
|
|
924
|
-
};
|
|
925
|
-
__name(_RadixNode, "RadixNode");
|
|
926
|
-
RadixNode = _RadixNode;
|
|
927
|
-
_RadixTree = class _RadixTree {
|
|
928
|
-
constructor() {
|
|
929
|
-
this.root = new RadixNode("");
|
|
930
|
-
}
|
|
931
|
-
/**
|
|
932
|
-
* Inserts a path and its associated value into the Radix Tree.
|
|
933
|
-
* This method normalizes the path and inserts it into the tree, associating it with
|
|
934
|
-
* @param path - The path to insert into the tree.
|
|
935
|
-
* @param value - The value to associate with the path.
|
|
936
|
-
*/
|
|
937
|
-
insert(path2, value) {
|
|
938
|
-
const segments = this.normalize(path2);
|
|
939
|
-
this.insertRecursive(this.root, segments, value);
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* Recursively inserts a path into the Radix Tree.
|
|
943
|
-
* This method traverses the tree and inserts the segments of the path, creating new nodes
|
|
944
|
-
* @param node - The node to start inserting from.
|
|
945
|
-
* @param segments - The segments of the path to insert.
|
|
946
|
-
* @param value - The value to associate with the path.
|
|
947
|
-
*/
|
|
948
|
-
insertRecursive(node, segments, value) {
|
|
949
|
-
if (segments.length === 0) {
|
|
950
|
-
node.value = value;
|
|
951
|
-
return;
|
|
952
|
-
}
|
|
953
|
-
const segment = segments[0] ?? "";
|
|
954
|
-
let child = node.children.find(
|
|
955
|
-
(c) => c.isParam === segment.startsWith(":") && (c.isParam || c.segment === segment)
|
|
956
|
-
);
|
|
957
|
-
if (!child) {
|
|
958
|
-
child = new RadixNode(segment);
|
|
959
|
-
node.addChild(child);
|
|
960
|
-
}
|
|
961
|
-
this.insertRecursive(child, segments.slice(1), value);
|
|
962
|
-
}
|
|
963
|
-
/**
|
|
964
|
-
* Searches for a path in the Radix Tree.
|
|
965
|
-
* This method normalizes the path and searches for it in the tree, returning the node
|
|
966
|
-
* @param path - The path to search for in the Radix Tree.
|
|
967
|
-
* @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
|
|
968
|
-
*/
|
|
969
|
-
search(path2) {
|
|
970
|
-
const segments = this.normalize(path2);
|
|
971
|
-
return this.searchRecursive(this.root, segments, {});
|
|
972
|
-
}
|
|
973
|
-
/**
|
|
974
|
-
* Recursively searches for a path in the Radix Tree.
|
|
975
|
-
* This method traverses the tree and searches for the segments of the path, collecting parameters
|
|
976
|
-
* @param node - The node to start searching from.
|
|
977
|
-
* @param segments - The segments of the path to search for.
|
|
978
|
-
* @param params - The parameters collected during the search.
|
|
979
|
-
* @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
|
|
980
|
-
*/
|
|
981
|
-
searchRecursive(node, segments, params) {
|
|
982
|
-
if (segments.length === 0) {
|
|
983
|
-
if (node.value !== void 0) {
|
|
984
|
-
return {
|
|
985
|
-
node,
|
|
986
|
-
params
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
return void 0;
|
|
990
|
-
}
|
|
991
|
-
const [segment, ...rest] = segments;
|
|
992
|
-
for (const child of node.children) {
|
|
993
|
-
if (child.isParam) {
|
|
994
|
-
const paramName = child.paramName;
|
|
995
|
-
const childParams = {
|
|
996
|
-
...params,
|
|
997
|
-
[paramName]: segment ?? ""
|
|
998
|
-
};
|
|
999
|
-
if (rest.length === 0) {
|
|
1000
|
-
return {
|
|
1001
|
-
node: child,
|
|
1002
|
-
params: childParams
|
|
1003
|
-
};
|
|
1004
|
-
}
|
|
1005
|
-
const result = this.searchRecursive(child, rest, childParams);
|
|
1006
|
-
if (result)
|
|
1007
|
-
return result;
|
|
1008
|
-
} else if (segment === child.segment) {
|
|
1009
|
-
if (rest.length === 0) {
|
|
1010
|
-
return {
|
|
1011
|
-
node: child,
|
|
1012
|
-
params
|
|
1013
|
-
};
|
|
1014
|
-
}
|
|
1015
|
-
const result = this.searchRecursive(child, rest, params);
|
|
1016
|
-
if (result)
|
|
1017
|
-
return result;
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
return void 0;
|
|
1021
|
-
}
|
|
1022
|
-
/**
|
|
1023
|
-
* Normalizes a path into an array of segments.
|
|
1024
|
-
* This method removes leading and trailing slashes, splits the path by slashes, and
|
|
1025
|
-
* @param path - The path to normalize.
|
|
1026
|
-
* @returns An array of normalized path segments.
|
|
1027
|
-
*/
|
|
1028
|
-
normalize(path2) {
|
|
1029
|
-
const segments = path2.replace(/^\/+|\/+$/g, "").split("/").filter(Boolean);
|
|
1030
|
-
return ["", ...segments];
|
|
1031
|
-
}
|
|
1032
|
-
};
|
|
1033
|
-
__name(_RadixTree, "RadixTree");
|
|
1034
|
-
RadixTree = _RadixTree;
|
|
1035
|
-
}
|
|
1036
|
-
});
|
|
1037
|
-
|
|
1038
|
-
// src/router.ts
|
|
1041
|
+
// src/internal/router.ts
|
|
1039
1042
|
var router_exports = {};
|
|
1040
1043
|
__export(router_exports, {
|
|
1041
1044
|
Router: () => Router
|
|
1042
1045
|
});
|
|
1043
1046
|
var Router;
|
|
1044
1047
|
var init_router = __esm({
|
|
1045
|
-
"src/router.ts"() {
|
|
1048
|
+
"src/internal/router.ts"() {
|
|
1046
1049
|
"use strict";
|
|
1047
1050
|
init_controller_decorator();
|
|
1048
1051
|
init_injectable_decorator();
|
|
1049
1052
|
init_method_decorator();
|
|
1050
1053
|
init_injector_explorer();
|
|
1051
|
-
init_exceptions();
|
|
1052
|
-
init_request();
|
|
1053
1054
|
init_logger();
|
|
1054
1055
|
init_radix_tree();
|
|
1056
|
+
init_exceptions();
|
|
1057
|
+
init_request();
|
|
1055
1058
|
Router = class {
|
|
1056
1059
|
constructor() {
|
|
1057
1060
|
this.routes = new RadixTree();
|
|
@@ -1295,67 +1298,12 @@ init_app_injector();
|
|
|
1295
1298
|
init_token();
|
|
1296
1299
|
init_router();
|
|
1297
1300
|
|
|
1298
|
-
// src/app.ts
|
|
1301
|
+
// src/internal/app.ts
|
|
1299
1302
|
init_injectable_decorator();
|
|
1300
1303
|
init_app_injector();
|
|
1301
1304
|
init_injector_explorer();
|
|
1302
|
-
init_request();
|
|
1303
|
-
init_router();
|
|
1304
|
-
import { app, BrowserWindow as BrowserWindow2, ipcMain, MessageChannelMain } from "electron/main";
|
|
1305
|
-
|
|
1306
|
-
// src/socket.ts
|
|
1307
|
-
init_injectable_decorator();
|
|
1308
|
-
init_request();
|
|
1309
|
-
init_logger();
|
|
1310
|
-
var NoxSocket = class {
|
|
1311
|
-
constructor() {
|
|
1312
|
-
this.channels = /* @__PURE__ */ new Map();
|
|
1313
|
-
}
|
|
1314
|
-
register(senderId, requestChannel, socketChannel) {
|
|
1315
|
-
this.channels.set(senderId, { request: requestChannel, socket: socketChannel });
|
|
1316
|
-
}
|
|
1317
|
-
get(senderId) {
|
|
1318
|
-
return this.channels.get(senderId);
|
|
1319
|
-
}
|
|
1320
|
-
unregister(senderId) {
|
|
1321
|
-
this.channels.delete(senderId);
|
|
1322
|
-
}
|
|
1323
|
-
getSenderIds() {
|
|
1324
|
-
return [...this.channels.keys()];
|
|
1325
|
-
}
|
|
1326
|
-
emit(eventName, payload, targetSenderIds) {
|
|
1327
|
-
const normalizedEvent = eventName.trim();
|
|
1328
|
-
if (normalizedEvent.length === 0) {
|
|
1329
|
-
throw new Error("Renderer event name must be a non-empty string.");
|
|
1330
|
-
}
|
|
1331
|
-
const recipients = targetSenderIds ?? this.getSenderIds();
|
|
1332
|
-
let delivered = 0;
|
|
1333
|
-
for (const senderId of recipients) {
|
|
1334
|
-
const channel = this.channels.get(senderId);
|
|
1335
|
-
if (!channel) {
|
|
1336
|
-
Logger.warn(`No message channel found for sender ID: ${senderId} while emitting "${normalizedEvent}".`);
|
|
1337
|
-
continue;
|
|
1338
|
-
}
|
|
1339
|
-
try {
|
|
1340
|
-
channel.socket.port1.postMessage(createRendererEventMessage(normalizedEvent, payload));
|
|
1341
|
-
delivered++;
|
|
1342
|
-
} catch (error) {
|
|
1343
|
-
Logger.error(`[Noxus] Failed to emit "${normalizedEvent}" to sender ${senderId}.`, error);
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
return delivered;
|
|
1347
|
-
}
|
|
1348
|
-
emitToRenderer(senderId, eventName, payload) {
|
|
1349
|
-
return this.emit(eventName, payload, [senderId]) > 0;
|
|
1350
|
-
}
|
|
1351
|
-
};
|
|
1352
|
-
__name(NoxSocket, "NoxSocket");
|
|
1353
|
-
NoxSocket = __decorateClass([
|
|
1354
|
-
Injectable({ lifetime: "singleton" })
|
|
1355
|
-
], NoxSocket);
|
|
1356
|
-
|
|
1357
|
-
// src/app.ts
|
|
1358
1305
|
init_logger();
|
|
1306
|
+
import { app, BrowserWindow as BrowserWindow2, ipcMain, MessageChannelMain } from "electron/main";
|
|
1359
1307
|
|
|
1360
1308
|
// src/window/window-manager.ts
|
|
1361
1309
|
init_injectable_decorator();
|
|
@@ -1526,7 +1474,62 @@ WindowManager = __decorateClass([
|
|
|
1526
1474
|
Injectable({ lifetime: "singleton" })
|
|
1527
1475
|
], WindowManager);
|
|
1528
1476
|
|
|
1529
|
-
// src/app.ts
|
|
1477
|
+
// src/internal/app.ts
|
|
1478
|
+
init_request();
|
|
1479
|
+
init_router();
|
|
1480
|
+
|
|
1481
|
+
// src/internal/socket.ts
|
|
1482
|
+
init_injectable_decorator();
|
|
1483
|
+
init_logger();
|
|
1484
|
+
init_request();
|
|
1485
|
+
var NoxSocket = class {
|
|
1486
|
+
constructor() {
|
|
1487
|
+
this.channels = /* @__PURE__ */ new Map();
|
|
1488
|
+
}
|
|
1489
|
+
register(senderId, requestChannel, socketChannel) {
|
|
1490
|
+
this.channels.set(senderId, { request: requestChannel, socket: socketChannel });
|
|
1491
|
+
}
|
|
1492
|
+
get(senderId) {
|
|
1493
|
+
return this.channels.get(senderId);
|
|
1494
|
+
}
|
|
1495
|
+
unregister(senderId) {
|
|
1496
|
+
this.channels.delete(senderId);
|
|
1497
|
+
}
|
|
1498
|
+
getSenderIds() {
|
|
1499
|
+
return [...this.channels.keys()];
|
|
1500
|
+
}
|
|
1501
|
+
emit(eventName, payload, targetSenderIds) {
|
|
1502
|
+
const normalizedEvent = eventName.trim();
|
|
1503
|
+
if (normalizedEvent.length === 0) {
|
|
1504
|
+
throw new Error("Renderer event name must be a non-empty string.");
|
|
1505
|
+
}
|
|
1506
|
+
const recipients = targetSenderIds ?? this.getSenderIds();
|
|
1507
|
+
let delivered = 0;
|
|
1508
|
+
for (const senderId of recipients) {
|
|
1509
|
+
const channel = this.channels.get(senderId);
|
|
1510
|
+
if (!channel) {
|
|
1511
|
+
Logger.warn(`No message channel found for sender ID: ${senderId} while emitting "${normalizedEvent}".`);
|
|
1512
|
+
continue;
|
|
1513
|
+
}
|
|
1514
|
+
try {
|
|
1515
|
+
channel.socket.port1.postMessage(createRendererEventMessage(normalizedEvent, payload));
|
|
1516
|
+
delivered++;
|
|
1517
|
+
} catch (error) {
|
|
1518
|
+
Logger.error(`[Noxus] Failed to emit "${normalizedEvent}" to sender ${senderId}.`, error);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
return delivered;
|
|
1522
|
+
}
|
|
1523
|
+
emitToRenderer(senderId, eventName, payload) {
|
|
1524
|
+
return this.emit(eventName, payload, [senderId]) > 0;
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
__name(NoxSocket, "NoxSocket");
|
|
1528
|
+
NoxSocket = __decorateClass([
|
|
1529
|
+
Injectable({ lifetime: "singleton" })
|
|
1530
|
+
], NoxSocket);
|
|
1531
|
+
|
|
1532
|
+
// src/internal/app.ts
|
|
1530
1533
|
var NoxApp = class {
|
|
1531
1534
|
constructor() {
|
|
1532
1535
|
this.router = inject(Router);
|
|
@@ -1668,10 +1671,10 @@ NoxApp = __decorateClass([
|
|
|
1668
1671
|
Injectable({ lifetime: "singleton", deps: [Router, NoxSocket, WindowManager] })
|
|
1669
1672
|
], NoxApp);
|
|
1670
1673
|
|
|
1671
|
-
// src/bootstrap.ts
|
|
1672
|
-
import { app as app2 } from "electron/main";
|
|
1674
|
+
// src/internal/bootstrap.ts
|
|
1673
1675
|
init_app_injector();
|
|
1674
1676
|
init_injector_explorer();
|
|
1677
|
+
import { app as app2 } from "electron/main";
|
|
1675
1678
|
async function bootstrapApplication(config = {}) {
|
|
1676
1679
|
await app2.whenReady();
|
|
1677
1680
|
const overrides = /* @__PURE__ */ new Map();
|
|
@@ -1703,7 +1706,7 @@ init_logger();
|
|
|
1703
1706
|
init_forward_ref();
|
|
1704
1707
|
init_request();
|
|
1705
1708
|
|
|
1706
|
-
// src/routes.ts
|
|
1709
|
+
// src/internal/routes.ts
|
|
1707
1710
|
function defineRoutes(routes) {
|
|
1708
1711
|
const paths = routes.map((r) => r.path.replace(/^\/+|\/+$/g, ""));
|
|
1709
1712
|
const duplicates = paths.filter((p, i) => paths.indexOf(p) !== i);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2025 NoxFly
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author NoxFly
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
interface IPortRequester {
|
|
8
|
+
requestPort(): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
interface NoxusPreloadAPI extends IPortRequester {
|
|
13
|
+
}
|
|
14
|
+
interface NoxusPreloadOptions {
|
|
15
|
+
exposeAs?: string;
|
|
16
|
+
initMessageType?: string;
|
|
17
|
+
requestChannel?: string;
|
|
18
|
+
responseChannel?: string;
|
|
19
|
+
targetWindow?: Window;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Exposes a minimal bridge in the isolated preload context so renderer processes
|
|
23
|
+
* can request the two MessagePorts required by Noxus. The bridge forwards both
|
|
24
|
+
* request/response and socket ports to the renderer via window.postMessage.
|
|
25
|
+
*/
|
|
26
|
+
declare function exposeNoxusBridge(options?: NoxusPreloadOptions): NoxusPreloadAPI;
|
|
27
|
+
|
|
28
|
+
export { type NoxusPreloadAPI, type NoxusPreloadOptions, exposeNoxusBridge };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2025 NoxFly
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author NoxFly
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
interface IPortRequester {
|
|
8
|
+
requestPort(): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
interface NoxusPreloadAPI extends IPortRequester {
|
|
13
|
+
}
|
|
14
|
+
interface NoxusPreloadOptions {
|
|
15
|
+
exposeAs?: string;
|
|
16
|
+
initMessageType?: string;
|
|
17
|
+
requestChannel?: string;
|
|
18
|
+
responseChannel?: string;
|
|
19
|
+
targetWindow?: Window;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Exposes a minimal bridge in the isolated preload context so renderer processes
|
|
23
|
+
* can request the two MessagePorts required by Noxus. The bridge forwards both
|
|
24
|
+
* request/response and socket ports to the renderer via window.postMessage.
|
|
25
|
+
*/
|
|
26
|
+
declare function exposeNoxusBridge(options?: NoxusPreloadOptions): NoxusPreloadAPI;
|
|
27
|
+
|
|
28
|
+
export { type NoxusPreloadAPI, type NoxusPreloadOptions, exposeNoxusBridge };
|
package/dist/preload.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2025 NoxFly
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author NoxFly
|
|
5
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
|
|
26
|
+
// src/preload.ts
|
|
27
|
+
var preload_exports = {};
|
|
28
|
+
__export(preload_exports, {
|
|
29
|
+
exposeNoxusBridge: () => exposeNoxusBridge
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(preload_exports);
|
|
32
|
+
|
|
33
|
+
// src/internal/preload-bridge.ts
|
|
34
|
+
var import_renderer = require("electron/renderer");
|
|
35
|
+
var DEFAULT_EXPOSE_NAME = "noxus";
|
|
36
|
+
var DEFAULT_INIT_EVENT = "init-port";
|
|
37
|
+
var DEFAULT_REQUEST_CHANNEL = "gimme-my-port";
|
|
38
|
+
var DEFAULT_RESPONSE_CHANNEL = "port";
|
|
39
|
+
function exposeNoxusBridge(options = {}) {
|
|
40
|
+
const {
|
|
41
|
+
exposeAs = DEFAULT_EXPOSE_NAME,
|
|
42
|
+
initMessageType = DEFAULT_INIT_EVENT,
|
|
43
|
+
requestChannel = DEFAULT_REQUEST_CHANNEL,
|
|
44
|
+
responseChannel = DEFAULT_RESPONSE_CHANNEL,
|
|
45
|
+
targetWindow = window
|
|
46
|
+
} = options;
|
|
47
|
+
const api = {
|
|
48
|
+
requestPort: /* @__PURE__ */ __name(() => {
|
|
49
|
+
import_renderer.ipcRenderer.send(requestChannel);
|
|
50
|
+
import_renderer.ipcRenderer.once(responseChannel, (event, message) => {
|
|
51
|
+
const ports = (event.ports ?? []).filter((port) => port !== void 0);
|
|
52
|
+
if (ports.length === 0) {
|
|
53
|
+
console.error("[Noxus] No MessagePort received from main process.");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
for (const port of ports) {
|
|
57
|
+
try {
|
|
58
|
+
port.start();
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error("[Noxus] Failed to start MessagePort.", error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
targetWindow.postMessage(
|
|
64
|
+
{
|
|
65
|
+
type: initMessageType,
|
|
66
|
+
senderId: message?.senderId
|
|
67
|
+
},
|
|
68
|
+
"*",
|
|
69
|
+
ports
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
}, "requestPort")
|
|
73
|
+
};
|
|
74
|
+
import_renderer.contextBridge.exposeInMainWorld(exposeAs, api);
|
|
75
|
+
return api;
|
|
76
|
+
}
|
|
77
|
+
__name(exposeNoxusBridge, "exposeNoxusBridge");
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
exposeNoxusBridge
|
|
81
|
+
});
|
|
82
|
+
/**
|
|
83
|
+
* @copyright 2025 NoxFly
|
|
84
|
+
* @license MIT
|
|
85
|
+
* @author NoxFly
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* @copyright 2025 NoxFly
|
|
89
|
+
* @license MIT
|
|
90
|
+
* @author NoxFly
|
|
91
|
+
*
|
|
92
|
+
* Entry point for Electron preload scripts.
|
|
93
|
+
* Imports electron/renderer — must NOT be bundled into renderer web code.
|
|
94
|
+
*/
|
|
95
|
+
//# sourceMappingURL=preload.js.map
|