Skip to content

Commit

Permalink
feat!: a lot of changes, see commit description
Browse files Browse the repository at this point in the history
- BREAKING: Refactored `@revenge-mod/plugins` and the Settings plugin
- Added the ability to install external plugins from storage
- External plugins can now subscribe to Metro module loads
- New `@revenge-mod/shared/components` submodule for common components
-
  • Loading branch information
PalmDevs committed Jan 1, 2025
1 parent 10063a0 commit f2f1365
Show file tree
Hide file tree
Showing 56 changed files with 1,654 additions and 967 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,7 @@ dist
.DS_Store

# TypeScript
tsdoc-metadata.json
tsdoc-metadata.json

# Private
.private
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"editor.defaultFormatter": "biomejs.biome"
}
{
"editor.defaultFormatter": "biomejs.biome"
}
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"level": "off"
},
"noExplicitAny": {
"level": "warn"
"level": "off"
},
"noConfusingVoidType": {
"level": "off"
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions libraries/debug/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export const PerformanceTimes = {
Modules_RequiredAssets: -1,
App_RunApplicationCalled: -1,
App_AfterRunRACallbacks: -1,
Plugins_CoreImported: -1,
Plugins_Registered: -1,
Storage_Initialized: -1,
Plugins_CoreStarted: -1,
Plugins_Started: -1,
App_CreateElementCalled: -1,
App_AfterRunCECallbacks: -1,
}
Expand Down
1 change: 1 addition & 0 deletions libraries/modules/src/common/components/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export type IconComponentProps = {

export const CheckmarkLargeIcon = wrapIcon(findProp<IconComponent>('CheckmarkLargeIcon')!)
export const CopyIcon = wrapIcon(findProp<IconComponent>('CopyIcon')!)
export const DownloadIcon = wrapIcon(findProp<IconComponent>('DownloadIcon')!)
export const FolderIcon = wrapIcon(findProp<IconComponent>('FolderIcon')!)
2 changes: 2 additions & 0 deletions libraries/modules/src/common/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export const {
}>('TextField', 'ContextMenu')!,
)

export const IntlLink = findProp<DiscordModules.Components.IntlLink>('IntlLink')!

export const PressableScale = findProp('PressableScale')

// Tables
Expand Down
1 change: 0 additions & 1 deletion libraries/modules/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export const NavigationNative = findByProps<

export type NavigationNativeStackParamList = {
RevengeCustomPage: { render: ComponentType } & StackNavigationOptions
// biome-ignore lint/suspicious/noExplicitAny: https://github.com/react-navigation/react-navigation/issues/9037
[Page: string]: any
}

Expand Down
15 changes: 8 additions & 7 deletions libraries/modules/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export namespace Metro {
/** Set to undefined once module is initialized */
dependencyMap: If<Initialized, undefined, DependencyMap>
/** Error value thrown by the factory */
// biome-ignore lint/suspicious/noExplicitAny: This is okay
error?: any
/** Set to undefined once module is initialized */
factory: If<Initialized, undefined, FactoryFn>
Expand Down Expand Up @@ -108,7 +107,6 @@ export namespace Metro {
}) => ModuleID
}

// biome-ignore lint/suspicious/noExplicitAny: This is okay
export type ModuleExports = any
}

Expand Down Expand Up @@ -190,7 +188,7 @@ export namespace DiscordModules {
}

export interface FilePickerUtils {
handleDocumentSelection(options?: { pickMultiple?: boolean }): Promise<FilePickerFile[]>
handleDocumentSelection(options?: { pickMultiple?: boolean }): Promise<FilePickerFile[] | undefined>
}

export interface ToastActionCreators {
Expand Down Expand Up @@ -240,9 +238,7 @@ export namespace DiscordModules {
}

export namespace Flux {
// biome-ignore lint/suspicious/noExplicitAny: shuddhup
export type DispatcherPayload = any
// biome-ignore lint/suspicious/noExplicitAny: shuddhup again
export type DispatcherDependency = any

export interface Dispatcher {
Expand Down Expand Up @@ -584,7 +580,7 @@ export namespace DiscordModules {

// Menus
export type ContextMenu = FC<{
title: string
title: ReactNode
triggerOnLongPress?: boolean
items: Array<ContextMenuItem | ContextMenuItem[]>
align?: 'left' | 'right' | 'above' | 'below'
Expand All @@ -610,7 +606,7 @@ export namespace DiscordModules {
startIcon?: ReactNode
endIcon?: ReactNode
}>
export type FlashList = FC

export type Text = FC<
TextProps & {
variant?: DiscordModules.Styles.TextVariant
Expand All @@ -622,5 +618,10 @@ export namespace DiscordModules {
children?: ReactNode
}
>

export type IntlLink = FC<{
target: string
children?: ReactNode
}>
}
}
1 change: 0 additions & 1 deletion libraries/patcher/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Metro } from '@revenge-mod/modules'
type WrappableName = 'after' | 'before' | 'instead'
type UnpatchFunction = () => boolean

// biome-ignore lint/suspicious/noExplicitAny: This is a valid use case
type SafeParameters<T> = T extends (...args: infer P) => any ? P : any[]

type KeysWithFunctionValues<T extends AnyObject> = {
Expand Down
3 changes: 0 additions & 3 deletions libraries/patcher/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { patcherLazyModuleSymbol } from '.'
import type { AwaitedWrappable, OnceModuleLoadedCallback, Wrappable, WrappableName } from './types'

// biome-ignore lint/suspicious/noExplicitAny: This is alright, I think
type CallableFunction = (...args: any[]) => any

export function createExtendedPatchFunction<N extends WrappableName>(fn: CallableFunction) {
// biome-ignore lint/suspicious/noExplicitAny: I'm not going out of my way to type this
function patchFn(this: any, ...args: any) {
if (patcherLazyModuleSymbol in args[0]) {
const onceModuleLoaded = args[0][patcherLazyModuleSymbol] as OnceModuleLoadedCallback
Expand All @@ -25,7 +23,6 @@ export function createExtendedPatchFunction<N extends WrappableName>(fn: Callabl
return fn.apply(this, args)
}

// biome-ignore lint/suspicious/noExplicitAny: I'm not going out of my way to type this
function promisePatchFn(this: any, ...args: [Promise<any>, ...any[]]) {
const thenable = args[0]
if (!thenable || !('then' in thenable)) throw new Error('Cannot await a non-thenable object')
Expand Down
4 changes: 3 additions & 1 deletion libraries/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"scripts": {},
"exports": {
".": "./src/index.ts",
"./internals": "./src/internals.ts"
"./constants": "./src/constants.ts",
"./internals": "./src/internals.ts",
"./schemas": "./src/schemas.ts"
},
"dependencies": {
"@revenge-mod/app": "workspace:*",
Expand Down
37 changes: 29 additions & 8 deletions libraries/plugins/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { InternalPluginDefinition } from './internals'
import type { PluginStopConfig } from './types'

export const PluginIdRegex = /^[a-z0-9-_\.]{1,128}$/

/**
* The keys that plugins are allowed to access in the plugin object
*/
export const WhitelistedPluginObjectKeys = [
'description',
'disable',
Expand All @@ -12,13 +14,32 @@ export const WhitelistedPluginObjectKeys = [
'stop',
'author',
'errors',
// biome-ignore lint/suspicious/noExplicitAny: get out
] as const satisfies ReadonlyArray<keyof InternalPluginDefinition<any, any, any>>

export const DefaultPluginStopConfig: Required<PluginStopConfig> = {
reloadRequired: false,
}

export const PluginStatus = {
Stopped: 1,
Fetching: 2,
StartedEarly: 3,
Starting: 4,
Started: 5,
Stopped: 0,
Fetching: 1,
Starting: 2,
Started: 3,
}

export type PluginStatus = (typeof PluginStatus)[keyof typeof PluginStatus]

export const PluginZipFileSizeLimit = 16 * 1024 * 1024 // 16 MB

export const InstallPluginResult = {
Success: 0,
AlreadyInstalled: 1,
InvalidManifest: 2,
InvalidFileFormat: 10,
InvalidKeyFileFormat: 11,
InvalidSignatureFileFormat: 12,
SignatureVerificationFailed: 20,
UnsignedUserConfirmationNeeded: 21,
} as const

export type PluginInstallResult = (typeof InstallPluginResult)[keyof typeof InstallPluginResult]
Loading

0 comments on commit f2f1365

Please sign in to comment.