feat(plugin/settings): expose plugin APIs during eval
This commit is contained in:
parent
0cc3e215eb
commit
51f86d7d6f
2 changed files with 22 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ import { Components } from '@revenge-mod/discord/ui'
|
|||
|
||||
import { getErrorStack } from '@revenge-mod/utils/errors'
|
||||
|
||||
import { pluginApi } from '..'
|
||||
import AssetIcon from '../components/icons/AssetIcon'
|
||||
|
||||
import type { SettingsItem } from '@revenge-mod/discord/ui/settings'
|
||||
|
|
@ -94,15 +95,30 @@ function EvaluateJavaScriptAlert() {
|
|||
setLoading(true)
|
||||
|
||||
try {
|
||||
if (!pluginApi) {
|
||||
alert('Unable to provide plugin API. Running snippet in a second...')
|
||||
await new Promise(rs => setTimeout(rs, 1000))
|
||||
} else {
|
||||
// @ts-expect-error
|
||||
globalThis.revenge = pluginApi.unscoped
|
||||
// @ts-expect-error
|
||||
globalThis.api = pluginApi
|
||||
}
|
||||
|
||||
// Do a no-local-scope-access eval
|
||||
// biome-ignore lint/security/noGlobalEval: This is intentional
|
||||
const res = globalThis.eval?.(code.current)
|
||||
|
||||
alert(
|
||||
nodeUtils.inspect(awaitResult && res instanceof Promise ? await res : res, {
|
||||
depth: inspectDepth,
|
||||
showHidden,
|
||||
}),
|
||||
)
|
||||
|
||||
// @ts-expect-error
|
||||
// biome-ignore lint/performance/noDelete: This is fine.
|
||||
delete globalThis.revenge, delete globalThis.api
|
||||
} catch (e) {
|
||||
alert(getErrorStack(e))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { PluginFlags } from '@revenge-mod/plugins'
|
||||
import { PluginFlags, type PluginApi } from '@revenge-mod/plugins'
|
||||
import { InternalPluginFlags, registerPlugin } from '@revenge-mod/plugins/_'
|
||||
|
||||
import { waitForModules } from '@revenge-mod/modules/finders'
|
||||
|
|
@ -26,6 +26,8 @@ import EvaluateJavaScriptSetting from './definitions/EvaluateJavaScriptSetting'
|
|||
|
||||
import type { FC } from 'react'
|
||||
|
||||
export let pluginApi: PluginApi
|
||||
|
||||
registerPlugin(
|
||||
{
|
||||
id: 'revenge.settings',
|
||||
|
|
@ -35,7 +37,9 @@ registerPlugin(
|
|||
icon: 'SettingsIcon',
|
||||
},
|
||||
{
|
||||
start() {
|
||||
start(api) {
|
||||
pluginApi = api
|
||||
|
||||
for (const [key, setting] of [
|
||||
[MobileSetting.REVENGE, RevengeSetting],
|
||||
[MobileSetting.REVENGE_PLUGINS, RevengePluginsSetting],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue