Compare commits

..

47 commits

Author SHA1 Message Date
OTKUSteyler
1547421074
Update index.ts
Some checks failed
Node.js CI / CD (Bun + Forgejo) / buildAndRelease (push) Has been cancelled
2026-09-12 10:39:07 +02:00
OTKUSteyler
f3b7935ab0
Update index.ts 2026-09-12 10:36:20 +02:00
OTKUSteyler
2fca83c60a
Merge branch 'kmmiio99o:main' into main 2026-09-11 09:31:49 +02:00
kmmiio99o
c663a3724c
Merge pull request #14 from ItsTripleSix/fix/account-switch-splash-hang
fix: prevent account-switch cold launch splash hang
2026-09-11 08:48:19 +02:00
OTKUSteyler
94e651a50e
Update index.ts 2026-09-11 08:28:51 +02:00
OTKUSteyler
40726d5b9a
Delete src/core/plugins/CustomBackgroundMusic directory 2026-09-11 08:27:50 +02:00
OTKUSteyler
d8b35b5501
Update updater.ts 2026-09-11 08:26:59 +02:00
OTKUSteyler
32d32d3f02
Update index.ts 2026-09-11 08:02:23 +02:00
OTKUSteyler
3914eb8e11
Create Settings.tsx 2026-09-11 08:00:13 +02:00
OTKUSteyler
ad9963ade2
Create index.ts 2026-09-11 07:59:27 +02:00
OTKUSteyler
363f9984f6
Delete src/core/plugins/custom background music directory 2026-09-11 07:58:22 +02:00
OTKUSteyler
f5c9edd1fd
Rename Index.ts to index.ts 2026-09-11 07:56:06 +02:00
OTKUSteyler
c1b2498009
Update index.ts 2026-09-11 07:43:27 +02:00
OTKUSteyler
1e381e4940
Update Settings.tsx 2026-09-11 07:38:52 +02:00
OTKUSteyler
e87aff3801
Update Index.ts 2026-09-11 07:38:00 +02:00
OTKUSteyler
0ed3508d7c
Update Index.ts 2026-09-11 07:23:46 +02:00
OTKUSteyler
c1b8f5969e
Create Settings.tsx 2026-09-11 07:22:42 +02:00
OTKUSteyler
24ebe343bd
Create Index.ts 2026-09-11 07:21:18 +02:00
ItsTripleSix
d0b633fa17
chore: bump ShiggyCord version to 1.4.1.8 2026-09-10 16:10:48 -06:00
ItsTripleSix
9dfe5ca671
fix: prevent account-switch cold launch splash hang 2026-09-10 16:09:53 -06:00
OTKUSteyler
bdb448eb94
Update index.ts 2026-09-09 08:39:24 +02:00
OTKUSteyler
2c91da18ea
Update index.ts 2026-09-09 08:38:39 +02:00
OTKUSteyler
1d630e1e3a
Update PluginCard.tsx 2026-09-05 16:47:28 +02:00
OTKUSteyler
2c0c24cb86
Update index.ts 2026-09-04 20:36:27 +02:00
OTKUSteyler
a42fb7ce36
Update About.tsx 2026-09-04 15:17:42 +02:00
OTKUSteyler
f48aea843f
Update debug.ts 2026-09-03 21:50:47 +02:00
OTKUSteyler
8430031566
Update reload.ts 2026-09-03 21:10:07 +02:00
OTKUSteyler
fa8ebe30bd
Update debug.ts 2026-09-03 21:09:44 +02:00
OTKUSteyler
e6e5728d25
Update index.ts 2026-09-03 20:43:33 +02:00
OTKUSteyler
5f41539026
Update index.tsx 2026-09-03 20:37:21 +02:00
OTKUSteyler
1b99480b82
Update build.mjs 2026-09-03 18:03:48 +02:00
OTKUSteyler
151b07434e
Update package.json 2026-09-03 18:02:28 +02:00
OTKUSteyler
11a6e4d1c4
Update package.json 2026-09-03 18:00:03 +02:00
OTKUSteyler
cbcbd53cc0
Add files via upload 2026-09-03 17:15:26 +02:00
OTKUSteyler
d26de6be8e
Update index.ts 2026-09-03 17:14:22 +02:00
OTKUSteyler
b51ae0677d
Update index.tsx 2026-09-03 17:13:38 +02:00
OTKUSteyler
5cdb7d9969
Update index.ts 2026-09-03 17:13:09 +02:00
OTKUSteyler
687f47318b
Update default.json 2026-09-03 17:12:03 +02:00
OTKUSteyler
1071349bbc
Add files via upload 2026-09-03 17:10:56 +02:00
OTKUSteyler
72ce900cd8
Update README.md 2026-09-03 17:09:30 +02:00
OTKUSteyler
ecef05061b
Update release.yml 2026-09-03 16:04:20 +02:00
kmmiio99o
15915a08b9
chore: update embed URLs for Instagram and Reddit 2026-09-02 19:41:07 +00:00
kmmiio99o
ad46e065c9
Merge branch 'C0C0B01:main' into main 2026-08-27 13:23:18 +02:00
cocobo1
f5bbcecade Merge pull request 'fix: properly resolve design components' (#31) from Purple-EyeZ/Kettu:dev into dev
Reviewed-on: https://codeberg.org/cocobo1/Kettu/pulls/31
2026-08-27 09:08:29 +02:00
kmmiio99o
3f5643931c
Merge branch 'dev' 2026-08-27 00:39:25 +02:00
Purple_Ξye™
28fe79ade4
fix: properly resolve design components (#12) 2026-08-27 00:33:00 +02:00
Purple_Ξye™
5858340d04 fix: properly resolve design components 2026-08-26 23:36:44 +02:00
15 changed files with 111 additions and 301 deletions

View file

@ -1,9 +1,9 @@
{
"name": "ShiggyCord",
"name": "GoonCord",
"private": true,
"author": {
"name": "kmmiio99o",
"url": "https://github.com/kmmiio99o"
"name": "OTKUSteyler",
"url": "https://github.com/OTKUSteyler"
},
"scripts": {
"build": "node scripts/build.mjs",

View file

@ -77,7 +77,7 @@ const config = {
constModules: {
globals: {
"bunny-build-info": {
version: `"1.4.1.7"`,
version: `"1.4.1.8"`,
},
},
},

View file

@ -18,16 +18,20 @@ export default () =>
},
],
execute([ephemeral], ctx) {
const info = getDebugInfo();
const content = [
"**💦GoonCord💦 Debug Info**",
`> 💦GoonCord💦: ${info.bunny.version} (${info.bunny.loader.name} ${info.bunny.loader.version})`,
`> Discord: ${info.discord.version} (${info.discord.build})`,
`> React: ${info.react.version} (RN ${info.react.nativeVersion})`,
`> Hermes: ${info.hermes.version} (bcv${info.hermes.bytecodeVersion})`,
`> System: ${info.os.name} ${info.os.version} ${info.os.sdk ? `(SDK ${info.os.sdk})` : ""}`.trimEnd(),
`> Device: ${info.device.model}`,
].join("\n");
const info = getDebugInfo();
if(info.device.codename === undefined) { info.device.codename = ""}
else{ info.device.codename = "(" + info.device.codename + ")" }
const content = [
"**💦GoonCord💦 Debug Info**",
`> GoonCord: ${info.bunny.version} (${info.bunny.loader.name} ${info.bunny.loader.version})`,
`> Discord: ${info.discord.version} (${info.discord.build})`,
`> React: ${info.react.version} (RN ${info.react.nativeVersion})`,
`> Hermes: ${info.hermes.version} (bcv${info.hermes.bytecodeVersion})`,
`> System: ${info.os.name} ${info.os.version} ${info.os.sdk ? `(SDK ${info.os.sdk})` : ""}`.trimEnd(),
`> Device: ${info.device.model} ${info.device.codename}`,
].join("\n");
if (ephemeral?.value) {
messageUtil.sendBotMessage(ctx.channel.id, content);

View file

@ -1,112 +0,0 @@
import { instead } from "@lib/api/patcher";
import { logger } from "@lib/utils/logger";
import { _lazyContextSymbol } from "@metro/lazy";
import { requireModule } from "@metro/internals/modules";
import { LazyModuleContext } from "@metro/types";
import { findByNameLazy } from "@metro/wrappers";
function log(...messages: any[]) {
try {
logger.warn("[ShiggyCord] patchAnimatedValue:", ...messages);
} catch {}
}
/**
* Discord's bundled React Native throws `AnimatedValue: Attempting to set value
* to undefined` when a `undefined` value reaches an `Animated.Value` — either
* through `setValue()` (which calls `_updateValue`) or through the constructor.
* Some of Discord's own flows (and third-party plugins) hit this during
* animation setup, which bubbles up to the React ErrorBoundary and makes
* ShiggyCord render its custom crash screen.
*
* Fix the root cause instead of masking the symptom:
* - `_updateValue` is a prototype method, so one patch covers every instance no
* matter which module captured the class reference.
* - The constructor is guarded by swapping the public `Animated.Value`
* reference (and the module's `default` export) for a patched proxy so that
* `new Animated.Value(undefined)` can no longer throw.
*/
export default function patchAnimatedValue() {
const unpatchers: Array<() => boolean> = [];
const install = (Class: any, source: string) => {
try {
if (
!Class?.prototype ||
typeof Class.prototype._updateValue !== "function"
) {
log(`${source}: resolved value is not AnimatedValue, skipping`);
return;
}
// setValue(undefined) → _updateValue(undefined). Keep the last value.
unpatchers.push(
instead(
"_updateValue",
Class.prototype,
function (this: any, args: any[], origFunc: Function) {
if (args[0] === undefined) args[0] = this?._value ?? 0;
return origFunc(...args);
},
),
);
// Constructor guard: coerce non-number to 0 so `new Animated.Value(undefined)` can't throw.
const guard = (args: any[], origFunc: Function) => {
if (typeof args[0] !== "number") args[0] = 0;
return origFunc(...args);
};
// 1. Module exports (`require(...).default`).
try {
const ctxt: LazyModuleContext | undefined =
findByNameLazy("AnimatedValue")[_lazyContextSymbol];
if (ctxt?.moduleId != null) {
const moduleExports = requireModule(ctxt.moduleId);
if (moduleExports?.default === Class) {
unpatchers.push(instead("default", moduleExports, guard));
}
}
} catch {}
// 2. The public `Animated.Value` namespace reference.
try {
const ReactNative: any = require("react-native");
const Animated = ReactNative?.Animated;
if (Animated && Animated.Value === Class) {
unpatchers.push(instead("Value", Animated, guard));
}
} catch {}
log(`${source}: patched _updateValue + constructor guard`);
} catch (e) {
log(`${source}: patch failed`, e);
}
};
// Primary: Discord's own RN Animated namespace (most reliable, no full scan).
try {
const ReactNative: any = require("react-native");
install(ReactNative?.Animated?.Value, "react-native.Animated.Value");
if (unpatchers.length > 0) {
return () => unpatchers.forEach((unpatch) => unpatch());
}
} catch (e) {
log("react-native.Animated path failed", e);
}
// Fallback: byName lookup.
try {
const ctxt: LazyModuleContext =
findByNameLazy("AnimatedValue")[_lazyContextSymbol];
if (ctxt) {
ctxt.getExports((Class: any) => install(Class, "findByNameLazy"));
} else {
log("no lazy context found");
}
} catch (e) {
log("findByNameLazy path failed", e);
}
return () => unpatchers.forEach((unpatch) => unpatch());
}

View file

@ -1,141 +0,0 @@
import React from "react";
import { View } from "react-native";
import { byProps } from "@metro/filters";
import { findExports } from "@metro/finders";
import { findByStoreNameLazy } from "@metro/wrappers";
import { instead } from "@lib/api/patcher";
import { logger } from "@lib/utils/logger";
import { isSemanticColor, resolveSemanticColor, semanticColors } from "@ui/color";
const ThemeStore = findByStoreNameLazy("ThemeStore");
function log(...messages: any[]) {
try {
logger.warn("[ShiggyCord] patchSafeCard:", ...messages);
} catch {}
}
let cardHealthy = false;
const FALLBACK_STYLE = {
borderRadius: 8,
padding: 16,
};
function resolveCardBackground(): string | undefined {
try {
const color = semanticColors?.CARD_BACKGROUND_DEFAULT;
if (isSemanticColor(color)) return resolveSemanticColor(color);
if (typeof color === "string") return color;
} catch {}
return undefined;
}
export default function patchSafeCard() {
const unpatchers: Array<() => boolean> = [];
try {
const cardModule = findExports(byProps("Card"));
const origCard = cardModule?.Card;
if (typeof origCard !== "function") {
log("no Card function on the resolved module, skipping");
return () => unpatchers.forEach((unpatch) => unpatch());
}
log("resolved design Card from first-match module");
let cardBackground = resolveCardBackground();
const unsubscribeTheme = ThemeStore?.addChangeListener?.(() => {
const resolved = resolveCardBackground();
if (resolved) cardBackground = resolved;
});
if (typeof unsubscribeTheme === "function") {
unpatchers.push(() => {
unsubscribeTheme();
return true;
});
}
class CardProbeBoundary extends React.Component<
{
fallback: React.ReactNode;
children?: React.ReactNode;
},
{ hasError: boolean }
> {
state = { hasError: false };
static getDerivedStateFromError() {
return { hasError: true };
}
componentDidCatch(error: unknown) {
try {
log("Card render threw, using View fallback", error);
} catch {}
}
render() {
if (this.state.hasError) return this.props.fallback;
return this.props.children;
}
}
class HealthyProbe extends React.Component<{
onHealthy: () => void;
children?: React.ReactNode;
}> {
componentDidMount() {
this.props.onHealthy();
}
render() {
return this.props.children;
}
}
const SafeCard = function SafeCard(props: any) {
if (cardHealthy) return React.createElement(origCard, props);
return React.createElement(
CardProbeBoundary,
{
fallback: React.createElement(
View,
{
style: [
FALLBACK_STYLE,
...(cardBackground
? [{ backgroundColor: cardBackground }]
: []),
props?.style,
],
},
props?.children,
),
},
React.createElement(
HealthyProbe,
{
onHealthy: () => {
cardHealthy = true;
},
},
React.createElement(origCard, props),
),
);
};
unpatchers.push(
instead("Card", cardModule, (args: any[]) => SafeCard(args[0] ?? {})),
);
log("patched design Card (adaptive probe on first mount)");
} catch (e) {
log("patch failed", e);
}
return () => unpatchers.forEach((unpatch) => unpatch());
}

View file

@ -11,7 +11,7 @@
"IMAGE_FILES": "Image Files",
"TEXT_FILES": "Text Files",
"BRAND": "Brand",
"SHIGGYCORD": "💦GoonCord💦",
"SHIGGYCORD": "GoonCord",
"SHIGGYCORD_URL": "GoonCord URL",
"BROWSER": "Browser",
"BYTECODE": "Bytecode",
@ -94,7 +94,7 @@
"PLUGINS": "Plugins",
"REFETCH": "Refetch",
"RELOAD": "Reload",
"RELOAD_DISCORD": "💦ReGoon💦 your Discord",
"RELOAD_DISCORD": "ReGoon your Discord",
"RELOAD_IN_NORMAL_MODE": "Reload in Normal Mode",
"RELOAD_IN_NORMAL_MODE_DESC": "Safe mode currently enabled, tap to reload in normal mode",
"RELOAD_IN_SAFE_MODE": "Reload in Safe Mode",

View file

@ -11,7 +11,7 @@ const { TableRowGroup, TableRow, TableSwitchRow, Stack } = findByProps(
"TableSwitchRow",
"Stack",
);
const { ScrollView, Text, Linking } = require("react-native");
const { ScrollView, Text } = require("react-native");
type FixEmbedSettings = {
twitter: boolean;
@ -45,11 +45,11 @@ function transformLinks(content: string, config: FixEmbedSettings): string {
"https://kkinstagram.com$1",
);
}
// TikTok: Replace domain, keep path (use embedez.com for all TikTok links)
// TikTok: Replace domain, keep path
if (config.tiktok) {
result = result.replace(
/https?:\/\/(?:www\.)?tiktok\.com(\/[^\s]+)/gi,
"https://embedez.com$1",
"https://tiktokez.com$1",
);
// TikTok short links (vm.tiktok.com)
result = result.replace(
@ -99,6 +99,7 @@ export default defineCorePlugin({
setConfig((prev) => ({ ...prev, [key]: value }));
};
// Prefer table-style rows (TableRowGroup / TableSwitchRow) and Stack layout similar to other core plugins.
const {
TableRowGroup: _TRG,
TableRow: _TR,
@ -106,6 +107,7 @@ export default defineCorePlugin({
Stack: _S,
} = findByProps("TableRowGroup", "TableRow", "TableSwitchRow", "Stack");
// Fallback if the table-style components are not available in the host environment
if (!_TRG || !_TSR || !_TR || !_S) {
return React.createElement(
ScrollView,
@ -118,6 +120,7 @@ export default defineCorePlugin({
);
}
// Use the resolved components
const TableRowGroup = _TRG;
const TableRow = _TR;
const TableSwitchRow = _TSR;
@ -161,12 +164,6 @@ export default defineCorePlugin({
"This plugin automatically converts social media links to privacy-friendly alternative frontends for better embeds.",
disabled: true,
}),
React.createElement(TableRow, {
label: "EmbedEZ",
subLabel: "TikTok embed fix powered by embedez.com — tap to open",
onPress: () => Linking.openURL("https://embedez.com/"),
arrow: true,
}),
),
),
]);

View file

@ -97,7 +97,7 @@ export default function About() {
variant="text-md/medium"
style={{ textAlign: "center", marginTop: 4 }}
>
💦Goon your discord client💦!
💦Goon💦 your discord client!
</Text>
</View>

View file

@ -125,7 +125,7 @@ export default function General() {
>
<TableRowGroup title="App Information">
<TableRow
label="💦GoonCord💦"
label="GoonCord"
icon={<TableRow.Icon source={{ uri: shiggycordIcon ?? "" }} />}
trailing={<TableRow.TrailingText text={debugInfo.bunny.version} />}
/>

View file

@ -11,7 +11,7 @@ async function initializeShiggyCord() {
Object.freeze = Object.seal = Object;
await require("@metro/internals/caches").initMetroCache();
await require(".").default();
require(".").default();
} catch (e) {
const { ClientInfoManager } = require("@lib/api/native/modules");
const stack = e instanceof Error ? e.stack : undefined;

View file

@ -1,6 +1,4 @@
import patchAnimatedValue from "@core/debug/patches/patchAnimatedValue";
import patchErrorBoundary from "@core/debug/patches/patchErrorBoundary";
import patchSafeCard from "@core/debug/patches/patchSafeCard";
import initFixes from "@core/fixes";
import { initFetchI18nStrings } from "@core/i18n";
import initSettings from "@core/ui/settings";
@ -32,8 +30,6 @@ export default async () => {
["patchCommands", () => patchCommands()],
["patchJsx", () => patchJsx()],
["patchErrorBoundary", () => patchErrorBoundary()],
["patchAnimatedValue", () => patchAnimatedValue()],
["patchSafeCard", () => patchSafeCard()],
["initVendettaObject", () => initVendettaObject()],
["initFetchI18nStrings", () => initFetchI18nStrings()],
["initSettings", () => initSettings()],
@ -92,5 +88,5 @@ export default async () => {
}
// Final ready log for basic UI availability.
logger.log("GoonCord is ready.");
logger.log("ShiggyCord is ready.");
};

View file

@ -40,19 +40,55 @@ export function updateBunnyColor(colorManifest: ColorManifest | null, { update =
});
if (internalDef != null) {
tokenRef.Theme[ref.key.toUpperCase()] = ref.key;
FormDivider.DIVIDER_COLORS[ref.key] = FormDivider.DIVIDER_COLORS[ref.current!.reference];
// Register the synthetic key BEFORE calling native, and verify it actually
// landed in every table native reads from. If any registration step fails,
// bail out to a known-good theme instead of handing native an unknown key.
try {
tokenRef.Theme[ref.key.toUpperCase()] = ref.key;
Object.keys(tokenRef.Shadow).forEach(k => tokenRef.Shadow[k][ref.key] = tokenRef.Shadow[k][ref.current!.reference]);
Object.keys(tokenRef.SemanticColor).forEach(k => {
tokenRef.SemanticColor[k][ref.key] = {
...tokenRef.SemanticColor[k][ref.current!.reference]
};
});
if (!FormDivider.DIVIDER_COLORS[ref.current!.reference]) {
throw new Error(`Missing divider color reference: ${ref.current!.reference}`);
}
FormDivider.DIVIDER_COLORS[ref.key] = FormDivider.DIVIDER_COLORS[ref.current!.reference];
Object.keys(tokenRef.Shadow).forEach(k => {
if (!(ref.current!.reference in tokenRef.Shadow[k])) {
throw new Error(`Missing shadow reference: ${ref.current!.reference}`);
}
tokenRef.Shadow[k][ref.key] = tokenRef.Shadow[k][ref.current!.reference];
});
Object.keys(tokenRef.SemanticColor).forEach(k => {
if (!(ref.current!.reference in tokenRef.SemanticColor[k])) {
throw new Error(`Missing semantic color reference: ${ref.current!.reference}`);
}
tokenRef.SemanticColor[k][ref.key] = {
...tokenRef.SemanticColor[k][ref.current!.reference]
};
});
} catch (e) {
console.error("Failed to register custom theme key, falling back", e);
ref.current = null; // force fallback path below
}
}
if (update) {
AppearanceManager.setShouldSyncAppearanceSettings(false);
AppearanceManager.updateTheme(internalDef != null ? ref.key : ref.lastSetDiscordTheme);
const targetTheme = ref.current != null ? ref.key : ref.lastSetDiscordTheme;
// This is the actual crash site: a raw call into native code with no
// guard. Wrap it so a native-side rejection can't take the whole
// bridge/thread down — fall back to the last known-good Discord theme.
try {
AppearanceManager.updateTheme(targetTheme);
} catch (e) {
console.error(`Native rejected theme "${targetTheme}", reverting to "${ref.lastSetDiscordTheme}"`, e);
try {
AppearanceManager.updateTheme(ref.lastSetDiscordTheme);
} catch (e2) {
console.error("Fallback theme also failed to apply", e2);
}
}
}
}

View file

@ -1,49 +1,64 @@
import { ImageLoader } from "./";
import type { LoaderPayload } from "./types";
type InteropReturn = Promise<{ ret: string } | { err: string } | { cancelled: true; reason: string }>;
export const loaderPayload = window.__PYON_LOADER__ as LoaderPayload;
export function isModuleRegistered(module: string) {
return loaderPayload.loader.modules[module] !== undefined;
}
export function isFunctionRegistered(module: string, function_: string) {
return loaderPayload.loader.modules[module]?.functions[function_] !== undefined;
}
export async function callFunction(module: string, functionName: string, args: unknown[]) {
if (!isFunctionRegistered(module, functionName)) {
throw new Error(`Function ${module}.${functionName} is not registered`);
}
const promise: InteropReturn = ImageLoader.queryCache([
"__pyon_bridge",
JSON.stringify({ m: module, f: functionName, a: args }),
]);
const result = await promise;
if ("ret" in result) {
return JSON.parse(result.ret);
}
if ("cancelled" in result) {
throw new Error(`Function ${module}.${functionName} was cancelled: ${result.reason}`);
}
if ("err" in result) {
throw new Error(result.err);
}
}
export interface LoaderModule {
hasFunction(functionName: string): boolean;
callFunction(functionName: string, args: unknown[]): Promise<unknown>;
}
type ModuleProps<T extends LoaderModule> = {
name: string;
argumentProcessors?: Partial<{ [key in keyof T]: (args: any[]) => any[] }>;
};
export function getModule<T extends LoaderModule>({ name, argumentProcessors: processArgs }: ModuleProps<T>) {
const module = loaderPayload.loader.modules[name];
if (!module) {
throw new Error(`Module ${name} is not registered`);
}
const baseObject: Record<string, any> = {
hasFunction: (functionName: string) => isFunctionRegistered(name, functionName),
callFunction: (functionName: string, args: unknown[]) => callFunction(name, functionName, args),
};
for (const [functionName] of Object.entries(module.functions)) {
baseObject[functionName] = (...args: unknown[]) =>
callFunction(
@ -53,8 +68,10 @@ export function getModule<T extends LoaderModule>({ name, argumentProcessors: pr
processArgs && functionName in processArgs ? processArgs[functionName](args) : args,
);
}
return baseObject as T;
}
/**
* Determines if safe mode is currently enabled. The result remains consistent over time.
* This will not change until the app is restarted. For draft changes, use the InitConfigStore.

View file

@ -1,49 +1,64 @@
import { ImageLoader } from "./";
import type { LoaderPayload } from "./types";
type InteropReturn = Promise<{ ret: string } | { err: string } | { cancelled: true; reason: string }>;
export const loaderPayload = window.__PYON_LOADER__ as LoaderPayload;
export function isModuleRegistered(module: string) {
return loaderPayload.loader.modules[module] !== undefined;
}
export function isFunctionRegistered(module: string, function_: string) {
return loaderPayload.loader.modules[module]?.functions[function_] !== undefined;
}
export async function callFunction(module: string, functionName: string, args: unknown[]) {
if (!isFunctionRegistered(module, functionName)) {
throw new Error(`Function ${module}.${functionName} is not registered`);
}
const promise: InteropReturn = ImageLoader.queryCache([
"__pyon_bridge",
JSON.stringify({ m: module, f: functionName, a: args }),
]);
const result = await promise;
if ("ret" in result) {
return JSON.parse(result.ret);
}
if ("cancelled" in result) {
throw new Error(`Function ${module}.${functionName} was cancelled: ${result.reason}`);
}
if ("err" in result) {
throw new Error(result.err);
}
}
export interface LoaderModule {
hasFunction(functionName: string): boolean;
callFunction(functionName: string, args: unknown[]): Promise<unknown>;
}
type ModuleProps<T extends LoaderModule> = {
name: string;
argumentProcessors?: Partial<{ [key in keyof T]: (args: any[]) => any[] }>;
};
export function getModule<T extends LoaderModule>({ name, argumentProcessors: processArgs }: ModuleProps<T>) {
const module = loaderPayload.loader.modules[name];
if (!module) {
throw new Error(`Module ${name} is not registered`);
}
const baseObject: Record<string, any> = {
hasFunction: (functionName: string) => isFunctionRegistered(name, functionName),
callFunction: (functionName: string, args: unknown[]) => callFunction(name, functionName, args),
};
for (const [functionName] of Object.entries(module.functions)) {
baseObject[functionName] = (...args: unknown[]) =>
callFunction(
@ -53,8 +68,10 @@ export function getModule<T extends LoaderModule>({ name, argumentProcessors: pr
processArgs && functionName in processArgs ? processArgs[functionName](args) : args,
);
}
return baseObject as T;
}
/**
* Determines if safe mode is currently enabled. The result remains consistent over time.
* This will not change until the app is restarted. For draft changes, use the InitConfigStore.
@ -62,4 +79,4 @@ export function getModule<T extends LoaderModule>({ name, argumentProcessors: pr
*/
export function isSafeModeEnabled() {
return Boolean(loaderPayload.loader.initConfig.safeMode);
}
}

View file

@ -117,17 +117,13 @@ for (const [id, moduleExports] of cacher.getModules()) {
}
const exportsKeysLength = Reflect.ownKeys(actualExports).length;
if (_source[prop] && exportsKeysLength >= _source[prop]) {
if (_source[prop] && exportsKeysLength <= _source[prop]) {
continue;
}
_module[prop] = actualExports[prop];
_source[prop] = Reflect.ownKeys(actualExports).length;
cacher.cacheId(id);
if (exportsKeysLength === 1) {
redesignProps.delete(prop);
}
}
}