chore: some cleanups

This commit is contained in:
pylixonly 2024-10-13 14:03:20 +08:00
parent dc81e9cfad
commit fd8ddce48b
43 changed files with 127 additions and 151 deletions

View file

@ -1,5 +1,5 @@
import { onJsxCreate } from "@lib/api/react/jsx";
import { after } from "@lib/api/patcher";
import { onJsxCreate } from "@lib/api/react/jsx";
import { findByName } from "@metro";
import { useEffect, useState } from "react";

View file

@ -1,11 +1,11 @@
import { Strings } from "@core/i18n";
import { VdPluginManager } from "@core/vendetta/plugins";
import { useProxy } from "@core/vendetta/storage";
import { installTheme, removeTheme, themes } from "@lib/addons/themes";
import { findAssetId } from "@lib/api/assets";
import { isThemeSupported } from "@lib/api/native/loader";
import { after } from "@lib/api/patcher";
import { useProxy } from "@core/vendetta/storage";
import { installTheme, removeTheme, themes } from "@lib/addons/themes";
import { VD_DISCORD_SERVER_ID, HTTP_REGEX_MULTI, VD_PLUGINS_CHANNEL_ID, VD_THEMES_CHANNEL_ID, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { HTTP_REGEX_MULTI, VD_DISCORD_SERVER_ID, VD_PLUGINS_CHANNEL_ID, VD_PROXY_PREFIX, VD_THEMES_CHANNEL_ID } from "@lib/utils/constants";
import { lazyDestructure } from "@lib/utils/lazy";
import { Button } from "@metro/common/components";
import { findByProps, findByPropsLazy } from "@metro/wrappers";

View file

@ -1,16 +1,16 @@
import { formatString, Strings } from "@core/i18n";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { VdPluginManager } from "@core/vendetta/plugins";
import { installTheme } from "@lib/addons/themes";
import { findAssetId } from "@lib/api/assets";
import { isThemeSupported } from "@lib/api/native/loader";
import { after, instead } from "@lib/api/patcher";
import { installTheme } from "@lib/addons/themes";
import { VD_THEMES_CHANNEL_ID, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { VD_PROXY_PREFIX,VD_THEMES_CHANNEL_ID } from "@lib/utils/constants";
import { lazyDestructure } from "@lib/utils/lazy";
import { channels, url } from "@metro/common";
import { byMutableProp } from "@metro/filters";
import { findExports } from "@metro/finders";
import { findByProps, findByPropsLazy } from "@metro/wrappers";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { showToast } from "@ui/toasts";
const showSimpleActionSheet = findExports(byMutableProp("showSimpleActionSheet"));

View file

@ -1,7 +1,7 @@
import { CardWrapper } from "@core/ui/components/AddonCard";
import { useProxy } from "@core/vendetta/storage";
import { findAssetId } from "@lib/api/assets";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import AlertModal, { AlertActionButton } from "@lib/ui/components/wrappers/AlertModal";
import isValidHttpUrl from "@lib/utils/isValidHttpUrl";
import { lazyDestructure } from "@lib/utils/lazy";

View file

@ -1,9 +1,9 @@
import PyoncordIcon from "@assets/icons/pyoncord.png";
import { Strings } from "@core/i18n";
import { useProxy } from "@core/vendetta/storage";
import { findAssetId } from "@lib/api/assets";
import { isFontSupported, isThemeSupported } from "@lib/api/native/loader";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { registerSection } from "@ui/settings";
import { version } from "bunny-build-info";

View file

@ -1,11 +1,11 @@
import { Strings } from "@core/i18n";
import { CheckState, useFileExists } from "@core/ui/hooks/useFS";
import AssetBrowser from "@core/ui/settings/pages/Developer/AssetBrowser";
import { useProxy } from "@core/vendetta/storage";
import { findAssetId } from "@lib/api/assets";
import { connectToDebugger } from "@lib/api/debug";
import { getReactDevToolsProp, getReactDevToolsVersion, isLoaderConfigSupported, isReactDevToolsPreloaded, isVendettaLoader } from "@lib/api/native/loader";
import { loaderConfig, settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { lazyDestructure } from "@lib/utils/lazy";
import { NavigationNative } from "@metro/common";
import { Button, LegacyFormText, Stack, TableRow, TableRowGroup, TableSwitchRow, TextInput } from "@metro/common/components";

View file

@ -1,15 +1,15 @@
import { Strings } from "@core/i18n";
import { CardWrapper } from "@core/ui/components/AddonCard";
import { findAssetId } from "@lib/api/assets";
import { BundleUpdaterManager } from "@lib/api/native/modules";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { useProxy } from "@core/vendetta/storage";
import { FontDefinition, fonts, selectFont } from "@lib/addons/fonts";
import { findAssetId } from "@lib/api/assets";
import { BundleUpdaterManager } from "@lib/api/native/modules";
import { lazyDestructure } from "@lib/utils/lazy";
import { findByProps } from "@metro";
import { NavigationNative, tokens } from "@metro/common";
import { Button, Card, IconButton, Stack, Text } from "@metro/common/components";
import * as Skia from "@shopify/react-native-skia";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { TextStyleSheet } from "@ui/styles";
import { useMemo } from "react";
import { View } from "react-native";

View file

@ -1,8 +1,8 @@
import { formatString, Strings } from "@core/i18n";
import { findAssetId } from "@lib/api/assets";
import { createProxy, useProxy } from "@core/vendetta/storage";
import { FontDefinition, fonts, removeFont, saveFont, validateFont } from "@lib/addons/fonts";
import { getCurrentTheme } from "@lib/addons/themes";
import { findAssetId } from "@lib/api/assets";
import { safeFetch } from "@lib/utils";
import { NavigationNative } from "@metro/common";
import { ActionSheet, BottomSheetTitleHeader, Button, IconButton, Stack, TableRow, TableRowGroup, Text, TextInput } from "@metro/common/components";

View file

@ -1,9 +1,9 @@
import { Strings } from "@core/i18n";
import AddonPage from "@core/ui/components/AddonPage";
import FontEditor from "@core/ui/settings/pages/Fonts/FontEditor";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { FontDefinition, fonts } from "@lib/addons/fonts";
import { settings } from "@lib/api/settings";
import { NavigationNative } from "@metro/common";
import FontCard from "./FontCard";

View file

@ -1,8 +1,8 @@
import { Strings } from "@core/i18n";
import Version from "@core/ui/settings/pages/General/Version";
import { useProxy } from "@core/vendetta/storage";
import { getDebugInfo } from "@lib/api/debug";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { Stack, TableRowGroup } from "@metro/common/components";
import { Platform, ScrollView } from "react-native";

View file

@ -1,10 +1,10 @@
import { Strings } from "@core/i18n";
import { PyoncordIcon } from "@core/ui/settings";
import About from "@core/ui/settings/pages/General/About";
import { useProxy } from "@core/vendetta/storage";
import { findAssetId } from "@lib/api/assets";
import { getDebugInfo, toggleSafeMode } from "@lib/api/debug";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { DISCORD_SERVER, GITHUB } from "@lib/utils/constants";
import { NavigationNative, url } from "@metro/common";
import { Stack, TableRow, TableRowGroup, TableSwitchRow } from "@metro/common/components";

View file

@ -1,6 +1,6 @@
import { findAssetId } from "@lib/api/assets";
import { installPlugin, isPluginInstalled, uninstallPlugin } from "@lib/addons/plugins";
import { BunnyPluginManifest } from "@lib/addons/plugins/types";
import { findAssetId } from "@lib/api/assets";
import { showToast } from "@lib/ui/toasts";
import { safeFetch } from "@lib/utils";
import { OFFICIAL_PLUGINS_REPO_URL } from "@lib/utils/constants";

View file

@ -5,7 +5,7 @@ import { NavigationNative, tokens } from "@metro/common";
import { Card, IconButton, Stack, TableSwitch, Text } from "@metro/common/components";
import { showSheet } from "@ui/sheets";
import chroma from "chroma-js";
import { createContext, memo, useContext, useMemo } from "react";
import { createContext, useContext, useMemo } from "react";
import { Image, View } from "react-native";
import { UnifiedPluginModel } from "..";

View file

@ -2,33 +2,24 @@ import { Strings } from "@core/i18n";
import AddonPage from "@core/ui/components/AddonPage";
import PluginCard from "@core/ui/settings/pages/Plugins/components/PluginCard";
import { VdPluginManager } from "@core/vendetta/plugins";
import { useProxy } from "@core/vendetta/storage";
import { isCorePlugin, isPluginInstalled, pluginSettings, registeredPlugins } from "@lib/addons/plugins";
import { Author } from "@lib/addons/types";
import { findAssetId } from "@lib/api/assets";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { useObservable } from "@lib/api/storage";
import { showToast } from "@lib/ui/toasts";
import { BUNNY_PROXY_PREFIX, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { lazyDestructure } from "@lib/utils/lazy";
import { findByProps } from "@metro";
import { NavigationNative, tokens } from "@metro/common";
import { Card, FlashList, IconButton, PressableScale, Stack, Text } from "@metro/common/components";
import { NavigationNative } from "@metro/common";
import { Card, FlashList, IconButton, Text } from "@metro/common/components";
import { ComponentProps } from "react";
import { Image, View } from "react-native";
import { View } from "react-native";
import unifyVdPlugin from "./models/vendetta";
import { isCorePlugin, isPluginInstalled, pluginSettings, registeredPlugins } from "@lib/addons/plugins";
import unifyBunnyPlugin from "./models/bunny";
import { createStyles } from "@lib/ui/styles";
import { Author } from "@lib/addons/types";
import unifyVdPlugin from "./models/vendetta";
const useStyles = createStyles({
xButton: {
position: "absolute",
right: 8,
top: 8,
tintColor: tokens.colors.INTERACTIVE_NORMAL
}
});
export interface UnifiedPluginModel {
id: string;
name: string;
@ -89,20 +80,11 @@ export default function Plugins() {
return [...vdPlugins, ...bnPlugins];
}}
ListHeaderComponent={() => {
const styles = useStyles();
const unproxiedPlugins = Object.values(VdPluginManager.plugins).filter(p => !p.id.startsWith(VD_PROXY_PREFIX) && !p.id.startsWith(BUNNY_PROXY_PREFIX));
if (!unproxiedPlugins.length) return null;
return <View style={{ marginVertical: 12, marginHorizontal: 10 }}>
<Card border="strong">
{/* <PressableScale
style={styles.xButton}
onPress={() => {
}}
>
<Image source={findAssetId("XSmallIcon")} />
</PressableScale> */}
<View style={{ flex: 1, justifyContent: "center", alignItems: "center", flexDirection: "row" }}>
<View style={{ gap: 6, flexShrink: 1 }}>
<Text variant="heading-md/bold">Unproxied Plugins Found</Text>

View file

@ -1,8 +1,8 @@
import { disablePlugin, enablePlugin, getId, getPluginSettingsComponent, isPluginEnabled, pluginSettings } from "@lib/addons/plugins";
import { BunnyPluginManifest } from "@lib/addons/plugins/types";
import { useObservable } from "@lib/api/storage";
import { UnifiedPluginModel } from "..";
import { useObservable } from "@lib/api/storage";
export default function unifyBunnyPlugin(manifest: BunnyPluginManifest): UnifiedPluginModel {
return {

View file

@ -1,10 +1,10 @@
import { formatString, Strings } from "@core/i18n";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { VdPluginManager } from "@core/vendetta/plugins";
import { findAssetId } from "@lib/api/assets";
import { purgeStorage } from "@core/vendetta/storage";
import { findAssetId } from "@lib/api/assets";
import { clipboard } from "@metro/common";
import { ActionSheet, ActionSheetRow, Button, TableRow, Text } from "@metro/common/components";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { hideSheet } from "@ui/sheets";
import { showToast } from "@ui/toasts";
import { ScrollView, View } from "react-native";

View file

@ -1,11 +1,11 @@
import { formatString, Strings } from "@core/i18n";
import AddonCard, { CardWrapper } from "@core/ui/components/AddonCard";
import { findAssetId } from "@lib/api/assets";
import { settings } from "@lib/api/settings";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { useProxy } from "@core/vendetta/storage";
import { applyTheme, fetchTheme, removeTheme, selectTheme, Theme, themes } from "@lib/addons/themes";
import { findAssetId } from "@lib/api/assets";
import { settings } from "@lib/api/settings";
import { clipboard } from "@metro/common";
import { showConfirmationAlert } from "@core/vendetta/alerts";
import { showToast } from "@ui/toasts";
function selectAndApply(value: boolean, theme: Theme) {

View file

@ -1,11 +1,11 @@
import { formatString, Strings } from "@core/i18n";
import AddonPage from "@core/ui/components/AddonPage";
import ThemeCard from "@core/ui/settings/pages/Themes/ThemeCard";
import { settings } from "@lib/api/settings";
import { useProxy } from "@core/vendetta/storage";
import { installTheme, Theme, themes } from "@lib/addons/themes";
import { Button } from "@metro/common/components";
import { Author } from "@lib/addons/types";
import { settings } from "@lib/api/settings";
import { Button } from "@metro/common/components";
export default function Themes() {
useProxy(settings);

View file

@ -1,12 +1,13 @@
import * as alerts from "@core/vendetta/alerts";
import * as storage from "@core/vendetta/storage";
import { createStorage } from "@core/vendetta/storage";
import * as themes from "@lib/addons/themes";
import * as assets from "@lib/api/assets";
import * as commands from "@lib/api/commands";
import * as debug from "@lib/api/debug";
import { getVendettaLoaderIdentity, isPyonLoader } from "@lib/api/native/loader";
import patcher from "@lib/api/patcher";
import { loaderConfig, settings } from "@lib/api/settings";
import * as storage from "@core/vendetta/storage";
import { createStorage } from "@core/vendetta/storage";
import * as themes from "@lib/addons/themes";
import * as utils from "@lib/utils";
import { cyrb64Hash } from "@lib/utils/cyrb64";
import { LoggerClass } from "@lib/utils/logger";
@ -14,7 +15,6 @@ import * as metro from "@metro";
import * as common from "@metro/common";
import { Forms } from "@metro/common/components";
import * as commonComponents from "@metro/common/components";
import * as alerts from "@core/vendetta/alerts";
import * as color from "@ui/color";
import * as components from "@ui/components";
import { createThemedStyleSheet } from "@ui/styles";

View file

@ -1,9 +1,9 @@
import { awaitStorage, createMMKVBackend, createStorage, purgeStorage, wrapSync } from "@core/vendetta/storage";
import { Author } from "@lib/addons/types";
import { settings } from "@lib/api/settings";
import { awaitStorage, createMMKVBackend, createStorage, purgeStorage, wrapSync } from "@core/vendetta/storage";
import { safeFetch } from "@lib/utils";
import { BUNNY_PROXY_PREFIX, VD_PROXY_PREFIX } from "@lib/utils/constants";
import { LoggerClass, logger } from "@lib/utils/logger";
import { logger,LoggerClass } from "@lib/utils/logger";
type EvaledPlugin = {
onLoad?(): void;

View file

@ -229,7 +229,7 @@ export const createFileBackend = (file: string, defaultData = {}, migratePromise
await FileManager.writeFile("documents", filePathFixer(file), JSON.stringify(defaultData), "utf8");
return JSON.parse(await FileManager.readFile(path, "utf8"));
},
set: async (data) => {
set: async data => {
await migratePromise;
await FileManager.writeFile("documents", filePathFixer(file), JSON.stringify(data), "utf8");
}

View file

@ -3,38 +3,36 @@ import { initFetchI18nStrings } from "@core/i18n";
import initSettings from "@core/ui/settings";
import { initVendettaObject } from "@core/vendetta/api";
import { VdPluginManager } from "@core/vendetta/plugins";
import { updateFonts } from "@lib/addons/fonts";
import { initPlugins, updatePlugins } from "@lib/addons/plugins";
import { initThemes, patchChatBackground } from "@lib/addons/themes";
import { patchCommands } from "@lib/api/commands";
import { patchLogHook } from "@lib/api/debug";
import { injectFluxInterceptor } from "@lib/api/flux";
import { patchJsx } from "@lib/api/react/jsx";
import { removeFile, writeFile } from "@lib/api/native/fs";
import { writeFile } from "@lib/api/native/fs";
import { isPyonLoader, isThemeSupported } from "@lib/api/native/loader";
import { FileManager } from "@lib/api/native/modules";
import { updateFonts } from "@lib/addons/fonts";
import { initPlugins, registerCorePlugins } from "@lib/addons/plugins";
import { initThemes, patchChatBackground } from "@lib/addons/themes";
import { patchJsx } from "@lib/api/react/jsx";
import { logger } from "@lib/utils/logger";
import initSafeMode from "@ui/safeMode";
import { patchSettings } from "@ui/settings";
import * as lib from "./lib";
export default async () => {
// Themes
if (isThemeSupported()) {
try {
if (isPyonLoader()) {
if (FileManager.removeFile != null) {
removeFile("vendetta_theme.json", "");
} else {
writeFile("vendetta_theme.json", "null", "");
}
}
initThemes();
} catch (e) {
console.error("[Bunny] Failed to initialize themes...", e);
function maybeLoadThemes() {
if (!isThemeSupported()) return;
try {
if (isPyonLoader()) {
writeFile("../vendetta_theme.json", "null");
}
initThemes();
} catch (e) {
console.error("Failed to initialize themes", e);
}
}
export default async () => {
maybeLoadThemes();
// Load everything in parallel
await Promise.all([
@ -49,7 +47,7 @@ export default async () => {
initSettings(),
initFixes(),
initSafeMode(),
registerCorePlugins()
updatePlugins()
]).then(
// Push them all to unloader
u => u.forEach(f => f && lib.unload.push(f))
@ -63,6 +61,7 @@ export default async () => {
.then(u => lib.unload.push(u))
.catch(() => alert("Failed to initialize Vendetta plugins"));
// And then, load Bunny plugins
initPlugins();
// Update the fonts

View file

@ -1,5 +1,5 @@
import { clearFolder, downloadFile, fileExists, removeFile, writeFile } from "@lib/api/native/fs";
import { awaitStorage, createMMKVBackend, createStorage, wrapSync } from "@core/vendetta/storage";
import { clearFolder, downloadFile, fileExists, removeFile, writeFile } from "@lib/api/native/fs";
import { safeFetch } from "@lib/utils";
type FontMap = Record<string, string>;

View file

@ -351,9 +351,24 @@ export function stopPlugin(id: string) {
pluginInstances.delete(id);
}
export async function registerCorePlugins() {
async function updateAllRepository() {
try {
await updateRepository(OFFICIAL_PLUGINS_REPO_URL);
} catch (error) {
console.error("Failed to update official plugins repository", error);
}
await Promise.allSettled(Object.keys(pluginRepositories).map(async repo => {
if (repo !== OFFICIAL_PLUGINS_REPO_URL) {
await updateRepository(repo);
}
}));
}
export async function updatePlugins() {
await awaitStorage(pluginRepositories, pluginSettings);
// Register core plugins
const corePlugins = getCorePlugins();
for (const id in corePlugins) {
const {
@ -370,6 +385,8 @@ export async function registerCorePlugins() {
manifestToId.set(instance.manifest, id);
corePluginInstances.set(id, instance);
}
await updateAllRepository();
}
/**

View file

@ -1,6 +1,6 @@
import { createStorage } from "@core/vendetta/storage";
import { Author } from "@lib/addons/types";
import { Logger } from "@lib/utils/logger";
import { Author } from "../types";
export interface PluginRepo {
[id: string]: {

View file

@ -2,10 +2,11 @@
* Theming system in Bunny is currently a prototype, expect an unreadable theme implementation below
*/
import { awaitStorage, createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@core/vendetta/storage";
import { Author } from "@lib/addons/types";
import { getStoredTheme, getThemeFilePath } from "@lib/api/native/loader";
import { ThemeManager } from "@lib/api/native/modules";
import { after, before, instead } from "@lib/api/patcher";
import { awaitStorage, createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@core/vendetta/storage";
import { findInReactTree, safeFetch } from "@lib/utils";
import { lazyDestructure, proxyLazy } from "@lib/utils/lazy";
import { byMutableProp } from "@metro/filters";
@ -13,7 +14,6 @@ import { createLazyModule } from "@metro/lazy";
import { findByNameLazy, findByProps, findByPropsLazy, findByStoreNameLazy } from "@metro/wrappers";
import chroma from "chroma-js";
import { ImageBackground, Platform, processColor } from "react-native";
import { Author } from "../types";
export interface ThemeData {
name: string;

View file

@ -1,4 +1,4 @@
export interface Author {
name: string;
id: string;
}
}

View file

@ -1,9 +1,9 @@
import { getThemeFromLoader, selectTheme, themes } from "@lib/addons/themes";
import { findAssetId } from "@lib/api/assets";
import { getLoaderName, getLoaderVersion, isThemeSupported } from "@lib/api/native/loader";
import { BundleUpdaterManager, ClientInfoManager, DeviceManager } from "@lib/api/native/modules";
import { after } from "@lib/api/patcher";
import { settings } from "@lib/api/settings";
import { getThemeFromLoader, selectTheme, themes } from "@lib/addons/themes";
import { logger } from "@lib/utils/logger";
import { showToast } from "@ui/toasts";
import { version } from "bunny-build-info";

View file

@ -4,6 +4,6 @@ export * as debug from "./debug";
export * as flux from "./flux";
export * as native from "./native";
export * as patcher from "./patcher";
export * as react from "./react";
export * as settings from "./settings";
export * as storage from "./storage";
export * as react from "./react";

View file

@ -4,7 +4,7 @@ import { FileManager } from "./modules";
* Removes all files in a directory from the path given
* @param path Path to the targeted directory
*/
export async function clearFolder(path: string, prefix = "pyoncord/") {
export async function clearFolder(path: string, { prefix = "pyoncord/" } = {}) {
if (typeof FileManager.clearFolder !== "function") throw new Error("'fs.clearFolder' is not supported");
return void await FileManager.clearFolder("documents", `${prefix}${path}`);
}
@ -13,7 +13,7 @@ export async function clearFolder(path: string, prefix = "pyoncord/") {
* Remove file from given path, currently no check for any failure
* @param path Path to the file
*/
export async function removeFile(path: string, prefix = "pyoncord/") {
export async function removeFile(path: string, { prefix = "pyoncord/" } = {}) {
if (typeof FileManager.removeFile !== "function") throw new Error("'fs.removeFile' is not supported");
return void await FileManager.removeFile("documents", `${prefix}${path}`);
}
@ -22,7 +22,7 @@ export async function removeFile(path: string, prefix = "pyoncord/") {
* Check if the file or directory given by the path exists
* @param path Path to the file
*/
export async function fileExists(path: string, prefix = "pyoncord/") {
export async function fileExists(path: string, { prefix = "pyoncord/" } = {}) {
return await FileManager.fileExists(`${FileManager.getConstants().DocumentsDirPath}/${prefix}${path}`);
}
@ -31,7 +31,7 @@ export async function fileExists(path: string, prefix = "pyoncord/") {
* @param path Path to the file
* @param data String data to write to the file
*/
export async function writeFile(path: string, data: string, prefix = "pyoncord/"): Promise<void> {
export async function writeFile(path: string, data: string, { prefix = "pyoncord/" } = {}): Promise<void> {
if (typeof data !== "string") throw new Error("Argument 'data' must be a string");
return void await FileManager.writeFile("documents", `${prefix}${path}`, data, "utf8");
}
@ -41,7 +41,7 @@ export async function writeFile(path: string, data: string, prefix = "pyoncord/"
* @param path Path to the file
* @param fallback Fallback data to return if the file doesn't exist, and will be written to the file
*/
export async function readFile(path: string, prefix = "pyoncord/"): Promise<string> {
export async function readFile(path: string, { prefix = "pyoncord/" } = {}): Promise<string> {
try {
return await FileManager.readFile(`${FileManager.getConstants().DocumentsDirPath}/${prefix}${path}`, "utf8");
} catch (err) {
@ -49,30 +49,19 @@ export async function readFile(path: string, prefix = "pyoncord/"): Promise<stri
}
}
export async function downloadFile(url: string, path: string, prefix = "pyoncord/") {
const blob = await fetch(url).then(r => r.blob());
const dataURL: string | null = await new Promise(r => {
const reader = new FileReader();
reader.onload = () => r(reader.result as unknown as string);
reader.readAsDataURL(blob);
});
let data: string;
if (dataURL == null) {
throw new Error("Failed to convert blob to data URL");
} else {
const index = dataURL.indexOf("base64,");
if (index === -1) throw new Error("dataURL does not contain base64");
data = dataURL.slice(index + 7);
/**
* Download a file from the given URL and save it to the path given
* @param url URL to download the file from
* @param path Path to save the file to
*/
export async function downloadFile(url: string, path: string, { prefix = "pyoncord/" } = {}) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Failed to download file from ${url}: ${response.statusText}`);
}
const arrayBuffer = await response.arrayBuffer();
const data = Buffer.from(arrayBuffer).toString("base64");
return void await FileManager.writeFile("documents", `${prefix}${path}`, data, "base64");
}
// // thanks Rosie, doesnt work though
// export async function downloadFile(url: string, path: string, prefix = "pyoncord/") {
// const arrayBuffer = await fetch(url).then(r => r.arrayBuffer());
// const data = Buffer.from(arrayBuffer).toString("base64");
// return void await FileManager.writeFile("documents", `${prefix}${path}`, data, "base64");
// }

View file

@ -86,4 +86,4 @@ export namespace RNModules {
*/
DocumentsDirPath: string;
}
}
}

View file

@ -1 +1 @@
export * as jsx from "./jsx";
export * as jsx from "./jsx";

View file

@ -1,5 +1,5 @@
import { getLoaderConfigPath } from "@lib/api/native/loader";
import { createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@core/vendetta/storage";
import { getLoaderConfigPath } from "@lib/api/native/loader";
export interface Settings {
debuggerUrl: string;

View file

@ -1,6 +1,6 @@
import { Emitter } from "@core/vendetta/Emitter";
import { Observable, ObserverOptions } from "@gullerya/object-observer";
import { fileExists, readFile, removeFile, writeFile } from "@lib/api/native/fs";
import { Emitter } from "@core/vendetta/Emitter";
import { debounce } from "es-toolkit";
const storageInitErrorSymbol = Symbol.for("bunny.storage.initError");
@ -187,4 +187,4 @@ export function awaitStorage(...proxies: any[]) {
/** @internal */
export function getPreloadedStorage<T extends object = {}>(path: string): T | undefined {
return _loadedStorage[path];
}
}

View file

@ -1,10 +1,10 @@
import "../global.d.ts"; // eslint-disable-line import-alias/import-alias
import "../modules.d.ts"; // eslint-disable-line import-alias/import-alias
export * as api from "./api";
export * as fonts from "./addons/fonts/index.js";
export * as plugins from "./addons/plugins/index.js";
export * as themes from "./addons/themes/index.js";
export * as api from "./api";
export * as ui from "./ui";
export * as utils from "./utils";
export * as metro from "@metro";

View file

@ -1,5 +1,4 @@
export * as wrappers from "./wrappers";
export { default as Codeblock } from "@ui/components/Codeblock";
export { default as ErrorBoundary } from "@ui/components/ErrorBoundary";
export { default as Search } from "@ui/components/Search";

View file

@ -1,34 +1,28 @@
import { lazyDestructure } from "@lib/utils/lazy";
import { findByProps } from "@metro";
import { findByFilePath, findByProps } from "@metro";
import { Text } from "@metro/common/components";
import { Button } from "@metro/common/types/components";
import { ComponentProps, ComponentType, ReactNode } from "react";
import { useWindowDimensions, View } from "react-native";
import { View } from "react-native";
type ActionButtonProps = Omit<ComponentProps<Button>, "onPress"> & {
onPress?: () => void | Promise<unknown>;
};
const {
AlertModal: _AlertModal,
AlertActionButton: _AlertActionButton
} = lazyDestructure(() => findByProps("AlertModal", "AlertActions"));
type ActionButtonProps = Omit<ComponentProps<Button>, "onPress"> & {
onPress?: () => void | Promise<unknown>;
};
export const AlertActionButton = _AlertActionButton as ComponentType<ActionButtonProps>;
export default function AlertModal(props: Record<string, unknown>) {
const { width: windowWidth } = useWindowDimensions();
const forwardFailedModal = findByFilePath("modules/forwarding/native/ForwardFailedAlertModal.tsx");
// ponyfill for extraContent
if ("extraContent" in props) {
if (!forwardFailedModal && "extraContent" in props) {
props.content = (
<View
style={{
/* HACK: the contents are drawn over the padding for some reason, so we set the max width */
maxWidth: windowWidth - 70,
flexShrink: 1, // has no effect but we'll keep it
gap: 16
}}>
<View style={{ gap: 16 }}>
<Text variant="text-md/medium" color="text-muted">
{props.content as string}
</Text>

View file

@ -1,3 +1,3 @@
import AlertModal, { AlertActionButton } from "./AlertModal";
export { AlertModal, AlertActionButton };
export { AlertActionButton, AlertModal };

View file

@ -1,6 +1,6 @@
export * as components from "./components";
export * as settings from "./settings";
export * as sheets from "./sheets";
export * as styles from "./styles";
export * as toasts from "./toasts";
export * as sheets from "./sheets";

View file

@ -1,7 +1,7 @@
import { after } from "@lib/api/patcher";
import { findInReactTree } from "@lib/utils";
import { i18n, NavigationNative } from "@metro/common";
import { LegacyFormIcon, LegacyFormRow, LegacyFormSection, LegacyFormDivider } from "@metro/common/components";
import { LegacyFormDivider,LegacyFormIcon, LegacyFormRow, LegacyFormSection } from "@metro/common/components";
import { findByNameLazy } from "@metro/wrappers";
import { registeredSections } from "@ui/settings";

View file

@ -50,4 +50,4 @@ export default function findInTree(
}: FindInTreeOptions = {},
): any | undefined {
return treeSearch(tree, filter, { walkable, ignore, maxDepth }, 0);
};
}

View file

@ -1,23 +1,20 @@
import * as constants from "./constants";
import cyrb64 from "./cyrb64";
import findInReactTree from "./findInReactTree";
import findInTree from "./findInTree";
import hookDefineProperty from "./hookDefineProperty";
import invariant from "./invariant";
import safeFetch from "./safeFetch";
import * as constants from "./constants";
import * as lazy from "./lazy";
import * as logger from "./logger";
import safeFetch from "./safeFetch";
export {
constants,
cyrb64,
findInReactTree,
findInTree,
hookDefineProperty,
invariant,
safeFetch,
constants,
lazy,
logger
};
logger,
safeFetch };

View file

@ -100,7 +100,6 @@ function onModuleRequire(moduleExports: any, id: Metro.ModuleID) {
patchedNativeComponentRegistry = true;
}
// Hook DeveloperExperimentStore
if (moduleExports?.default?.constructor?.displayName === "DeveloperExperimentStore") {
moduleExports.default = new Proxy(moduleExports.default, {