fix: permissionPresetsOf 未 inject 时不再抛错。(#52)

直访和 ctx.get 都放进 try。
This commit is contained in:
Cracer authored and GitHub committed 2026-10-01 16:25:07 +08:00
1 parent 2929bb783b
commit 7977b38176
1 file changed
+6 -2
+6 -2
View File
@@ -243,12 +243,16 @@ function rewriteLiveAssembly(config, assembled, context) {
});
}
/** Cordis 的 ctx 是 Proxy:未声明 inject 时点属性会抛 "cannot get property ... without inject",所以两段都要包 try。 */
function permissionPresetsOf(ctx) {
if (ctx?.permissionPresets && typeof ctx.permissionPresets.set === "function") return ctx.permissionPresets;
try {
const direct = ctx?.permissionPresets;
if (direct && typeof direct.set === "function") return direct;
} catch { /* without inject */ }
try {
const svc = ctx?.get?.("permissionPresets");
if (svc && typeof svc.set === "function") return svc;
} catch {}
} catch { /* missing */ }
return null;
}