Skip to content

Commit

Permalink
[dev] half-baked rdt support
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Apr 16, 2024
1 parent a4f64d9 commit 6527060
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/core/i18n/default.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"ABOUT": "About",
"PLUGIN_REFETCH_SUCCESSFUL": "Successfully refetched plugin!",
"PLUGIN_REFETCH_FAILED": "Failed to refetch plugin!",
"ACTIONS": "Actions",
"ARE_YOU_SURE_TO_CLEAR_DATA": "Are you sure you wish to clear the data of {name}?",
"ARE_YOU_SURE_TO_DELETE_PLUGIN": "Are you sure you wish to delete {name}? This will clear all of the plugin's data.",
Expand Down Expand Up @@ -47,6 +45,7 @@
"INSTALL": "Install",
"INSTALL_ADDON": "Install Add-on",
"INSTALL_PLUGIN": "Install Plugin",
"INSTALL_REACT_DEVTOOLS": "Install React DevTools",
"INSTALL_THEME": "Install Theme",
"LINKS": "Links",
"LOAD_FROM_CUSTOM_URL": "Load from custom url",
Expand All @@ -65,8 +64,9 @@
"OPEN_IN_BROWSER": "Open in Browser",
"OPERATING_SYSTEM": "Operating System",
"OVERFLOW_PLUGIN_SETTINGS": "Plugin settings",
"TOASTS_PLUGIN_UPDATE": "{update, select, true {Enabled} false {Disabled}} updates for {name}.",
"PLATFORM": "Platform",
"PLUGIN_REFETCH_FAILED": "Failed to refetch plugin!",
"PLUGIN_REFETCH_SUCCESSFUL": "Successfully refetched plugin!",
"PLUGINS": "Plugins",
"REFETCH": "Refetch",
"RELOAD": "Reload",
Expand All @@ -75,6 +75,7 @@
"RELOAD_IN_NORMAL_MODE_DESC": "This will reload Discord normally",
"RELOAD_IN_SAFE_MODE": "Reload in Safe Mode",
"RELOAD_IN_SAFE_MODE_DESC": "This will reload Discord without loading addons",
"RESTART_REQUIRED_TO_TAKE_EFFECT": "Restart required to take effect",
"RETRY": "Retry",
"RETRY_RENDER": "Retry Render",
"SAFE_MODE": "Safe Mode",
Expand All @@ -90,6 +91,7 @@
"THEMES": "Themes",
"THEMES_RELOAD_FOR_CHANGES": "Reload the app to fully apply changes!",
"TOASTS_INSTALLED_PLUGIN": "Installed plugin",
"TOASTS_PLUGIN_UPDATE": "{update, select, true {Enabled} false {Disabled}} updates for {name}.",
"UH_OH": "Uh oh.",
"UNINSTALL": "Uninstall",
"UNINSTALL_TITLE": "Uninstall {title}",
Expand Down
51 changes: 48 additions & 3 deletions src/core/ui/settings/pages/Developer.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { Strings } from "@core/i18n";
import AssetBrowser from "@core/ui/settings/pages/AssetBrowser";
import { getAssetIDByName } from "@lib/api/assets";
import { getReactDevToolsProp, getReactDevToolsVersion, isLoaderConfigSupported, isReactDevToolsPreloaded } from "@lib/api/native/loader";
import { fileExists, removeFile, writeFile } from "@lib/api/native/fs";
import { getReactDevToolsProp, getReactDevToolsVersion, isLoaderConfigSupported, isReactDevToolsPreloaded, isVendettaLoader } from "@lib/api/native/loader";
import { useProxy } from "@lib/api/storage";
import { connectToDebugger } from "@lib/debug";
import { loaderConfig, settings } from "@lib/settings";
import { FormText } from "@lib/ui/components/discord/Forms";
import { Stack, TableRow, TableRowGroup, TableSwitchRow, TextInput } from "@lib/ui/components/discord/Redesign";
import { Button, Stack, TableRow, TableRowGroup, TableSwitchRow, TextInput } from "@lib/ui/components/discord/Redesign";
import { NavigationNative } from "@metro/common";
import { findByProps } from "@metro/filters";
import { semanticColors } from "@ui/color";
import { ErrorBoundary } from "@ui/components";
import { createStyles, TextStyleSheet } from "@ui/styles";
import { useState } from "react";
import { ScrollView, StyleSheet } from "react-native";

const { hideActionSheet } = findByProps("openLazy", "hideActionSheet");
const { showSimpleActionSheet } = findByProps("showSimpleActionSheet");

const RDT_EMBED_LINK = "https://raw.githubusercontent.com/amsyarasyiq/rdt-embedder/main/dist.js";

const useStyles = createStyles({
leadingText: {
...TextStyleSheet["heading-md/semibold"],
Expand All @@ -26,6 +30,16 @@ const useStyles = createStyles({
});

export default function Developer() {
const [rdtEmbedded, setRdtEmbedded] = useState(false);
const [rdtDownloading, setRdtDownloading] = useState(true);

React.useEffect(() => {
fileExists("preloads/reactDevtools.js").then(exists => {
setRdtEmbedded(exists);
setRdtDownloading(false);
});
}, []);

const styles = useStyles();
const navigation = NavigationNative.useNavigation();

Expand Down Expand Up @@ -79,7 +93,7 @@ export default function Developer() {
placeholder="http://localhost:4040/vendetta.js"
label={Strings.BUNNY_URL}
/>} />}
{isReactDevToolsPreloaded() && <TableSwitchRow
{isReactDevToolsPreloaded() && isVendettaLoader() && <TableSwitchRow
label={Strings.LOAD_REACT_DEVTOOLS}
subLabel={`${Strings.VERSION}: ${getReactDevToolsVersion()}`}
icon={<TableRow.Icon source={getAssetIDByName("ic_badge_staff")} />}
Expand Down Expand Up @@ -120,6 +134,37 @@ export default function Developer() {
],
})}
/>
<TableRow
label={Strings.INSTALL_REACT_DEVTOOLS}
subLabel={Strings.RESTART_REQUIRED_TO_TAKE_EFFECT}
icon={<TableRow.Icon source={getAssetIDByName("DownloadIcon")} />}
trailing={
<Button
size="sm"
loading={rdtDownloading}
disabled={rdtDownloading}
variant={rdtEmbedded ? "secondary" : "primary"}
text={rdtEmbedded ? Strings.UNINSTALL : Strings.INSTALL}
onPress={async () => {
if (!rdtEmbedded) {
setRdtDownloading(true);
const res = await fetch(RDT_EMBED_LINK);
const bundle = await res.text();
await writeFile("preloads/reactDevtools.js", bundle);
setRdtDownloading(false);
setRdtEmbedded(true);
} else {
setRdtDownloading(true);
await removeFile("preloads/reactDevtools.js");
setRdtEmbedded(false);
setRdtDownloading(false);
}
}}
icon={getAssetIDByName(rdtEmbedded ? "ic_message_delete" : "DownloadIcon")}
style={{ marginLeft: 8 }}
/>
}
/>
</TableRowGroup>
</Stack>
</ScrollView>
Expand Down
14 changes: 12 additions & 2 deletions src/lib/api/native/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ export function getThemeFilePath() {
}

export function isReactDevToolsPreloaded() {
if (isPyonLoader()) return false;
else if (isVendettaLoader()) {
if (isPyonLoader()) {
return Boolean(window.__reactDevTools);
}
if (isVendettaLoader()) {
return vendettaLoaderIdentity!!.features.devtools != null;
}

Expand All @@ -154,6 +156,11 @@ export function isReactDevToolsPreloaded() {
export function getReactDevToolsProp(): string | null {
if (!isReactDevToolsPreloaded()) return null;

if (isPyonLoader()) {
window.__pyoncord_rdt = window.__reactDevTools.exports;
return "__pyoncord_rdt";
}

if (isVendettaLoader()) {
return vendettaLoaderIdentity!!.features.devtools!!.prop;
}
Expand All @@ -164,6 +171,9 @@ export function getReactDevToolsProp(): string | null {
export function getReactDevToolsVersion() {
if (!isReactDevToolsPreloaded()) return null;

if (isPyonLoader()) {
return window.__reactDevTools.version || null;
}
if (isVendettaLoader()) {
return vendettaLoaderIdentity!!.features.devtools!!.version;
}
Expand Down

0 comments on commit 6527060

Please sign in to comment.