fix(lib)!: refactor structure
This commit is contained in:
parent
98b84a43c7
commit
ef5f2ce87c
31 changed files with 288 additions and 149 deletions
|
|
@ -9,29 +9,38 @@
|
|||
"./actions": {
|
||||
"default": "./src/actions.ts"
|
||||
},
|
||||
"./flux": {
|
||||
"default": "./src/flux.ts"
|
||||
"./common": {
|
||||
"default": "./src/common/index.ts"
|
||||
},
|
||||
"./common/flux": {
|
||||
"default": "./src/common/flux.ts"
|
||||
},
|
||||
"./design": {
|
||||
"default": "./src/design/index.ts"
|
||||
},
|
||||
"./design/components": {
|
||||
"default": "./src/design/components/index.ts"
|
||||
},
|
||||
"./design/components/Icon": {
|
||||
"default": "./src/design/components/Icon.ts"
|
||||
},
|
||||
"./native": {
|
||||
"default": "./src/native.ts"
|
||||
},
|
||||
"./polyfills": {
|
||||
"default": "./src/polyfills.ts"
|
||||
},
|
||||
"./preinit": {
|
||||
"default": "./src/preinit.ts"
|
||||
},
|
||||
"./settings": {
|
||||
"default": "./src/settings/index.ts"
|
||||
"./modules": {
|
||||
"default": "./src/modules/index.ts"
|
||||
},
|
||||
"./modules/settings": {
|
||||
"default": "./src/modules/settings/index.ts"
|
||||
},
|
||||
"./types": {
|
||||
"types": "./types/index.ts"
|
||||
},
|
||||
"./ui": {
|
||||
"default": "./src/ui/index.ts"
|
||||
},
|
||||
"./_/settings": {
|
||||
"default": "./src/settings/_internal.ts"
|
||||
"./_/modules/settings": {
|
||||
"default": "./src/modules/settings/_internal.ts"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,12 +12,45 @@ import { ReactJsxRuntimeModuleId, ReactModuleId } from '@revenge-mod/react'
|
|||
|
||||
import { proxify } from '@revenge-mod/utils/proxy'
|
||||
|
||||
import { DispatcherModuleId } from './common/flux'
|
||||
|
||||
import type { DiscordModules } from '../types'
|
||||
|
||||
export let ActionSheetActionCreators: DiscordModules.Actions.ActionSheetActionCreators = proxify(
|
||||
() => {
|
||||
const module = lookupModule(
|
||||
moduleStateAware(
|
||||
byProps<DiscordModules.Actions.ActionSheetActionCreators>('hideActionSheet'),
|
||||
byDependencies([
|
||||
undefined,
|
||||
ReactModuleId,
|
||||
ReactJsxRuntimeModuleId,
|
||||
DispatcherModuleId,
|
||||
relativeDep(1),
|
||||
relativeDep(2),
|
||||
2,
|
||||
]),
|
||||
),
|
||||
{
|
||||
includeUninitialized: true,
|
||||
},
|
||||
)
|
||||
|
||||
if (module) {
|
||||
// This allows the Proxy instance to be garbage collected
|
||||
// after the module is initialized.
|
||||
ActionSheetActionCreators = module
|
||||
gc()
|
||||
return module
|
||||
}
|
||||
},
|
||||
{
|
||||
hint: 'object',
|
||||
},
|
||||
)!
|
||||
|
||||
export let AlertActionCreators: DiscordModules.Actions.AlertActionCreators = proxify(
|
||||
() => {
|
||||
// ID: 3667
|
||||
// [175, 180, 2553, 684, 1249, 3668, 1675, 2]
|
||||
const module = lookupModule(
|
||||
moduleStateAware(
|
||||
byProps<DiscordModules.Actions.AlertActionCreators>('openAlert', 'dismissAlert'),
|
||||
|
|
@ -25,7 +58,7 @@ export let AlertActionCreators: DiscordModules.Actions.AlertActionCreators = pro
|
|||
ReactModuleId,
|
||||
ReactJsxRuntimeModuleId,
|
||||
undefined,
|
||||
undefined,
|
||||
DispatcherModuleId,
|
||||
relativeDep(1),
|
||||
undefined,
|
||||
2,
|
||||
|
|
@ -48,15 +81,12 @@ export let AlertActionCreators: DiscordModules.Actions.AlertActionCreators = pro
|
|||
|
||||
export let ToastActionCreators: DiscordModules.Actions.ToastActionCreators = proxify(() => {
|
||||
// Many other modules share the same dependencies, the second yielded should be the correct module.
|
||||
// [684, 2]
|
||||
|
||||
// Dispatcher.tsx (ID: 684)
|
||||
// [685, 652, 606, 585, 806, 2]
|
||||
// [Dispatcher, ImportTracker]
|
||||
|
||||
const generator = lookupModules(
|
||||
moduleStateAware(
|
||||
every(byProps<DiscordModules.Actions.ToastActionCreators>('open'), withoutProps('init')),
|
||||
byDependencies([[relativeDep(1), undefined, undefined, undefined, undefined, 2], 2]),
|
||||
byDependencies([DispatcherModuleId, 2]),
|
||||
),
|
||||
{
|
||||
includeUninitialized: true,
|
||||
|
|
|
|||
28
lib/discord/src/common/flux.ts
Normal file
28
lib/discord/src/common/flux.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { lookupModuleId, waitForModules } from '@revenge-mod/modules/finders'
|
||||
import { byDependencies, byProps, moduleStateAware, relativeDep } from '@revenge-mod/modules/finders/filters'
|
||||
|
||||
import type { DiscordModules } from '../../types'
|
||||
|
||||
export const DispatcherModuleId = lookupModuleId(
|
||||
moduleStateAware(
|
||||
byProps<DiscordModules.Flux.Dispatcher>('_interceptors'),
|
||||
byDependencies([relativeDep(1), undefined, undefined, undefined, undefined, 2]),
|
||||
),
|
||||
{
|
||||
includeUninitialized: true,
|
||||
},
|
||||
)
|
||||
|
||||
export const Dispatcher = __r(DispatcherModuleId!) as DiscordModules.Flux.Dispatcher
|
||||
|
||||
waitForModules(byProps<DiscordModules.Flux.Store>('_dispatchToken'), (_, store) => {
|
||||
const name = store.getName()
|
||||
_stores[name] = store
|
||||
})
|
||||
|
||||
const _stores: Record<string, any> = {}
|
||||
|
||||
export const stores = new Proxy(_stores, {
|
||||
ownKeys: () => Reflect.ownKeys(_stores),
|
||||
get: (_, name) => stores[name as string],
|
||||
})
|
||||
13
lib/discord/src/common/index.ts
Normal file
13
lib/discord/src/common/index.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { lookupModule, lookupModuleId } from '@revenge-mod/modules/finders'
|
||||
import { byName, byProps } from '@revenge-mod/modules/finders/filters'
|
||||
|
||||
import type { DiscordModules } from '../../types'
|
||||
|
||||
// ../discord_common/js/packages/flux
|
||||
export * as flux from './flux'
|
||||
|
||||
// ../discord_common/js/shared/Logger.tsx
|
||||
export const Logger = lookupModule(byName<DiscordModules.Logger>('Logger'))!
|
||||
// ../discord_common/js/packages/tokens/native.tsx
|
||||
export const tokensModuleId = lookupModuleId(byProps('RawColor'))!
|
||||
export const tokens = __r(tokensModuleId)
|
||||
29
lib/discord/src/design/components/Icon.ts
Normal file
29
lib/discord/src/design/components/Icon.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { getAssetByName, getAssetModuleId } from '@revenge-mod/assets'
|
||||
|
||||
import { lookupModule } from '@revenge-mod/modules/finders'
|
||||
import { byDependencies, byProps } from '@revenge-mod/modules/finders/filters'
|
||||
|
||||
import { ReactJsxRuntimeModuleId, ReactModuleId } from '@revenge-mod/react'
|
||||
|
||||
import { tokensModuleId } from '../../common'
|
||||
|
||||
import type { FC } from 'react'
|
||||
|
||||
// [React, ReactJsxRuntime, (BaseIconImage), (Tokens), (Asset), 2]
|
||||
// Asset = relativeDep(1)
|
||||
const filter = [ReactModuleId, ReactJsxRuntimeModuleId, tokensModuleId, undefined, undefined, 2]
|
||||
|
||||
export function lookupGeneratedIconComponent<N extends string>(name: N) {
|
||||
const icon = lookupModule(byProps(name))?.[name]
|
||||
if (icon) return icon
|
||||
|
||||
const mid = getAssetModuleId(getAssetByName(name)!)!
|
||||
if (!mid) return
|
||||
|
||||
filter[4] = mid
|
||||
|
||||
return lookupModule(byDependencies<{ [K in N]: FC }>(filter), {
|
||||
includeInitialized: false,
|
||||
includeUninitialized: true,
|
||||
})?.[name]
|
||||
}
|
||||
1
lib/discord/src/design/components/_exports.ts
Normal file
1
lib/discord/src/design/components/_exports.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * as Icon from './Icon'
|
||||
|
|
@ -3,9 +3,10 @@ import { byDependencies, byProps, looseDeps, moduleStateAware, relativeDep } fro
|
|||
|
||||
import { proxify } from '@revenge-mod/utils/proxy'
|
||||
|
||||
import type { DiscordModules } from '../../types'
|
||||
import type { DiscordModules } from '../../../types'
|
||||
|
||||
export let Components: Components = proxify(
|
||||
// design/native.tsx
|
||||
let components: Components = proxify(
|
||||
() => {
|
||||
// ID: 3236
|
||||
// [3237, 1366, 3238, 3239, 2, ...];
|
||||
|
|
@ -22,7 +23,7 @@ export let Components: Components = proxify(
|
|||
if (module) {
|
||||
// This allows the Proxy instance to be garbage collected
|
||||
// after the module is initialized.
|
||||
Components = module
|
||||
components = module
|
||||
gc()
|
||||
return module
|
||||
}
|
||||
|
|
@ -32,6 +33,8 @@ export let Components: Components = proxify(
|
|||
},
|
||||
)!
|
||||
|
||||
export default components
|
||||
|
||||
export interface Components {
|
||||
ActionSheet: DiscordModules.Components.ActionSheet
|
||||
ActionSheetRow: DiscordModules.Components.ActionSheetRow
|
||||
9
lib/discord/src/design/index.ts
Normal file
9
lib/discord/src/design/index.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import components_ from './components'
|
||||
import * as components_exports from './components/_exports'
|
||||
|
||||
const components = {
|
||||
...components_,
|
||||
...components_exports,
|
||||
}
|
||||
|
||||
export { components }
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
import { waitForModules } from '@revenge-mod/modules/finders'
|
||||
import { byProps } from '@revenge-mod/modules/finders/filters'
|
||||
|
||||
import type { DiscordModules } from '../types'
|
||||
|
||||
waitForModules(byProps<DiscordModules.Flux.Store>('_dispatchToken'), (_, store) => {
|
||||
const name = store.getName()
|
||||
_stores[name] = store
|
||||
})
|
||||
|
||||
const _stores: Record<string, any> = {}
|
||||
|
||||
export const stores = new Proxy(_stores, {
|
||||
ownKeys: () => Reflect.ownKeys(_stores),
|
||||
get: (_, name) => stores[name as string],
|
||||
})
|
||||
|
|
@ -1,16 +1,7 @@
|
|||
import { lookupModule } from '@revenge-mod/modules/finders'
|
||||
import { byName, byProps } from '@revenge-mod/modules/finders/filters'
|
||||
|
||||
import type { DiscordModules } from '../types'
|
||||
|
||||
export * from './preinit'
|
||||
|
||||
export * as flux from './flux'
|
||||
export * as actions from './actions'
|
||||
export * as common from './common'
|
||||
export * as design from './design'
|
||||
export * as modules from './modules'
|
||||
export * as native from './native'
|
||||
export * as settings from './settings'
|
||||
export * as ui from './ui'
|
||||
|
||||
// ../discord_common/js/shared/Logger.tsx
|
||||
export const Logger = lookupModule(byName<DiscordModules.Logger>('Logger'))!
|
||||
// ../discord_common/js/packages/tokens/native.tsx
|
||||
export const tokens = lookupModule(byProps('RawColor'))!
|
||||
|
|
|
|||
1
lib/discord/src/modules/index.ts
Normal file
1
lib/discord/src/modules/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * as settings from './settings'
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { _data, _subs } from './_internal'
|
||||
|
||||
import type { ComponentType, ReactNode } from 'react'
|
||||
import type { DiscordModules } from '../../types'
|
||||
import type { DiscordModules } from '../../../types'
|
||||
|
||||
export type SettingsModulesLoadedSubscription = () => void
|
||||
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import { lookupModule } from '@revenge-mod/modules/finders'
|
||||
import { byDependencies, byProps, moduleStateAware, relativeDep } from '@revenge-mod/modules/finders/filters'
|
||||
|
||||
export const nodeUtils = lookupModule(moduleStateAware(byProps('inspect'), byDependencies([relativeDep(1), [], []])), {
|
||||
includeInitialized: false,
|
||||
includeUninitialized: true,
|
||||
})! as typeof import('node:util')
|
||||
|
|
@ -1 +0,0 @@
|
|||
export * from './common'
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
import type { ComponentProps, FC, ReactNode } from 'react'
|
||||
import type { Buffer as _Buffer } from 'buffer'
|
||||
|
||||
import type { ComponentProps, ComponentType, FC, ReactNode } from 'react'
|
||||
import type {
|
||||
ImageSourcePropType,
|
||||
ImageStyle,
|
||||
|
|
@ -157,6 +159,35 @@ export namespace DiscordModules {
|
|||
}): void
|
||||
close(): void
|
||||
}
|
||||
|
||||
export interface ActionSheetActionCreators {
|
||||
openLazy<T extends ComponentType>(
|
||||
sheet: Promise<{ default: T }>,
|
||||
key: string,
|
||||
props: ComponentProps<T>,
|
||||
): void
|
||||
hideActionSheet(key?: string): void
|
||||
}
|
||||
|
||||
// export namespace ActionSheetActionCreators {
|
||||
// interface SimpleActionSheetOption {
|
||||
// icon?: number
|
||||
// label: string
|
||||
// isDestructive?: boolean
|
||||
// disabled?: boolean
|
||||
// onPress?(): void
|
||||
// }
|
||||
|
||||
// function showSimpleActionSheet(options: {
|
||||
// key: string
|
||||
// header: {
|
||||
// title: string
|
||||
// icon?: ReactNode
|
||||
// onClose?(): void
|
||||
// }
|
||||
// options: SimpleActionSheetOption[]
|
||||
// }): void
|
||||
// }
|
||||
}
|
||||
|
||||
export namespace Components {
|
||||
|
|
@ -458,3 +489,9 @@ export namespace DiscordModules {
|
|||
export type Slider = FC<SliderProps>
|
||||
}
|
||||
}
|
||||
|
||||
/// POLYFILLS
|
||||
|
||||
declare global {
|
||||
var Buffer: typeof _Buffer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@
|
|||
"./init": {
|
||||
"default": "./src/init.ts"
|
||||
},
|
||||
"./types": {
|
||||
"default": "./types.ts"
|
||||
},
|
||||
"./_": {
|
||||
"default": "./src/_internal.ts"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,21 @@ import * as PluginsLibrary from '@revenge-mod/plugins'
|
|||
import * as ReactLibrary from '@revenge-mod/react'
|
||||
import * as UtilsLibrary from '@revenge-mod/utils'
|
||||
|
||||
const { PluginFlags, PluginStatus } = PluginsLibrary
|
||||
import type {
|
||||
InitPluginApi,
|
||||
Plugin,
|
||||
PluginApi,
|
||||
PluginCleanup,
|
||||
PluginFlags,
|
||||
PluginLifecycles,
|
||||
PluginManifest,
|
||||
UnscopedInitPluginApi,
|
||||
UnscopedPluginApi,
|
||||
} from '../types'
|
||||
|
||||
export const _uapi: PluginsLibrary.UnscopedInitPluginApi | PluginsLibrary.UnscopedPluginApi = {
|
||||
const { PluginFlags: Flag, PluginStatus: Status } = PluginsLibrary
|
||||
|
||||
export const _uapi: UnscopedInitPluginApi | UnscopedPluginApi = {
|
||||
discord: DiscordLibrary,
|
||||
modules: ModulesLibrary,
|
||||
patcher: PatcherLibrary,
|
||||
|
|
@ -16,13 +28,13 @@ export const _uapi: PluginsLibrary.UnscopedInitPluginApi | PluginsLibrary.Unscop
|
|||
utils: UtilsLibrary,
|
||||
}
|
||||
|
||||
const _plugins = new Map<PluginsLibrary.PluginManifest['id'], InternalPlugin>()
|
||||
const _pluginIFlags = new Map<PluginsLibrary.PluginManifest['id'], InternalPluginFlags>()
|
||||
const _plugins = new Map<PluginManifest['id'], InternalPlugin>()
|
||||
const _pluginIFlags = new Map<PluginManifest['id'], InternalPluginFlags>()
|
||||
|
||||
export function registerPlugin(
|
||||
manifest: PluginsLibrary.PluginManifest,
|
||||
lifecycles: PluginsLibrary.PluginLifecycles,
|
||||
flags: PluginsLibrary.PluginFlags,
|
||||
manifest: PluginManifest,
|
||||
lifecycles: PluginLifecycles,
|
||||
flags: PluginFlags,
|
||||
iFlags: InternalPluginFlags,
|
||||
) {
|
||||
// TODO(plugins): verify plugin manifest
|
||||
|
|
@ -32,8 +44,8 @@ export function registerPlugin(
|
|||
|
||||
const handleError = (e: unknown) => {
|
||||
plugin.errors.push(e)
|
||||
plugin.flags |= PluginFlags.Errored
|
||||
if (plugin.flags & PluginFlags.Enabled) return plugin.disable()
|
||||
plugin.flags |= Flag.Errored
|
||||
if (plugin.flags & Flag.Enabled) return plugin.disable()
|
||||
}
|
||||
|
||||
const plugin: InternalPlugin = {
|
||||
|
|
@ -45,15 +57,15 @@ export function registerPlugin(
|
|||
status: 0,
|
||||
flags,
|
||||
prepareStart: () => {
|
||||
// const sapi = api as PluginsLibrary.PluginApi
|
||||
// const sapi = api as PluginApi
|
||||
// sapi.settings ??= ...
|
||||
},
|
||||
async init() {
|
||||
if (!(plugin.flags & PluginFlags.Enabled)) throw new Error(`Plugin "${manifest.id}" is not enabled`)
|
||||
if (plugin.status & (PluginStatus.Initing | PluginStatus.Inited))
|
||||
if (!(plugin.flags & Flag.Enabled)) throw new Error(`Plugin "${manifest.id}" is not enabled`)
|
||||
if (plugin.status & (Status.Initing | Status.Inited))
|
||||
throw new Error(`Plugin "${manifest.id}" is initializing or already initialized`)
|
||||
|
||||
plugin.status |= PluginStatus.Initing
|
||||
plugin.status |= Status.Initing
|
||||
|
||||
try {
|
||||
const prom = lifecycles.init?.(api)
|
||||
|
|
@ -61,55 +73,55 @@ export function registerPlugin(
|
|||
await prom
|
||||
|
||||
// plugin.disable() already handles, so it's the try block
|
||||
plugin.status |= PluginStatus.Inited
|
||||
plugin.status &= ~PluginStatus.Initing
|
||||
plugin.status |= Status.Inited
|
||||
plugin.status &= ~Status.Initing
|
||||
} catch (e) {
|
||||
await handleError(e)
|
||||
}
|
||||
},
|
||||
async start() {
|
||||
if (!(plugin.flags & PluginFlags.Enabled)) throw new Error(`Plugin "${manifest.id}" is not enabled`)
|
||||
if (plugin.status & (PluginStatus.Starting | PluginStatus.Started))
|
||||
if (!(plugin.flags & Flag.Enabled)) throw new Error(`Plugin "${manifest.id}" is not enabled`)
|
||||
if (plugin.status & (Status.Starting | Status.Started))
|
||||
throw new Error(`Plugin "${manifest.id}" is starting or already started`)
|
||||
|
||||
// Clear errors from previous runs
|
||||
plugin.errors = []
|
||||
plugin.status &= ~PluginFlags.Errored
|
||||
plugin.status &= ~Flag.Errored
|
||||
|
||||
plugin.status |= PluginStatus.Starting
|
||||
plugin.status |= Status.Starting
|
||||
|
||||
plugin.prepareStart()
|
||||
|
||||
try {
|
||||
const prom = lifecycles.start?.(api as PluginsLibrary.PluginApi)
|
||||
const prom = lifecycles.start?.(api as PluginApi)
|
||||
plugin.promises.push(prom)
|
||||
await prom
|
||||
|
||||
// plugin.disable() already handles, so it's in the try block
|
||||
plugin.status |= PluginStatus.Started
|
||||
plugin.status &= ~PluginStatus.Starting
|
||||
plugin.status |= Status.Started
|
||||
plugin.status &= ~Status.Starting
|
||||
} catch (e) {
|
||||
await handleError(e)
|
||||
}
|
||||
},
|
||||
async stop() {
|
||||
if (!(plugin.flags & PluginFlags.Enabled)) throw new Error(`Plugin "${manifest.id}" is not enabled`)
|
||||
if (!(plugin.flags & Flag.Enabled)) throw new Error(`Plugin "${manifest.id}" is not enabled`)
|
||||
|
||||
if (plugin.status & PluginStatus.Stopping) throw new Error(`Plugin "${manifest.id}" is stopping`)
|
||||
if (plugin.status & Status.Stopping) throw new Error(`Plugin "${manifest.id}" is stopping`)
|
||||
|
||||
// If the plugin is initializing or starting, we need to wait for it to finish, then we'll stop it
|
||||
if (plugin.status & (PluginStatus.Initing | PluginStatus.Starting)) await Promise.all(plugin.promises)
|
||||
if (plugin.status & (Status.Initing | Status.Starting)) await Promise.all(plugin.promises)
|
||||
|
||||
if (plugin.status & (PluginStatus.Inited | PluginStatus.Started))
|
||||
if (plugin.status & (Status.Inited | Status.Started))
|
||||
throw new Error(`Plugin "${manifest.id}" is not initialized started`)
|
||||
|
||||
// In case the plugin only has init() and stop()
|
||||
plugin.prepareStart()
|
||||
|
||||
plugin.status |= PluginStatus.Stopping
|
||||
plugin.status |= Status.Stopping
|
||||
|
||||
try {
|
||||
await lifecycles.stop?.(api as PluginsLibrary.PluginApi)
|
||||
await lifecycles.stop?.(api as PluginApi)
|
||||
} catch (e) {
|
||||
await handleError(e)
|
||||
} finally {
|
||||
|
|
@ -119,7 +131,7 @@ export function registerPlugin(
|
|||
if (result.status === 'rejected') {
|
||||
await handleError(result.reason)
|
||||
// Some cleanup was unsuccessful, so we need to reload the app
|
||||
plugin.flags |= PluginFlags.ReloadRequired
|
||||
plugin.flags |= Flag.ReloadRequired
|
||||
}
|
||||
|
||||
// Clear unnecessary data
|
||||
|
|
@ -133,21 +145,25 @@ export function registerPlugin(
|
|||
}
|
||||
},
|
||||
async enable() {
|
||||
plugin.flags |= PluginFlags.Enabled
|
||||
plugin.flags |= Flag.Enabled
|
||||
},
|
||||
async disable() {
|
||||
plugin.flags &= ~PluginFlags.Enabled
|
||||
plugin.flags &= ~Flag.Enabled
|
||||
|
||||
// If plugin is not stopped, and is also not stopping, we need to stop it
|
||||
if (plugin.status && !(plugin.status & PluginStatus.Stopping)) await plugin.stop()
|
||||
if (plugin.status && !(plugin.status & Status.Stopping)) await plugin.stop()
|
||||
},
|
||||
}
|
||||
|
||||
const api: PluginsLibrary.InitPluginApi | PluginsLibrary.PluginApi = {
|
||||
let logger: InstanceType<typeof DiscordLibrary.common.Logger>
|
||||
|
||||
const api: InitPluginApi | PluginApi = {
|
||||
cleanup: (...items) => {
|
||||
plugin.cleanups.push(...items)
|
||||
},
|
||||
logger: new DiscordLibrary.Logger(`Revenge > ${plugin.manifest.name}`),
|
||||
get logger() {
|
||||
return (logger ??= new DiscordLibrary.common.Logger(`Revenge > ${manifest.name}`))
|
||||
},
|
||||
plugin,
|
||||
unscoped: _uapi,
|
||||
}!
|
||||
|
|
@ -157,27 +173,27 @@ export function registerPlugin(
|
|||
|
||||
export function getEnabledPluginsCount() {
|
||||
let count = 0
|
||||
for (const plugin of _plugins.values()) if (plugin.flags & PluginFlags.Enabled) count++
|
||||
for (const plugin of _plugins.values()) if (plugin.flags & Flag.Enabled) count++
|
||||
return count
|
||||
}
|
||||
|
||||
export async function initPlugins() {
|
||||
const promises: Promise<void>[] = []
|
||||
for (const plugin of _plugins.values()) if (plugin.flags & PluginFlags.Enabled) promises.push(plugin.init())
|
||||
for (const plugin of _plugins.values()) if (plugin.flags & Flag.Enabled) promises.push(plugin.init())
|
||||
// These Promises never throw, so it is fine
|
||||
await Promise.all(promises)
|
||||
}
|
||||
|
||||
export async function startPlugins() {
|
||||
const promises: Promise<void>[] = []
|
||||
for (const plugin of _plugins.values()) if (plugin.flags & PluginFlags.Enabled) promises.push(plugin.start())
|
||||
for (const plugin of _plugins.values()) if (plugin.flags & Flag.Enabled) promises.push(plugin.start())
|
||||
// These Promises never throw, so it is fine
|
||||
await Promise.all(promises)
|
||||
}
|
||||
|
||||
export interface InternalPlugin extends PluginsLibrary.Plugin {
|
||||
export interface InternalPlugin extends Plugin {
|
||||
promises: Promise<void>[]
|
||||
cleanups: PluginsLibrary.PluginCleanup[]
|
||||
cleanups: PluginCleanup[]
|
||||
prepareStart(): void
|
||||
init(): Promise<void>
|
||||
start(): Promise<void>
|
||||
|
|
|
|||
|
|
@ -20,7 +20,3 @@ export const PluginStatus = {
|
|||
Started: 1 << 3,
|
||||
Stopping: 1 << 4,
|
||||
}
|
||||
|
||||
export type PluginFlags = (typeof PluginFlags)[keyof typeof PluginFlags]
|
||||
|
||||
export type PluginStatus = (typeof PluginStatus)[keyof typeof PluginStatus]
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
export * from './constants'
|
||||
export * from './types'
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { ReactNative } from '@revenge-mod/react'
|
|||
|
||||
import { _uapi, initPlugins, startPlugins } from './_internal'
|
||||
|
||||
import type { UnscopedPluginApi } from './types'
|
||||
import type { UnscopedPluginApi } from '../types'
|
||||
|
||||
// Setup non-limited APIs
|
||||
const uapi = _uapi as UnscopedPluginApi
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import type { DiscordModules } from '@revenge-mod/discord/types'
|
||||
|
||||
import type { PluginFlags, PluginStatus } from './constants'
|
||||
import type { PluginFlags as PF, PluginStatus as PS } from './src/constants'
|
||||
|
||||
export type PluginFlags = (typeof PF)[keyof typeof PF]
|
||||
export type PluginStatus = (typeof PS)[keyof typeof PS]
|
||||
|
||||
/**
|
||||
* The unscoped plugin API (limited). This API is available as a global for plugins.
|
||||
|
|
@ -11,6 +11,9 @@
|
|||
},
|
||||
"./preinit": {
|
||||
"default": "./src/preinit.ts"
|
||||
},
|
||||
"./types": {
|
||||
"default": "./types.ts"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { byProps } from '@revenge-mod/modules/finders/filters'
|
|||
import { yielded } from '@revenge-mod/utils/generators'
|
||||
|
||||
export * as jsxRuntime from './jsx-runtime'
|
||||
export * from '../types'
|
||||
|
||||
export const ReactModuleId = yielded(lookupModuleIds(byProps<typeof import('react')>('useState')), 1)!
|
||||
export const ReactNativeModuleId = lookupModuleId(byProps<typeof import('react-native')>('AppRegistry'))!
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
import './jsx-runtime/preinit'
|
||||
import './jsx-runtime/patches'
|
||||
|
|
|
|||
23
lib/react/types.ts
Normal file
23
lib/react/types.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
export namespace ReactNative {
|
||||
export namespace AssetsRegistry {
|
||||
export type AssetDestPathResolver = 'android' | 'generic'
|
||||
|
||||
export interface PackagerAsset {
|
||||
__packager_asset: boolean
|
||||
fileSystemLocation?: string
|
||||
httpServerLocation?: string
|
||||
width?: number
|
||||
height?: number
|
||||
scales: number[]
|
||||
hash: string
|
||||
name: string
|
||||
type: string
|
||||
resolver?: AssetDestPathResolver
|
||||
}
|
||||
}
|
||||
|
||||
export interface AssetsRegistry {
|
||||
registerAsset(asset: AssetsRegistry.PackagerAsset): number
|
||||
getAssetByID(assetId: number): AssetsRegistry.PackagerAsset
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"default": "./types.d.ts"
|
||||
"types": "./types.d.ts"
|
||||
},
|
||||
"./tsconfig": {
|
||||
"default": "./tsconfig.json"
|
||||
|
|
|
|||
46
lib/types/types.d.ts
vendored
46
lib/types/types.d.ts
vendored
|
|
@ -1,17 +1,17 @@
|
|||
// All of these typings are exported, be careful what you export here!
|
||||
|
||||
import type { Buffer as _Buffer } from 'buffer'
|
||||
/// <reference path="../../node_modules/react-native/types/index.d.ts" />
|
||||
|
||||
import type { Metro } from '@revenge-mod/modules/types'
|
||||
import type { ErrorUtils as RNErrorUtils } from 'react-native'
|
||||
|
||||
/// HERMES
|
||||
|
||||
declare global {
|
||||
declare function setTimeout(cb: (...args: unknown[]) => unknown, timeout?: number): number
|
||||
function setTimeout(cb: (...args: unknown[]) => unknown, timeout?: number): number
|
||||
/**
|
||||
* Calls the garbage collector
|
||||
*/
|
||||
declare function gc(): void
|
||||
function gc(): void
|
||||
|
||||
interface HermesInternalObject {
|
||||
getRuntimeProperties(): Record<string, string>
|
||||
|
|
@ -30,7 +30,7 @@ declare global {
|
|||
/// HERMES PROMISES
|
||||
|
||||
declare global {
|
||||
interface Promise {
|
||||
interface Promise<T> {
|
||||
/// PROMISE POLYFILLS FROM: https://github.com/then/promise
|
||||
/// AND: https://github.com/facebook/hermes/blob/main/lib/InternalBytecode/01-Promise.js
|
||||
_h: 0 | 1 | 2
|
||||
|
|
@ -73,8 +73,8 @@ declare global {
|
|||
/// REACT NATIVE
|
||||
|
||||
declare global {
|
||||
declare function nativeLoggingHook(str: string, level: number): void
|
||||
declare function alert(message: unknown): void
|
||||
function nativeLoggingHook(str: string, level: number): void
|
||||
function alert(message: unknown): void
|
||||
|
||||
var nativePerformanceNow: typeof performance.now
|
||||
var performance: {
|
||||
|
|
@ -82,36 +82,4 @@ declare global {
|
|||
}
|
||||
|
||||
var globalEvalWithSourceUrl: (code: string, sourceURL: string) => any
|
||||
|
||||
const ErrorUtils: RNErrorUtils
|
||||
}
|
||||
|
||||
/// POLYFILLS
|
||||
|
||||
declare global {
|
||||
var Buffer: typeof _Buffer
|
||||
}
|
||||
|
||||
export namespace ReactNative {
|
||||
namespace AssetsRegistry {
|
||||
export type AssetDestPathResolver = 'android' | 'generic'
|
||||
|
||||
export interface PackagerAsset {
|
||||
__packager_asset: boolean
|
||||
fileSystemLocation?: string
|
||||
httpServerLocation?: string
|
||||
width?: number
|
||||
height?: number
|
||||
scales: number[]
|
||||
hash: string
|
||||
name: string
|
||||
type: string
|
||||
resolver?: AssetDestPathResolver
|
||||
}
|
||||
}
|
||||
|
||||
export interface AssetsRegistry {
|
||||
registerAsset(asset: AssetsRegistry.PackagerAsset): number
|
||||
getAssetByID(assetId: number): AssetsRegistry.PackagerAsset
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue