diff --git a/build.mjs b/build.mjs index 737ba5d..9909af8 100644 --- a/build.mjs +++ b/build.mjs @@ -37,7 +37,7 @@ try { legalComments: "none", alias: { "@*": "src*", - "@types": "src/def.d.ts" + "@types": "src/utils/types.ts" }, plugins: [ { diff --git a/packages/bunny-types/def.tt b/packages/bunny-types/def.tt index 432973b..2700c3a 100644 --- a/packages/bunny-types/def.tt +++ b/packages/bunny-types/def.tt @@ -2,24 +2,32 @@ \import ./index @bunny from BunnyObject { - patcher + api { + commands + native + storage + assets + patcher + } + managers { + plugins + themes + } metro { + filters common } - constants - utils - debug ui { components - toasts alerts - assets + color + toasts } - native - plugins - themes - commands - storage + utils { + constants + types + logger + } + debug settings - loader } \ No newline at end of file diff --git a/src/lib/commands/core/debug.ts b/src/core/commands/debug.ts similarity index 94% rename from src/lib/commands/core/debug.ts rename to src/core/commands/debug.ts index 538f5d4..b5f23c7 100644 --- a/src/lib/commands/core/debug.ts +++ b/src/core/commands/debug.ts @@ -1,7 +1,7 @@ -import { Strings } from "@/lib/i18n"; +import { Strings } from "@/core/i18n"; import { getDebugInfo } from "@lib/debug"; import { messageUtil } from "@metro/common"; -import { ApplicationCommand, ApplicationCommandOptionType } from "../types"; +import { ApplicationCommand, ApplicationCommandOptionType } from "@/lib/api/commands/types"; export default () => { name: "debug", diff --git a/src/lib/commands/core/eval.ts b/src/core/commands/eval.ts similarity index 95% rename from src/lib/commands/core/eval.ts rename to src/core/commands/eval.ts index 5128581..59064ad 100644 --- a/src/lib/commands/core/eval.ts +++ b/src/core/commands/eval.ts @@ -1,7 +1,7 @@ import { findByProps } from "@metro/filters"; import { messageUtil } from "@metro/common"; -import { Strings } from "@/lib/i18n"; -import { ApplicationCommand, ApplicationCommandOptionType } from "../types"; +import { Strings } from "@/core/i18n"; +import { ApplicationCommand, ApplicationCommandOptionType } from "@/lib/api/commands/types"; const util = findByProps("inspect"); const AsyncFunction = (async () => void 0).constructor; diff --git a/src/lib/commands/core/plugins.ts b/src/core/commands/plugins.ts similarity index 91% rename from src/lib/commands/core/plugins.ts rename to src/core/commands/plugins.ts index 01fc038..d7a8c7c 100644 --- a/src/lib/commands/core/plugins.ts +++ b/src/core/commands/plugins.ts @@ -1,7 +1,7 @@ import { messageUtil } from "@metro/common"; -import { plugins as pluginStorage } from "@lib/plugins"; -import { Strings } from "@/lib/i18n"; -import { ApplicationCommand, ApplicationCommandOptionType } from "../types"; +import { plugins as pluginStorage } from "@lib/managers/plugins"; +import { Strings } from "@/core/i18n"; +import { ApplicationCommand, ApplicationCommandOptionType } from "@/lib/api/commands/types"; export default () => { name: "plugins", diff --git a/src/lib/fixes.ts b/src/core/fixes.ts similarity index 92% rename from src/lib/fixes.ts rename to src/core/fixes.ts index b1c2a0e..6b459f7 100644 --- a/src/lib/fixes.ts +++ b/src/core/fixes.ts @@ -1,5 +1,5 @@ import { FluxDispatcher, moment } from "@metro/common"; -import logger from "@lib/logger"; +import logger from "@lib/utils/logger"; function onDispatch({ locale }: { locale: string }) { // Timestamps diff --git a/src/lib/i18n/default.json b/src/core/i18n/default.json similarity index 100% rename from src/lib/i18n/default.json rename to src/core/i18n/default.json diff --git a/src/lib/i18n/index.ts b/src/core/i18n/index.ts similarity index 100% rename from src/lib/i18n/index.ts rename to src/core/i18n/index.ts diff --git a/src/lib/polyfills.ts b/src/core/polyfills.ts similarity index 91% rename from src/lib/polyfills.ts rename to src/core/polyfills.ts index 7c745e6..b3034a1 100644 --- a/src/lib/polyfills.ts +++ b/src/core/polyfills.ts @@ -3,3 +3,6 @@ const allSettledFulfill = (value: T) => ({ status: "fulfilled", value }); const allSettledReject = (reason: T) => ({ status: "rejected", reason }); const mapAllSettled = (item: T) => Promise.resolve(item).then(allSettledFulfill, allSettledReject); export const allSettled = (iterator: T) => Promise.all(Array.from(iterator).map(mapAllSettled)); + +// @ts-ignore +Promise.allSettled ??= allSettled; \ No newline at end of file diff --git a/src/lib/preinit.ts b/src/core/preinit.ts similarity index 87% rename from src/lib/preinit.ts rename to src/core/preinit.ts index c481e34..b48b729 100644 --- a/src/lib/preinit.ts +++ b/src/core/preinit.ts @@ -1,6 +1,6 @@ // Hoist required modules -import { isThemeSupported } from "./loader"; +import { isThemeSupported } from "../lib/api/native/loader"; // This used to be in filters.ts, but things became convoluted const basicFind = (filter: (m: any) => any | string) => { @@ -22,7 +22,7 @@ export const chroma = basicFind(m => m.brewer) as typeof import("chroma-js"); // Themes if (isThemeSupported()) { try { - require("@lib/themes").initThemes(); + require("@lib/managers/themes").initThemes(); } catch (e) { console.error("[Vendetta] Failed to initialize themes...", e); } diff --git a/src/lib/vendettaObject.ts b/src/core/vendettaObject.ts similarity index 94% rename from src/lib/vendettaObject.ts rename to src/core/vendettaObject.ts index da21ab4..771524c 100644 --- a/src/lib/vendettaObject.ts +++ b/src/core/vendettaObject.ts @@ -1,17 +1,17 @@ -import patcher from "@lib/patcher"; -import { getVendettaLoaderIdentity } from "@lib/loader"; -import settings, { loaderConfig } from "@lib/settings"; +import patcher from "@lib/api/patcher"; +import { getVendettaLoaderIdentity } from "@lib/api/native/loader"; +import { settings, loaderConfig } from "@lib/settings"; import * as debug from "@lib/debug"; -import * as plugins from "@lib/plugins"; -import * as themes from "@lib/themes"; -import * as commands from "@lib/commands"; -import * as storage from "@lib/storage"; +import * as plugins from "@lib/managers/plugins"; +import * as themes from "@lib/managers/themes"; +import * as commands from "@/lib/api/commands"; +import * as storage from "@/lib/api/storage"; import * as metro from "@metro/filters"; import * as common from "@metro/common"; import * as components from "@ui/components"; import * as toasts from "@ui/toasts"; import * as alerts from "@ui/alerts"; -import * as assets from "@ui/assets"; +import * as assets from "@/lib/api/assets"; import * as color from "@ui/color"; import * as utils from "@lib/utils"; diff --git a/src/entry.ts b/src/entry.ts index 0340b4d..638212a 100644 --- a/src/entry.ts +++ b/src/entry.ts @@ -14,7 +14,7 @@ const init = (async () => { await import(".").then((m) => m.default()); } catch (e) { - const { ClientInfoManager } = require("@lib/native/modules"); + const { ClientInfoManager } = require("@lib/api/native/modules"); const stack = e instanceof Error ? e.stack : undefined; console.log(stack ?? e?.toString?.() ?? e); diff --git a/src/index.ts b/src/index.ts index 9b5684c..2755e55 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,13 @@ import { patchLogHook } from "@lib/debug"; -import { patchCommands } from "@lib/commands"; -import { initPlugins } from "@lib/plugins"; -import { patchChatBackground } from "@lib/themes"; -import { patchAssets } from "@ui/assets"; +import { patchCommands } from "@/lib/api/commands"; +import { initPlugins } from "@lib/managers/plugins"; +import { patchChatBackground } from "@lib/managers/themes"; +import { patchAssets } from "@/lib/api/assets"; import initQuickInstall from "@ui/quickInstall"; import initSafeMode from "@ui/safeMode"; import initSettings from "@ui/settings"; -import initFixes from "@lib/fixes"; -import logger from "@lib/logger"; +import initFixes from "@/core/fixes"; +import logger from "@lib/utils/logger"; import initWindowObject from "@lib/windowObject"; export default async () => { diff --git a/src/ui/assets.ts b/src/lib/api/assets.ts similarity index 95% rename from src/ui/assets.ts rename to src/lib/api/assets.ts index 11ff78b..431b60f 100644 --- a/src/ui/assets.ts +++ b/src/lib/api/assets.ts @@ -1,5 +1,5 @@ import { assets } from "@metro/common"; -import { after } from "@lib/patcher"; +import { after } from "@lib/api/patcher"; export const all: Record = {}; diff --git a/src/lib/commands/index.ts b/src/lib/api/commands/index.ts similarity index 91% rename from src/lib/commands/index.ts rename to src/lib/api/commands/index.ts index 61566d7..b13b303 100644 --- a/src/lib/commands/index.ts +++ b/src/lib/api/commands/index.ts @@ -1,5 +1,5 @@ import { commands as commandsModule } from "@metro/common"; -import { after } from "@lib/patcher"; +import { after } from "@lib/api/patcher"; import { ApplicationCommand, ApplicationCommandType, ApplicationCommandInputType } from "./types"; let commands: ApplicationCommand[] = []; @@ -11,9 +11,9 @@ export function patchCommands() { // Register core commands [ - require("@lib/commands/core/eval"), - require("@lib/commands/core/debug"), - require("@lib/commands/core/plugins") + require("@/core/commands/eval"), + require("@/core/commands/debug"), + require("@/core/commands/plugins") ].forEach(r => registerCommand(r.default())); return () => { diff --git a/src/lib/commands/types.ts b/src/lib/api/commands/types.ts similarity index 100% rename from src/lib/commands/types.ts rename to src/lib/api/commands/types.ts diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts new file mode 100644 index 0000000..e67ed7f --- /dev/null +++ b/src/lib/api/index.ts @@ -0,0 +1,5 @@ +export * as commands from "./commands"; +export * as native from "./native"; +export * as storage from "./storage"; +export * as assets from "./assets"; +export * as patcher from "./patcher"; \ No newline at end of file diff --git a/src/lib/native/fs.ts b/src/lib/api/native/fs.ts similarity index 98% rename from src/lib/native/fs.ts rename to src/lib/api/native/fs.ts index 6fa1d5b..e4e4ad0 100644 --- a/src/lib/native/fs.ts +++ b/src/lib/api/native/fs.ts @@ -1,4 +1,4 @@ -import { FileManager } from "@lib/native/modules"; +import { FileManager } from "./modules"; /** * Remove file from given path, currently no check for any failure diff --git a/src/lib/native/index.ts b/src/lib/api/native/index.ts similarity index 100% rename from src/lib/native/index.ts rename to src/lib/api/native/index.ts diff --git a/src/lib/loader.ts b/src/lib/api/native/loader.ts similarity index 94% rename from src/lib/loader.ts rename to src/lib/api/native/loader.ts index 3e454f2..5e9a26c 100644 --- a/src/lib/loader.ts +++ b/src/lib/api/native/loader.ts @@ -1,4 +1,4 @@ -import { Theme } from "./themes"; +import { Theme } from "../../managers/themes"; // @ts-ignore const pyonLoaderIdentity = globalThis.__PYON_LOADER__; @@ -65,6 +65,16 @@ function polyfillVendettaLoaderIdentity() { return loader as VendettaLoaderIdentity; } +export function getLoaderIdentity() { + if (isPyonLoader()) { + return pyonLoaderIdentity; + } else if (isVendettaLoader()) { + return getVendettaLoaderIdentity(); + } + + return null; +} + export function getVendettaLoaderIdentity(): VendettaLoaderIdentity | null { // @ts-ignore if (globalThis.__vendetta_loader) return globalThis.__vendetta_loader; diff --git a/src/lib/native/modules.ts b/src/lib/api/native/modules.ts similarity index 100% rename from src/lib/native/modules.ts rename to src/lib/api/native/modules.ts diff --git a/src/lib/patcher.ts b/src/lib/api/patcher.ts similarity index 100% rename from src/lib/patcher.ts rename to src/lib/api/patcher.ts diff --git a/src/lib/storage/backends.ts b/src/lib/api/storage/backends.ts similarity index 98% rename from src/lib/storage/backends.ts rename to src/lib/api/storage/backends.ts index d428ba2..325e842 100644 --- a/src/lib/storage/backends.ts +++ b/src/lib/api/storage/backends.ts @@ -1,5 +1,5 @@ -import { MMKVManager, FileManager } from "@lib/native/modules"; import { ReactNative as RN } from "@metro/common"; +import { FileManager, MMKVManager } from "../native/modules"; export interface StorageBackend { get: () => unknown | Promise; diff --git a/src/lib/storage/index.ts b/src/lib/api/storage/index.ts similarity index 95% rename from src/lib/storage/index.ts rename to src/lib/api/storage/index.ts index 88ada11..1c0af0a 100644 --- a/src/lib/storage/index.ts +++ b/src/lib/api/storage/index.ts @@ -1,5 +1,5 @@ -import createEmitter, { Emitter } from "@lib/emitter"; -import { StorageBackend } from "@lib/storage/backends"; +import { createEmitter, Emitter } from "@lib/utils/emitter"; +import { StorageBackend } from "@lib/api/storage/backends"; const emitterSymbol = Symbol.for("vendetta.storage.emitter"); const syncAwaitSymbol = Symbol.for("vendetta.storage.accessor"); @@ -113,4 +113,4 @@ export function wrapSync>(store: T): Awaited { export const awaitSyncWrapper = (store: any) => new Promise((res) => store[syncAwaitSymbol](res)); -export * from "@lib/storage/backends"; +export * from "@lib/api/storage/backends"; diff --git a/src/lib/debug.ts b/src/lib/debug.ts index 2de46a7..f14ac07 100644 --- a/src/lib/debug.ts +++ b/src/lib/debug.ts @@ -1,12 +1,12 @@ import { ReactNative as RN } from "@metro/common"; -import { after } from "@lib/patcher"; -import { getThemeFromLoader, selectTheme } from "@lib/themes"; -import { ClientInfoManager, DeviceManager, BundleUpdaterManager } from "@lib/native/modules"; -import { getAssetIDByName } from "@ui/assets"; +import { after } from "@lib/api/patcher"; +import { getThemeFromLoader, selectTheme } from "@lib/managers/themes"; +import { ClientInfoManager, DeviceManager, BundleUpdaterManager } from "@lib/api/native/modules"; +import { getAssetIDByName } from "@/lib/api/assets"; import { showToast } from "@ui/toasts"; -import settings from "@lib/settings"; -import logger from "@lib/logger"; -import { getLoaderName, isThemeSupported } from "./loader"; +import { settings } from "@lib/settings"; +import logger from "@lib/utils/logger"; +import { getLoaderName, isThemeSupported } from "./api/native/loader"; import type { PlatformConstants } from "react-native"; import { version } from "bunny-build"; export let socket: WebSocket; diff --git a/src/lib/managers/index.ts b/src/lib/managers/index.ts new file mode 100644 index 0000000..48154ef --- /dev/null +++ b/src/lib/managers/index.ts @@ -0,0 +1,2 @@ +export * as plugins from "./plugins"; +export * as themes from "./themes"; diff --git a/src/lib/plugins.ts b/src/lib/managers/plugins.ts similarity index 95% rename from src/lib/plugins.ts rename to src/lib/managers/plugins.ts index e6c7f1c..a3e6c2f 100644 --- a/src/lib/plugins.ts +++ b/src/lib/managers/plugins.ts @@ -1,9 +1,9 @@ import { safeFetch } from "@lib/utils"; -import { awaitSyncWrapper, createMMKVBackend, createStorage, purgeStorage, wrapSync } from "@lib/storage"; -import { allSettled } from "@lib/polyfills"; -import logger, { logModule } from "@lib/logger"; -import settings from "@lib/settings"; -import { Author } from "./types"; +import { awaitSyncWrapper, createMMKVBackend, createStorage, purgeStorage, wrapSync } from "@/lib/api/storage"; +import logger, { logModule } from "@lib/utils/logger"; +import { settings } from "@lib/settings"; +import { Author } from "../utils/types"; +import { allSettled } from "@/core/polyfills"; type EvaledPlugin = { onLoad?(): void; diff --git a/src/lib/themes.ts b/src/lib/managers/themes.ts similarity index 97% rename from src/lib/themes.ts rename to src/lib/managers/themes.ts index 98740a6..32dd499 100644 --- a/src/lib/themes.ts +++ b/src/lib/managers/themes.ts @@ -2,12 +2,12 @@ import { ReactNative as RN, chroma } from "@metro/common"; import { findInReactTree, safeFetch } from "@lib/utils"; import { find, findByName, findByProps, findByStoreName } from "@metro/filters"; -import { after, before, instead } from "@lib/patcher"; -import { createFileBackend, createMMKVBackend, createStorage, wrapSync, awaitSyncWrapper } from "@lib/storage"; -import logger from "@lib/logger"; -import { ThemeManager } from "@lib/native/modules"; -import { getStoredTheme, getThemeFilePath } from "./loader"; -import { Author } from "./types"; +import { after, before, instead } from "@lib/api/patcher"; +import { createFileBackend, createMMKVBackend, createStorage, wrapSync, awaitSyncWrapper } from "@/lib/api/storage"; +import logger from "@lib/utils/logger"; +import { ThemeManager } from "@lib/api/native/modules"; +import { getStoredTheme, getThemeFilePath } from "../api/native/loader"; +import { Author } from "../utils/types"; export interface ThemeData { name: string; diff --git a/src/lib/metro/common.ts b/src/lib/metro/common.ts index 7740b1a..0f9ff0a 100644 --- a/src/lib/metro/common.ts +++ b/src/lib/metro/common.ts @@ -1,5 +1,5 @@ import { find, findByProps, findByStoreName } from "@metro/filters"; -import { ReactNative as RN } from "@lib/preinit"; +import { ReactNative as RN } from "@/core/preinit"; import type { StyleSheet } from "react-native"; export interface DiscordStyleSheet { @@ -60,13 +60,13 @@ export const FluxDispatcher = findByProps("_currentDispatchActionType"); // React export const React = window.React as typeof import("react"); -export { ReactNative } from "@lib/preinit"; +export { ReactNative } from "@/core/preinit"; // Moment export const moment = findByProps("isMoment") as typeof import("moment"); // chroma.js -export { chroma } from "@lib/preinit"; +export { chroma } from "@/core/preinit"; // Lodash export const lodash = findByProps("forEachRight") as typeof import("lodash"); diff --git a/src/lib/metro/filters.ts b/src/lib/metro/filters.ts index 39be16a..2d6242e 100644 --- a/src/lib/metro/filters.ts +++ b/src/lib/metro/filters.ts @@ -1,4 +1,4 @@ -import { instead } from "@lib/patcher"; +import { instead } from "@lib/api/patcher"; type MetroModulesIndex = `${number}` | number; diff --git a/src/lib/metro/index.ts b/src/lib/metro/index.ts new file mode 100644 index 0000000..cfaa07d --- /dev/null +++ b/src/lib/metro/index.ts @@ -0,0 +1,3 @@ +export * from "./filters"; +export * as filters from "./filters"; +export * as common from "./common"; \ No newline at end of file diff --git a/src/lib/settings.ts b/src/lib/settings.ts index e9bf872..63e08ea 100644 --- a/src/lib/settings.ts +++ b/src/lib/settings.ts @@ -1,5 +1,5 @@ -import { createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@lib/storage"; -import { getLoaderConfigPath } from "./loader"; +import { createFileBackend, createMMKVBackend, createStorage, wrapSync } from "@/lib/api/storage"; +import { getLoaderConfigPath } from "./api/native/loader"; export interface Settings { debuggerUrl: string; @@ -18,7 +18,7 @@ export interface LoaderConfig { loadReactDevTools: boolean; } -export default wrapSync(createStorage(createMMKVBackend("VENDETTA_SETTINGS"))); +export const settings = wrapSync(createStorage(createMMKVBackend("VENDETTA_SETTINGS"))); export const loaderConfig = wrapSync(createStorage( createFileBackend(getLoaderConfigPath(), { diff --git a/src/ui/alerts.ts b/src/lib/ui/alerts.ts similarity index 96% rename from src/ui/alerts.ts rename to src/lib/ui/alerts.ts index 03cac07..77ca2fd 100644 --- a/src/ui/alerts.ts +++ b/src/lib/ui/alerts.ts @@ -1,6 +1,6 @@ import { findByProps } from "@metro/filters"; import InputAlert, { InputAlertProps } from "@ui/components/InputAlert"; -import { ButtonColors } from "@/lib/types"; +import { ButtonColors } from "@/lib/utils/types"; const Alerts = findByProps("openLazy", "close"); diff --git a/src/ui/color.ts b/src/lib/ui/color.ts similarity index 96% rename from src/ui/color.ts rename to src/lib/ui/color.ts index 84dd916..0ab1100 100644 --- a/src/ui/color.ts +++ b/src/lib/ui/color.ts @@ -1,5 +1,5 @@ import { constants } from "@metro/common"; -import { color } from "@lib/themes"; +import { color } from "@lib/managers/themes"; //! This module is only found on 165.0+, under the assumption that iOS 165.0 is the same as Android 165.0. //* In 167.1, most if not all traces of the old color modules were removed. diff --git a/src/ui/components/Codeblock.tsx b/src/lib/ui/components/Codeblock.tsx similarity index 100% rename from src/ui/components/Codeblock.tsx rename to src/lib/ui/components/Codeblock.tsx diff --git a/src/ui/components/ContextMenu.tsx b/src/lib/ui/components/ContextMenu.tsx similarity index 94% rename from src/ui/components/ContextMenu.tsx rename to src/lib/ui/components/ContextMenu.tsx index 70cbd82..a679b25 100644 --- a/src/ui/components/ContextMenu.tsx +++ b/src/lib/ui/components/ContextMenu.tsx @@ -1,6 +1,6 @@ import { findByProps } from "@lib/metro/filters"; -import { ReactNative } from "@lib/preinit"; -import { instead } from "@lib/patcher"; +import { ReactNative } from "@/core/preinit"; +import { instead } from "@lib/api/patcher"; const { ContextMenu: _ContextMenu } = findByProps("ContextMenu"); const { AccessibilityInfo } = ReactNative diff --git a/src/ui/components/ErrorBoundary.tsx b/src/lib/ui/components/ErrorBoundary.tsx similarity index 97% rename from src/ui/components/ErrorBoundary.tsx rename to src/lib/ui/components/ErrorBoundary.tsx index dadb569..19c4626 100644 --- a/src/ui/components/ErrorBoundary.tsx +++ b/src/lib/ui/components/ErrorBoundary.tsx @@ -1,4 +1,4 @@ -import { Strings } from "@/lib/i18n"; +import { Strings } from "@/core/i18n"; import { React, ReactNative as RN, stylesheet } from "@metro/common"; import { Forms, Button, Codeblock } from "@ui/components"; diff --git a/src/ui/components/InputAlert.tsx b/src/lib/ui/components/InputAlert.tsx similarity index 97% rename from src/ui/components/InputAlert.tsx rename to src/lib/ui/components/InputAlert.tsx index 59d5e2c..7ce12f1 100644 --- a/src/ui/components/InputAlert.tsx +++ b/src/lib/ui/components/InputAlert.tsx @@ -1,4 +1,4 @@ -import { ButtonColors } from "@/lib/types"; +import { ButtonColors } from "@/lib/utils/types"; import { findByProps } from "@metro/filters"; import { Forms, Alert } from "@ui/components"; diff --git a/src/ui/components/Search.tsx b/src/lib/ui/components/Search.tsx similarity index 92% rename from src/ui/components/Search.tsx rename to src/lib/ui/components/Search.tsx index 2dea17b..b3acb70 100644 --- a/src/ui/components/Search.tsx +++ b/src/lib/ui/components/Search.tsx @@ -1,8 +1,8 @@ import { ReactNative as RN } from "@metro/common"; import { findByProps } from "@metro/filters"; import ErrorBoundary from "@ui/components/ErrorBoundary"; -import { getAssetIDByName } from "@ui/assets"; -import { Strings } from "@/lib/i18n"; +import { getAssetIDByName } from "@/lib/api/assets"; +import { Strings } from "@/core/i18n"; const { TextInput } = findByProps("TableRow"); diff --git a/src/ui/components/Summary.tsx b/src/lib/ui/components/Summary.tsx similarity index 95% rename from src/ui/components/Summary.tsx rename to src/lib/ui/components/Summary.tsx index 2cb8152..378bc28 100644 --- a/src/ui/components/Summary.tsx +++ b/src/lib/ui/components/Summary.tsx @@ -1,5 +1,5 @@ import { ReactNative as RN } from "@metro/common"; -import { getAssetIDByName } from "@ui/assets"; +import { getAssetIDByName } from "@/lib/api/assets"; import { findByProps } from "@/lib/metro/filters"; const { FormRow } = findByProps("FormRow"); diff --git a/src/ui/components/index.ts b/src/lib/ui/components/index.ts similarity index 100% rename from src/ui/components/index.ts rename to src/lib/ui/components/index.ts diff --git a/src/lib/ui/index.ts b/src/lib/ui/index.ts new file mode 100644 index 0000000..239184b --- /dev/null +++ b/src/lib/ui/index.ts @@ -0,0 +1,5 @@ +export * as alerts from "./alerts"; +export * as color from "./color"; +export * as toasts from "./toasts"; +export * as settings from "./settings"; +export * as components from "./components"; diff --git a/src/ui/quickInstall/forumPost.tsx b/src/lib/ui/quickInstall/forumPost.tsx similarity index 89% rename from src/ui/quickInstall/forumPost.tsx rename to src/lib/ui/quickInstall/forumPost.tsx index e603988..dd75e1c 100644 --- a/src/ui/quickInstall/forumPost.tsx +++ b/src/lib/ui/quickInstall/forumPost.tsx @@ -1,14 +1,14 @@ import { findByName, findByProps } from "@metro/filters"; -import { DISCORD_SERVER_ID, PLUGINS_CHANNEL_ID, THEMES_CHANNEL_ID, HTTP_REGEX_MULTI, PROXY_PREFIX } from "@lib/constants"; -import { after } from "@lib/patcher"; -import { installPlugin, plugins, removePlugin } from "@lib/plugins"; -import { installTheme, removeTheme, themes } from "@lib/themes"; +import { DISCORD_SERVER_ID, PLUGINS_CHANNEL_ID, THEMES_CHANNEL_ID, HTTP_REGEX_MULTI, PROXY_PREFIX } from "@lib/utils/constants"; +import { after } from "@lib/api/patcher"; +import { installPlugin, plugins, removePlugin } from "@lib/managers/plugins"; +import { installTheme, removeTheme, themes } from "@lib/managers/themes"; import { findInReactTree } from "@lib/utils"; -import { getAssetIDByName } from "@ui/assets"; +import { getAssetIDByName } from "@/lib/api/assets"; import { showToast } from "@ui/toasts"; -import { useProxy } from "@/lib/storage"; -import { isThemeSupported } from "@/lib/loader"; -import { Strings, formatStringSplit } from "@/lib/i18n"; +import { useProxy } from "@/lib/api/storage"; +import { isThemeSupported } from "@/lib/api/native/loader"; +import { Strings, formatStringSplit } from "@/core/i18n"; type PostType = "Plugin" | "Theme"; @@ -53,7 +53,7 @@ function useExtractThreadContent(thread: any, _firstMessage = null, actionSheet let urls = firstMessage?.content?.match(HTTP_REGEX_MULTI)?.filter(postMap[postType].urlsFilter); if (!urls || !urls[0]) return; - // Sync with lib/plugins + // Sync with lib/managers/plugins if (postType === "Plugin" && !urls[0].endsWith("/")) urls[0] += "/"; return [postType, urls[0]]; diff --git a/src/ui/quickInstall/index.ts b/src/lib/ui/quickInstall/index.ts similarity index 100% rename from src/ui/quickInstall/index.ts rename to src/lib/ui/quickInstall/index.ts diff --git a/src/ui/quickInstall/url.tsx b/src/lib/ui/quickInstall/url.tsx similarity index 87% rename from src/ui/quickInstall/url.tsx rename to src/lib/ui/quickInstall/url.tsx index 06734f6..ff2fe59 100644 --- a/src/ui/quickInstall/url.tsx +++ b/src/lib/ui/quickInstall/url.tsx @@ -1,14 +1,14 @@ import { findByProps, find } from "@metro/filters"; import { ReactNative as RN, channels, url } from "@metro/common"; -import { PROXY_PREFIX, THEMES_CHANNEL_ID } from "@lib/constants"; -import { after, instead } from "@lib/patcher"; -import { installPlugin } from "@lib/plugins"; -import { installTheme } from "@lib/themes"; +import { PROXY_PREFIX, THEMES_CHANNEL_ID } from "@lib/utils/constants"; +import { after, instead } from "@lib/api/patcher"; +import { installPlugin } from "@lib/managers/plugins"; +import { installTheme } from "@lib/managers/themes"; import { showConfirmationAlert } from "@ui/alerts"; -import { getAssetIDByName } from "@ui/assets"; +import { getAssetIDByName } from "@/lib/api/assets"; import { showToast } from "@ui/toasts"; -import { isThemeSupported } from "@/lib/loader"; -import { Strings, formatString, formatStringSplit } from "@lib/i18n"; +import { isThemeSupported } from "@/lib/api/native/loader"; +import { Strings, formatString, formatStringSplit } from "@/core/i18n"; const showSimpleActionSheet = find((m) => m?.showSimpleActionSheet && !Object.getOwnPropertyDescriptor(m, "showSimpleActionSheet")?.get); const handleClick = findByProps("handleClick"); diff --git a/src/ui/safeMode.tsx b/src/lib/ui/safeMode.tsx similarity index 96% rename from src/ui/safeMode.tsx rename to src/lib/ui/safeMode.tsx index deaa68d..348360d 100644 --- a/src/ui/safeMode.tsx +++ b/src/lib/ui/safeMode.tsx @@ -1,12 +1,12 @@ import { ReactNative as RN, stylesheet } from "@metro/common"; import { findByName, findByProps, findByStoreName } from "@metro/filters"; -import { after } from "@lib/patcher"; +import { after } from "@lib/api/patcher"; import { toggleSafeMode } from "@lib/debug"; -import { DeviceManager } from "@lib/native/modules"; +import { DeviceManager } from "@lib/api/native/modules"; import { semanticColors } from "@ui/color"; import { Button, Codeblock, ErrorBoundary as _ErrorBoundary, SafeAreaView } from "@ui/components"; -import settings from "@lib/settings"; -import { ButtonColors } from "@/lib/types"; +import { settings } from "@lib/settings"; +import { ButtonColors } from "@/lib/utils/types"; const ErrorBoundary = findByName("ErrorBoundary"); diff --git a/src/ui/settings/components/AddonPage.tsx b/src/lib/ui/settings/components/AddonPage.tsx similarity index 91% rename from src/ui/settings/components/AddonPage.tsx rename to src/lib/ui/settings/components/AddonPage.tsx index 3444ca8..e19da85 100644 --- a/src/ui/settings/components/AddonPage.tsx +++ b/src/lib/ui/settings/components/AddonPage.tsx @@ -1,13 +1,13 @@ import { NavigationNative, ReactNative as RN, clipboard } from "@metro/common"; -import { useProxy } from "@lib/storage"; +import { useProxy } from "@/lib/api/storage"; import { HelpMessage, ErrorBoundary, Search } from "@ui/components"; import { CardWrapper } from "@ui/settings/components/Card"; -import settings from "@lib/settings"; +import { settings } from "@lib/settings"; import { findByProps } from "@/lib/metro/filters"; -import { HTTP_REGEX_MULTI } from "@/lib/constants"; -import { showInputAlert } from "@/ui/alerts"; -import { getAssetIDByName } from "@/ui/assets"; -import { Strings, formatString } from "@/lib/i18n"; +import { HTTP_REGEX_MULTI } from "@/lib/utils/constants"; +import { showInputAlert } from "@ui/alerts"; +import { getAssetIDByName } from "@/lib/api/assets"; +import { Strings, formatString } from "@/core/i18n"; interface AddonPageProps { title: string; diff --git a/src/ui/settings/components/AssetDisplay.tsx b/src/lib/ui/settings/components/AssetDisplay.tsx similarity index 93% rename from src/ui/settings/components/AssetDisplay.tsx rename to src/lib/ui/settings/components/AssetDisplay.tsx index 3a6c4bf..6b6521b 100644 --- a/src/ui/settings/components/AssetDisplay.tsx +++ b/src/lib/ui/settings/components/AssetDisplay.tsx @@ -1,7 +1,7 @@ import { ReactNative as RN, clipboard } from "@metro/common"; import { showToast } from "@ui/toasts"; import { Forms } from "@ui/components"; -import { Asset } from "@/ui/assets"; +import { Asset } from "@/lib/api/assets"; interface AssetDisplayProps { asset: Asset } diff --git a/src/ui/settings/components/Card.tsx b/src/lib/ui/settings/components/Card.tsx similarity index 97% rename from src/ui/settings/components/Card.tsx rename to src/lib/ui/settings/components/Card.tsx index 63c8d39..25c1f95 100644 --- a/src/ui/settings/components/Card.tsx +++ b/src/lib/ui/settings/components/Card.tsx @@ -1,7 +1,7 @@ -import ContextMenu from "@/ui/components/ContextMenu"; +import ContextMenu from "@ui/components/ContextMenu"; import { ReactNative as RN, stylesheet } from "@metro/common"; import { findByProps } from "@metro/filters"; -import { getAssetIDByName } from "@ui/assets"; +import { getAssetIDByName } from "@/lib/api/assets"; import { semanticColors } from "@ui/color"; const { TableRow, TableRowIcon, TableSwitchRow, TableCheckboxRow, TableRowGroup } = findByProps("TableRow"); diff --git a/src/ui/settings/components/InstallButton.tsx b/src/lib/ui/settings/components/InstallButton.tsx similarity index 88% rename from src/ui/settings/components/InstallButton.tsx rename to src/lib/ui/settings/components/InstallButton.tsx index 42d3ddf..b5ddcff 100644 --- a/src/ui/settings/components/InstallButton.tsx +++ b/src/lib/ui/settings/components/InstallButton.tsx @@ -1,9 +1,9 @@ import { ReactNative as RN, stylesheet, clipboard } from "@metro/common"; -import { HTTP_REGEX_MULTI } from "@lib/constants"; +import { HTTP_REGEX_MULTI } from "@lib/utils/constants"; import { showInputAlert } from "@ui/alerts"; -import { getAssetIDByName } from "@ui/assets"; +import { getAssetIDByName } from "@/lib/api/assets"; import { semanticColors } from "@ui/color"; -import { Strings } from "@/lib/i18n"; +import { Strings } from "@/core/i18n"; const styles = stylesheet.createThemedStyleSheet({ icon: { diff --git a/src/ui/settings/components/PluginCard.tsx b/src/lib/ui/settings/components/PluginCard.tsx similarity index 94% rename from src/ui/settings/components/PluginCard.tsx rename to src/lib/ui/settings/components/PluginCard.tsx index ca7f733..8fe46a7 100644 --- a/src/ui/settings/components/PluginCard.tsx +++ b/src/lib/ui/settings/components/PluginCard.tsx @@ -1,13 +1,13 @@ import { NavigationNative, clipboard } from "@metro/common"; -import { removePlugin, startPlugin, stopPlugin, getSettings, fetchPlugin, BunnyPlugin } from "@lib/plugins"; -import { MMKVManager } from "@lib/native/modules"; -import { getAssetIDByName } from "@ui/assets"; +import { removePlugin, startPlugin, stopPlugin, getSettings, fetchPlugin, BunnyPlugin } from "@lib/managers/plugins"; +import { MMKVManager } from "@lib/api/native/modules"; +import { getAssetIDByName } from "@/lib/api/assets"; import { showToast } from "@ui/toasts"; import { showConfirmationAlert } from "@ui/alerts"; import Card, { CardWrapper } from "@ui/settings/components/Card"; -import { useProxy } from "@/lib/storage"; -import { ButtonColors } from "@/lib/types"; -import { Strings, formatString } from "@/lib/i18n"; +import { useProxy } from "@/lib/api/storage"; +import { ButtonColors } from "@/lib/utils/types"; +import { Strings, formatString } from "@/core/i18n"; async function stopThenStart(plugin: BunnyPlugin, callback: Function) { if (plugin.enabled) stopPlugin(plugin.id, false); diff --git a/src/ui/settings/components/SettingsSection.tsx b/src/lib/ui/settings/components/SettingsSection.tsx similarity index 86% rename from src/ui/settings/components/SettingsSection.tsx rename to src/lib/ui/settings/components/SettingsSection.tsx index 65ba717..887c1c1 100644 --- a/src/ui/settings/components/SettingsSection.tsx +++ b/src/lib/ui/settings/components/SettingsSection.tsx @@ -1,10 +1,10 @@ import { NavigationNative } from "@metro/common"; -import { useProxy } from "@lib/storage"; -import { getAssetIDByName } from "@ui/assets"; +import { useProxy } from "@/lib/api/storage"; +import { getAssetIDByName } from "@/lib/api/assets"; import { getRenderableScreens } from "@ui/settings/data"; import { ErrorBoundary, Forms } from "@ui/components"; -import settings from "@lib/settings"; -import { Strings } from "@/lib/i18n"; +import { settings } from "@lib/settings"; +import { Strings } from "@/core/i18n"; const { FormRow, FormSection, FormDivider } = Forms; diff --git a/src/ui/settings/components/ThemeCard.tsx b/src/lib/ui/settings/components/ThemeCard.tsx similarity index 92% rename from src/ui/settings/components/ThemeCard.tsx rename to src/lib/ui/settings/components/ThemeCard.tsx index 235b807..7adf286 100644 --- a/src/ui/settings/components/ThemeCard.tsx +++ b/src/lib/ui/settings/components/ThemeCard.tsx @@ -1,14 +1,14 @@ import { clipboard } from "@metro/common"; -import { Theme, applyTheme, fetchTheme, removeTheme, selectTheme, themes } from "@lib/themes"; -import { useProxy } from "@lib/storage"; -import { BundleUpdaterManager } from "@lib/native/modules"; -import { getAssetIDByName } from "@ui/assets"; +import { Theme, applyTheme, fetchTheme, removeTheme, selectTheme, themes } from "@lib/managers/themes"; +import { useProxy } from "@/lib/api/storage"; +import { BundleUpdaterManager } from "@lib/api/native/modules"; +import { getAssetIDByName } from "@/lib/api/assets"; import { showConfirmationAlert } from "@ui/alerts"; import { showToast } from "@ui/toasts"; -import settings from "@lib/settings"; +import { settings } from "@lib/settings"; import Card, { CardWrapper } from "@ui/settings/components/Card"; -import { ButtonColors } from "@/lib/types"; -import { Strings, formatString } from "@/lib/i18n"; +import { ButtonColors } from "@/lib/utils/types"; +import { Strings, formatString } from "@/core/i18n"; async function selectAndApply(value: boolean, id: string) { try { diff --git a/src/ui/settings/components/Version.tsx b/src/lib/ui/settings/components/Version.tsx similarity index 94% rename from src/ui/settings/components/Version.tsx rename to src/lib/ui/settings/components/Version.tsx index ad172f7..4f6d789 100644 --- a/src/ui/settings/components/Version.tsx +++ b/src/lib/ui/settings/components/Version.tsx @@ -1,5 +1,5 @@ import { clipboard } from "@metro/common"; -import { getAssetIDByName } from "@ui/assets"; +import { getAssetIDByName } from "@/lib/api/assets"; import { showToast } from "@ui/toasts"; import { Forms } from "@ui/components"; import { findByProps } from "@/lib/metro/filters"; diff --git a/src/ui/settings/data.tsx b/src/lib/ui/settings/data.tsx similarity index 92% rename from src/ui/settings/data.tsx rename to src/lib/ui/settings/data.tsx index bbc6fce..c761a56 100644 --- a/src/ui/settings/data.tsx +++ b/src/lib/ui/settings/data.tsx @@ -1,22 +1,22 @@ import { ReactNative as RN, NavigationNative, stylesheet, lodash } from "@metro/common"; -import { installPlugin } from "@lib/plugins"; -import { installTheme } from "@lib/themes"; +import { installPlugin } from "@lib/managers/plugins"; +import { installTheme } from "@lib/managers/themes"; import { showConfirmationAlert } from "@ui/alerts"; import { semanticColors } from "@ui/color"; import { showToast } from "@ui/toasts"; import { without } from "@lib/utils"; -import { getAssetIDByName } from "@ui/assets"; -import settings from "@lib/settings"; +import { getAssetIDByName } from "@/lib/api/assets"; +import { settings } from "@lib/settings"; import ErrorBoundary from "@ui/components/ErrorBoundary"; import InstallButton from "@ui/settings/components/InstallButton"; import General from "@ui/settings/pages/General"; import Plugins from "@ui/settings/pages/Plugins"; import Themes from "@ui/settings/pages/Themes"; import Developer from "@ui/settings/pages/Developer"; -import { PROXY_PREFIX } from "@/lib/constants"; +import { PROXY_PREFIX } from "@/lib/utils/constants"; import { findByProps } from "@/lib/metro/filters"; -import { isThemeSupported } from "@/lib/loader"; -import { Strings } from "@/lib/i18n"; +import { isThemeSupported } from "@/lib/api/native/loader"; +import { Strings } from "@/core/i18n"; const { useSafeAreaInsets } = findByProps("useSafeAreaInsets"); @@ -67,7 +67,7 @@ export const getScreens = (youKeys = false): Screen[] => [ onConfirm: () => installPlugin(input) .then(() => showToast(Strings.TOASTS_INSTALLED_PLUGIN, getAssetIDByName("Check"))) - .catch((x) => showToast(x?.message ?? `${x}`, getAssetIDByName("Small"))), + .catch((x: any) => showToast(x?.message ?? `${x}`, getAssetIDByName("Small"))), cancelText: Strings.CANCEL, })); else return await installPlugin(input); diff --git a/src/ui/settings/index.ts b/src/lib/ui/settings/index.ts similarity index 100% rename from src/ui/settings/index.ts rename to src/lib/ui/settings/index.ts diff --git a/src/ui/settings/pages/AssetBrowser.tsx b/src/lib/ui/settings/pages/AssetBrowser.tsx similarity index 96% rename from src/ui/settings/pages/AssetBrowser.tsx rename to src/lib/ui/settings/pages/AssetBrowser.tsx index 139c769..af141e9 100644 --- a/src/ui/settings/pages/AssetBrowser.tsx +++ b/src/lib/ui/settings/pages/AssetBrowser.tsx @@ -1,5 +1,5 @@ import { ReactNative as RN } from "@metro/common"; -import { all } from "@ui/assets"; +import { all } from "@/lib/api/assets"; import { Forms, Search, ErrorBoundary } from "@ui/components"; import AssetDisplay from "@ui/settings/components/AssetDisplay"; diff --git a/src/ui/settings/pages/Developer.tsx b/src/lib/ui/settings/pages/Developer.tsx similarity index 96% rename from src/ui/settings/pages/Developer.tsx rename to src/lib/ui/settings/pages/Developer.tsx index fa1da7f..b993872 100644 --- a/src/ui/settings/pages/Developer.tsx +++ b/src/lib/ui/settings/pages/Developer.tsx @@ -1,14 +1,14 @@ import { ReactNative as RN, NavigationNative, stylesheet } from "@metro/common"; import { findByProps } from "@metro/filters"; import { connectToDebugger } from "@lib/debug"; -import { useProxy } from "@lib/storage"; -import { getAssetIDByName } from "@ui/assets"; +import { useProxy } from "@/lib/api/storage"; +import { getAssetIDByName } from "@/lib/api/assets"; import { ErrorBoundary, Forms } from "@ui/components"; -import settings, { loaderConfig } from "@lib/settings"; +import { settings, loaderConfig } from "@lib/settings"; import AssetBrowser from "@ui/settings/pages/AssetBrowser"; import { semanticColors } from "@ui/color"; -import { getReactDevToolsProp, getReactDevToolsVersion, isLoaderConfigSupported, isReactDevToolsPreloaded } from "@/lib/loader"; -import { Strings } from "@/lib/i18n"; +import { getReactDevToolsProp, getReactDevToolsVersion, isLoaderConfigSupported, isReactDevToolsPreloaded } from "@/lib/api/native/loader"; +import { Strings } from "@/core/i18n"; const { Stack, TableRow, TableSwitchRow, TableRowGroup, TextInput } = findByProps("TableRow"); const { FormText } = Forms; diff --git a/src/ui/settings/pages/General.tsx b/src/lib/ui/settings/pages/General.tsx similarity index 95% rename from src/ui/settings/pages/General.tsx rename to src/lib/ui/settings/pages/General.tsx index 8df3530..f104440 100644 --- a/src/ui/settings/pages/General.tsx +++ b/src/lib/ui/settings/pages/General.tsx @@ -1,14 +1,14 @@ import { ReactNative as RN, stylesheet, url } from "@metro/common"; -import { DISCORD_SERVER, GITHUB } from "@lib/constants"; +import { DISCORD_SERVER, GITHUB } from "@lib/utils/constants"; import { getDebugInfo, toggleSafeMode } from "@lib/debug"; -import { useProxy } from "@lib/storage"; -import { getAssetIDByName } from "@ui/assets"; +import { useProxy } from "@/lib/api/storage"; +import { getAssetIDByName } from "@/lib/api/assets"; import { Summary } from "@ui/components"; -import settings from "@lib/settings"; +import { settings } from "@lib/settings"; import Version from "@ui/settings/components/Version"; import { findByProps } from "@lib/metro/filters"; import { semanticColors } from "@ui/color"; -import { Strings } from "@/lib/i18n"; +import { Strings } from "@/core/i18n"; const { Stack, TableRow, TableSwitchRow, TableRowGroup } = findByProps("TableRow"); const debugInfo = getDebugInfo() as any; diff --git a/src/ui/settings/pages/Plugins.tsx b/src/lib/ui/settings/pages/Plugins.tsx similarity index 68% rename from src/ui/settings/pages/Plugins.tsx rename to src/lib/ui/settings/pages/Plugins.tsx index aeec7bb..23c68dc 100644 --- a/src/ui/settings/pages/Plugins.tsx +++ b/src/lib/ui/settings/pages/Plugins.tsx @@ -1,9 +1,9 @@ -import { useProxy } from "@lib/storage"; -import { BunnyPlugin, installPlugin, plugins } from "@lib/plugins"; -import settings from "@lib/settings"; +import { useProxy } from "@/lib/api/storage"; +import { BunnyPlugin, installPlugin, plugins } from "@lib/managers/plugins"; +import { settings } from "@lib/settings"; import AddonPage from "@ui/settings/components/AddonPage"; import PluginCard from "@ui/settings/components/PluginCard"; -import { Strings } from "@/lib/i18n"; +import { Strings } from "@/core/i18n"; export default function Plugins() { useProxy(settings) diff --git a/src/ui/settings/pages/Themes.tsx b/src/lib/ui/settings/pages/Themes.tsx similarity index 79% rename from src/ui/settings/pages/Themes.tsx rename to src/lib/ui/settings/pages/Themes.tsx index f765024..4d28a40 100644 --- a/src/ui/settings/pages/Themes.tsx +++ b/src/lib/ui/settings/pages/Themes.tsx @@ -1,11 +1,11 @@ -import { useProxy } from "@lib/storage"; -import { Theme, installTheme, themes } from "@lib/themes"; +import { useProxy } from "@/lib/api/storage"; +import { Theme, installTheme, themes } from "@lib/managers/themes"; import { Button } from "@ui/components"; -import settings from "@lib/settings"; +import { settings } from "@lib/settings"; import AddonPage from "@ui/settings/components/AddonPage"; import ThemeCard from "@ui/settings/components/ThemeCard"; -import { ButtonColors } from "@/lib/types"; -import { Strings } from "@/lib/i18n"; +import { ButtonColors } from "@/lib/utils/types"; +import { Strings } from "@/core/i18n"; export default function Themes() { useProxy(settings); diff --git a/src/ui/settings/patches/panels.tsx b/src/lib/ui/settings/patches/panels.tsx similarity index 97% rename from src/ui/settings/patches/panels.tsx rename to src/lib/ui/settings/patches/panels.tsx index 82b7563..46bcdc4 100644 --- a/src/ui/settings/patches/panels.tsx +++ b/src/lib/ui/settings/patches/panels.tsx @@ -1,6 +1,6 @@ import { i18n } from "@metro/common"; import { findByName } from "@metro/filters"; -import { after } from "@lib/patcher"; +import { after } from "@lib/api/patcher"; import { findInReactTree } from "@lib/utils"; import { getPanelsScreens } from "@ui/settings/data"; import SettingsSection from "@ui/settings/components/SettingsSection"; diff --git a/src/ui/settings/patches/you.tsx b/src/lib/ui/settings/patches/you.tsx similarity index 98% rename from src/ui/settings/patches/you.tsx rename to src/lib/ui/settings/patches/you.tsx index 6f3a12a..dab0e4c 100644 --- a/src/ui/settings/patches/you.tsx +++ b/src/lib/ui/settings/patches/you.tsx @@ -1,8 +1,8 @@ import { findByProps } from "@metro/filters"; -import { after, before } from "@lib/patcher"; +import { after, before } from "@lib/api/patcher"; import { getRenderableScreens, getScreens, getYouData } from "@ui/settings/data"; import { i18n } from "@lib/metro/common"; -import { Strings } from "@/lib/i18n"; +import { Strings } from "@/core/i18n"; export default function patchYou() { const patches = new Array; diff --git a/src/ui/toasts.ts b/src/lib/ui/toasts.ts similarity index 94% rename from src/ui/toasts.ts rename to src/lib/ui/toasts.ts index 4115eea..ef59834 100644 --- a/src/ui/toasts.ts +++ b/src/lib/ui/toasts.ts @@ -1,6 +1,6 @@ import { findByProps } from "@metro/filters"; import { ReactNative, toasts } from "@metro/common"; -import { getAssetIDByName } from "@ui/assets"; +import { getAssetIDByName } from "@/lib/api/assets"; const { uuid4 } = findByProps("uuid4"); diff --git a/src/lib/constants.ts b/src/lib/utils/constants.ts similarity index 100% rename from src/lib/constants.ts rename to src/lib/utils/constants.ts diff --git a/src/lib/emitter.ts b/src/lib/utils/emitter.ts similarity index 96% rename from src/lib/emitter.ts rename to src/lib/utils/emitter.ts index 4b64555..c862df9 100644 --- a/src/lib/emitter.ts +++ b/src/lib/utils/emitter.ts @@ -26,8 +26,7 @@ export interface Emitter { emit: (event: EmitterEvent, data: EmitterListenerData) => void; } - -export default function createEmitter(): Emitter { +export function createEmitter(): Emitter { return { listeners: Object.values(Events).reduce((acc, val: string) => ((acc[val] = new Set()), acc), {}) as EmitterListeners, diff --git a/src/lib/utils/findInReactTree.ts b/src/lib/utils/findInReactTree.ts index 9d4ea53..3708167 100644 --- a/src/lib/utils/findInReactTree.ts +++ b/src/lib/utils/findInReactTree.ts @@ -1,6 +1,6 @@ import { findInTree } from "@lib/utils"; import { SearchFilter } from "./findInTree"; -export default (tree: { [key: string]: any }, filter: SearchFilter): any => findInTree(tree, filter, { +export const findInReactTree = (tree: { [key: string]: any }, filter: SearchFilter): any => findInTree(tree, filter, { walkable: ["props", "children", "child", "sibling"], }); \ No newline at end of file diff --git a/src/lib/utils/findInTree.ts b/src/lib/utils/findInTree.ts index 3c3c9c4..4f77b61 100644 --- a/src/lib/utils/findInTree.ts +++ b/src/lib/utils/findInTree.ts @@ -40,7 +40,7 @@ function treeSearch(tree: SearchTree, filter: SearchFilter, opts: Required(object: O, ...keys: K): Omit { +export function without(object: O, ...keys: K): Omit { const cloned = { ...object }; keys.forEach((k) => delete cloned[k]); return cloned; diff --git a/src/lib/windowObject.ts b/src/lib/windowObject.ts index 195e70e..41bff1c 100644 --- a/src/lib/windowObject.ts +++ b/src/lib/windowObject.ts @@ -1,59 +1,56 @@ -import { createVendettaObject } from "./vendettaObject"; -import * as constants from "@lib/constants"; -import * as debug from "@lib/debug"; -import * as native from "@lib/native"; -import * as plugins from "@lib/plugins"; -import * as themes from "@lib/themes"; -import * as commands from "@lib/commands"; -import * as storage from "@lib/storage"; -import * as metro from "@metro/filters"; +import { createVendettaObject } from "../core/vendettaObject"; +import * as constants from "@lib/utils/constants"; +import * as native from "@lib/api/native"; +import * as plugins from "@lib/managers/plugins"; +import * as themes from "@lib/managers/themes"; +import * as commands from "@/lib/api/commands"; +import * as storage from "@/lib/api/storage"; import * as common from "@metro/common"; import * as components from "@ui/components"; import * as toasts from "@ui/toasts"; import * as alerts from "@ui/alerts"; -import * as assets from "@ui/assets"; +import * as assets from "@/lib/api/assets"; import * as color from "@ui/color"; +import logger from "./utils/logger"; +import patcher from "./api/patcher"; + +import * as api from "@lib/api"; +import * as managers from "@lib/api"; +import * as metro from "@lib/metro"; +import * as ui from "@lib/ui"; import * as utils from "@lib/utils"; -import logger from "./logger"; -import patcher from "./patcher"; -import settings, { loaderConfig } from "./settings"; +import * as debug from "@lib/debug"; +import * as settings from "@lib/settings"; + +function createBunnyObject(unloads: any[]) { + return { + api: { + commands: { ...commands }, + native: { ...native }, + storage: { ...storage }, + assets: { ...assets }, + patcher: { ...patcher } + }, + managers: { ...managers }, + metro: { ...metro }, + ui: { ...ui }, + utils: { ...utils }, + settings, + version: debug.versionHash, + unload: () => { + unloads.filter(i => typeof i === "function").forEach(p => p()); + // @ts-expect-error + delete window.bunny; + }, + } +} + +const dest = { ...api }; +type Y = typeof dest; + +export type BunnyObject = ReturnType; export default function initWindowObject(unloads: any[]) { window.vendetta = createVendettaObject(unloads); window.bunny = createBunnyObject(unloads); } - -function createBunnyObject(unloads: any[]) { - return { - patcher: utils.without(patcher, "unpatchAll"), - metro: { ...metro, common: { ...common } }, - constants: { ...constants }, - utils: { ...utils }, - debug: utils.without({ ...debug }, "versionHash", "patchLogHook", "toggleSafeMode"), - ui: { - components: { ...components }, - toasts: { ...toasts }, - alerts: { ...alerts }, - assets: { ...assets }, - ...color, - }, - native: { ...native }, - plugins: utils.without({ ...plugins }, "initPlugins", "evalPlugin"), - themes: utils.without({ ...themes }, "initThemes"), - commands: utils.without({ ...commands }, "patchCommands"), - storage: { ...storage }, - settings: settings, - loader: { - identity: null, - config: loaderConfig, - }, - logger: { ...logger }, - version: debug.versionHash, - unload: () => { - unloads.filter(i => typeof i === "function").forEach(p => p()); - delete window.vendetta; - }, - } -} - -export type BunnyObject = ReturnType; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 82ab0d6..0fa6b1e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,8 @@ "@*": ["src*"], "@lib/*": ["src/lib/*"], "@metro/*": ["src/lib/metro/*"], - "@ui/*": ["src/ui/*"], + "@ui/*": ["src/lib/ui/*"], + "@types": ["src/utils/types.ts"], "bunny-build": ["src/modules.d.ts"] }, "plugins": [