revenge-bundle-next/src/plugins/start/developer-kit/index.ts
PalmDevs 3f60b4dfb7
feat!: more plugin system improvements + API changes + other fixes
BREAKING CHANGES:

- lib/modules!: Renamed `callBridgeMethod*` to `callNativeMethod*` and interface `Methods` to `NativeMethods`. This is to achieve naming consistency with the native API and be more clear.
- lib/storage!: Renamed to `@revenge-mod/json-storage`. A storage can be in any arbitrary format. While there's little potential for non-JSON storage formats, but the naming should allow for it regardless. This is not a drop-in replacements. There are breaking changes in export names and new APIs.
- plugins/revenge.api.storage!: Renamed to `revenge.api.jsonStorage`. Plugin options are renamed and its structure has changed as well.
- Native now holds the path for official storage APIs. This update uses new paths without any migration!
- lib/plugins!: `Plugin.errors` is now read-only. Use `Plugin.reportError(e)` instead.
- lib/plugins!: `Plugin.flags` has been completely removed in favor of these methods: `Plugin.requireReload()`, `Plugin.disable()`.

OTHER CHANGES:

- Fixed sorting for 'Enabled first'
- Updated native method names to be more consistent
- Cleand up dead code
- Make methods more 'safe' by removing non-null assertion casts
2026-07-09 23:47:53 +07:00

82 lines
2.2 KiB
TypeScript

import {
onSettingsModulesLoaded,
refreshSettingsNavigator,
refreshSettingsOverviewScreen,
} from '@revenge-mod/discord/modules/settings'
import {
InternalPluginFlags,
isPluginEnabledLate,
PluginFlags,
registerPlugin,
} from '@revenge-mod/plugins/_'
import pluginSettings from '../settings'
import * as dt from './devtools'
import defer * as rdt from './react-devtools'
import defer * as utils from './utils'
import type { PluginApi } from '@revenge-mod/plugins/types'
interface Storage {
devTools: DevToolsSettings & { alias?: string }
reactDevTools: DevToolsSettings
}
interface DevToolsSettings {
address: string
autoConnect: boolean
}
const defaultStorage: Storage = {
devTools: {
address: 'localhost:7864',
autoConnect: false,
},
reactDevTools: {
address: 'localhost:8097',
autoConnect: false,
},
}
// TODO(PalmDevs): only register in development builds once updates can be made automatic
registerPlugin<{ jsonStorage: Storage }>(
{
id: 'revenge.developer-kit',
name: 'Developer Kit',
description: 'Tools assisting Revenge developers.',
author: 'Revenge',
icon: 'WrenchIcon',
dependencies: [pluginSettings],
},
{
jsonStorage: {
load: true,
default: defaultStorage,
},
async start(api_) {
api = api_
onSettingsModulesLoaded(utils.register)
if (isPluginEnabledLate(api_.plugin)) {
refreshSettingsOverviewScreen()
refreshSettingsNavigator()
}
const settings = await api.jsonStorage.get()
dt.DTContext.addr = settings.devTools.address
dt.DTContext.alias = settings.devTools.alias ?? ''
rdt.RDTContext.addr = settings.reactDevTools.address
if (settings.devTools.autoConnect) dt.connect()
if (settings.reactDevTools.autoConnect) rdt.connect()
},
stop({ cleanup }) {
cleanup(refreshSettingsOverviewScreen, refreshSettingsNavigator)
},
},
PluginFlags.Enabled,
InternalPluginFlags.Internal,
)
// Expose to EvalJSSetting
export let api: PluginApi<{ jsonStorage: Storage }>