mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Fix nostr SimplePool bootstrap
This commit is contained in:
1 parent
e30927d9fd
commit
325a6bd2bf
2 files changed
+35
-17
No files matched your search
+8
-4
@@ -210,10 +210,14 @@ function isSimplePoolConstructor(candidate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
typeof prototype.sub === "function" &&
|
||||
typeof prototype.close === "function"
|
||||
);
|
||||
const hasSubscribeMethod =
|
||||
typeof prototype.sub === "function" ||
|
||||
typeof prototype.subscribe === "function" ||
|
||||
typeof prototype.subscribeMany === "function";
|
||||
|
||||
const hasCloseMethod = typeof prototype.close === "function";
|
||||
|
||||
return hasSubscribeMethod && hasCloseMethod;
|
||||
}
|
||||
|
||||
function unwrapSimplePool(candidate) {
|
||||
|
||||
+27
-13
@@ -584,19 +584,33 @@ export function bootstrapNostrTools() {
|
||||
return activeTools;
|
||||
};
|
||||
|
||||
try {
|
||||
Object.defineProperty(scope, "NostrTools", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return activeTools;
|
||||
},
|
||||
set(value) {
|
||||
applyActive(value);
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
userLogger.warn("[bitvid] Failed to install NostrTools guard.", error);
|
||||
const existingDescriptor =
|
||||
scope && typeof scope === "object"
|
||||
? Object.getOwnPropertyDescriptor(scope, "NostrTools")
|
||||
: null;
|
||||
|
||||
const canInstallGuard =
|
||||
!existingDescriptor || existingDescriptor.configurable === true;
|
||||
|
||||
if (canInstallGuard) {
|
||||
try {
|
||||
Object.defineProperty(scope, "NostrTools", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return activeTools;
|
||||
},
|
||||
set(value) {
|
||||
applyActive(value);
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
userLogger.warn("[bitvid] Failed to install NostrTools guard.", error);
|
||||
}
|
||||
} else {
|
||||
devLogger.info(
|
||||
"[bitvid] Skipping NostrTools guard; existing property is non-configurable."
|
||||
);
|
||||
}
|
||||
|
||||
applyActive(existingGlobalTools);
|
||||
|
||||
Reference in new issue
Block a user