fix: improve perf by not returning implicitly
This commit is contained in:
parent
255b4b4655
commit
77f8d62720
24 changed files with 87 additions and 35 deletions
|
|
@ -35,7 +35,9 @@ export interface Cache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const save = debounce(() => CacheStorage.set({}), 1000)
|
const save = debounce(() => {
|
||||||
|
CacheStorage.set({})
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
export function cacheAsset(asset: Asset, moduleId: Metro.ModuleID) {
|
export function cacheAsset(asset: Asset, moduleId: Metro.ModuleID) {
|
||||||
// Merge directly into the cache, only debouncing actual writes
|
// Merge directly into the cache, only debouncing actual writes
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,7 @@ export const [Dispatcher, DispatcherModuleId] = lookupModule(
|
||||||
) as [DiscordModules.Flux.Dispatcher, Metro.ModuleID]
|
) as [DiscordModules.Flux.Dispatcher, Metro.ModuleID]
|
||||||
|
|
||||||
waitForModules(byProps<DiscordModules.Flux.Store>('_dispatchToken'), store => {
|
waitForModules(byProps<DiscordModules.Flux.Store>('_dispatchToken'), store => {
|
||||||
const name = store.getName()
|
_stores[store.getName()] = store
|
||||||
_stores[name] = store
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const _stores: Record<string, any> = {}
|
const _stores: Record<string, any> = {}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,9 @@ export interface Cache {
|
||||||
| undefined
|
| undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const save = debounce(() => CacheStorage.set({}), 1000)
|
const save = debounce(() => {
|
||||||
|
CacheStorage.set({})
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
export function cacheFilterResult(
|
export function cacheFilterResult(
|
||||||
key: Filter['key'],
|
key: Filter['key'],
|
||||||
|
|
|
||||||
|
|
@ -304,7 +304,9 @@ export async function stopPlugin(plugin: InternalPlugin) {
|
||||||
// If the lifecycles don't finish in 5 seconds, a reload is probably required to unapply the changes
|
// If the lifecycles don't finish in 5 seconds, a reload is probably required to unapply the changes
|
||||||
if (!finished) plugin.flags |= Flag.ReloadRequired
|
if (!finished) plugin.flags |= Flag.ReloadRequired
|
||||||
})
|
})
|
||||||
.catch(e => handlePluginError(e, plugin))
|
.catch(e => {
|
||||||
|
handlePluginError(e, plugin)
|
||||||
|
})
|
||||||
else if (
|
else if (
|
||||||
!(plugin.status & (Status.PreInited | Status.Inited | Status.Started))
|
!(plugin.status & (Status.PreInited | Status.Inited | Status.Started))
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
import { _emitter } from '@revenge-mod/plugins/_'
|
import { _emitter } from '@revenge-mod/plugins/_'
|
||||||
|
|
||||||
_emitter.on('register', (plugin, options) => (plugin._s = options.storage))
|
_emitter.on('register', (plugin, options) => {
|
||||||
|
plugin._s = options.storage
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ export function debounce<F extends (...args: any[]) => any>(
|
||||||
return (...args: Parameters<F>) =>
|
return (...args: Parameters<F>) =>
|
||||||
new Promise(rs => {
|
new Promise(rs => {
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
timer = setTimeout(() => rs(func(...args)), timeout)
|
timer = setTimeout(() => {
|
||||||
|
rs(func(...args))
|
||||||
|
}, timeout)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ export function interceptProperty(
|
||||||
delete proto[prop]
|
delete proto[prop]
|
||||||
const desc = _intercepting.get(prop)
|
const desc = _intercepting.get(prop)
|
||||||
if (desc) objectDefineProperty(proto, prop, desc)
|
if (desc) objectDefineProperty(proto, prop, desc)
|
||||||
_intercepting.delete(prop)
|
return _intercepting.delete(prop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,15 @@ export function allSettled(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sleep(ms: number): Promise<void> {
|
export function sleep(ms: number): Promise<void> {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms))
|
return new Promise(resolve => {
|
||||||
|
setTimeout(resolve, ms)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sleepReject(ms: number, msg?: string): Promise<void> {
|
export function sleepReject(ms: number, msg?: string): Promise<void> {
|
||||||
return new Promise((_, reject) => setTimeout(() => reject(msg), ms))
|
return new Promise((_, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
reject(msg)
|
||||||
|
}, ms)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,8 @@ const { jsx: _jsx, jsxs: _jsxs, Fragment } = ReactJsxRuntime
|
||||||
const jsx = ((type, ...args) =>
|
const jsx = ((type, ...args) =>
|
||||||
_jsx(unproxy(type as object), ...args)) as typeof _jsx
|
_jsx(unproxy(type as object), ...args)) as typeof _jsx
|
||||||
|
|
||||||
const jsxs = ((type, ...args) => {
|
const jsxs = ((type, ...args) =>
|
||||||
return _jsxs(unproxy(type as object), ...args)
|
_jsxs(unproxy(type as object), ...args)) as typeof _jsxs
|
||||||
}) as typeof _jsxs
|
|
||||||
|
|
||||||
function unproxy(type: object): ElementType {
|
function unproxy(type: object): ElementType {
|
||||||
return (isProxified(type)
|
return (isProxified(type)
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ import { interceptProperty } from '@revenge-mod/utils/objects'
|
||||||
|
|
||||||
// By doing this, we are assuming __METRO_GLOBAL_PREFIX__ is an empty string and globalThis.__d isn't already set.
|
// By doing this, we are assuming __METRO_GLOBAL_PREFIX__ is an empty string and globalThis.__d isn't already set.
|
||||||
// But both should be true either way.
|
// But both should be true either way.
|
||||||
const unintercept = interceptProperty(
|
const unintercept = interceptProperty('__d', (_, mDefine) => {
|
||||||
'__d',
|
unintercept()
|
||||||
(_, mDefine) => (unintercept(), patchMetroDefine(mDefine)),
|
return patchMetroDefine(mDefine)
|
||||||
)
|
})
|
||||||
|
|
||||||
import {
|
import {
|
||||||
onModuleFirstRequired,
|
onModuleFirstRequired,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@ const EvalJSSetting: SettingsItem = {
|
||||||
IconComponent: () => <TableRowAssetIcon name="FileIcon" />,
|
IconComponent: () => <TableRowAssetIcon name="FileIcon" />,
|
||||||
title: () => 'Evaluate JavaScript',
|
title: () => 'Evaluate JavaScript',
|
||||||
useDescription: () => 'Runs a JavaScript code snippet.',
|
useDescription: () => 'Runs a JavaScript code snippet.',
|
||||||
onPress: () => AlertActionCreators.openAlert(AlertKey, <EvalJSAlert />),
|
onPress: () => {
|
||||||
|
AlertActionCreators.openAlert(AlertKey, <EvalJSAlert />)
|
||||||
|
},
|
||||||
type: 'pressable',
|
type: 'pressable',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +101,9 @@ function EvalJSAlert() {
|
||||||
<TextArea
|
<TextArea
|
||||||
autoFocus
|
autoFocus
|
||||||
label="Code"
|
label="Code"
|
||||||
onChange={v => (code.current = v)}
|
onChange={v => {
|
||||||
|
code.current = v
|
||||||
|
}}
|
||||||
placeholder="ReactNative.NativeModules.BundleUpdaterManager.reload()"
|
placeholder="ReactNative.NativeModules.BundleUpdaterManager.reload()"
|
||||||
size="md"
|
size="md"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,9 @@ const RDTAutoConnectSetting: SettingsItem = {
|
||||||
useValue: () =>
|
useValue: () =>
|
||||||
api.storage.use(s => s.devtools?.autoConnect !== undefined)!.devtools
|
api.storage.use(s => s.devtools?.autoConnect !== undefined)!.devtools
|
||||||
.autoConnect,
|
.autoConnect,
|
||||||
onValueChange: v => api.storage.set({ devtools: { autoConnect: v } }),
|
onValueChange: v => {
|
||||||
|
api.storage.set({ devtools: { autoConnect: v } })
|
||||||
|
},
|
||||||
type: 'toggle',
|
type: 'toggle',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,10 @@ registerPlugin<{ storage: Storage }>(
|
||||||
api = api_
|
api = api_
|
||||||
|
|
||||||
if (isSettingsModulesLoaded()) require('./utils').register()
|
if (isSettingsModulesLoaded()) require('./utils').register()
|
||||||
else onSettingsModulesLoaded(() => require('./utils').register())
|
else
|
||||||
|
onSettingsModulesLoaded(() => {
|
||||||
|
require('./utils').register()
|
||||||
|
})
|
||||||
|
|
||||||
if (api_.plugin.flags & PluginFlags.EnabledLate)
|
if (api_.plugin.flags & PluginFlags.EnabledLate)
|
||||||
refreshSettingsOverviewScreen()
|
refreshSettingsOverviewScreen()
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,9 @@ export default function AssetBrowserSettingScreen() {
|
||||||
return (
|
return (
|
||||||
<Page spacing={16}>
|
<Page spacing={16}>
|
||||||
<SearchInput
|
<SearchInput
|
||||||
onChange={(v: string) => debouncedSetSearch(v)}
|
onChange={(v: string) => {
|
||||||
|
debouncedSetSearch(v)
|
||||||
|
}}
|
||||||
size="md"
|
size="md"
|
||||||
/>
|
/>
|
||||||
<FlashList.FlashList
|
<FlashList.FlashList
|
||||||
|
|
@ -124,7 +126,9 @@ function AssetDisplay({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
label={asset.name}
|
label={asset.name}
|
||||||
onPress={() => openAssetDisplayAlert(asset, id, metadata)}
|
onPress={() => {
|
||||||
|
openAssetDisplayAlert(asset, id, metadata)
|
||||||
|
}}
|
||||||
start={start}
|
start={start}
|
||||||
subLabel={metadata
|
subLabel={metadata
|
||||||
.filter(([, , , hiddenInText]) => !hiddenInText)
|
.filter(([, , , hiddenInText]) => !hiddenInText)
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,9 @@ export function RDTAddrSetting() {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onChange={text => (RDTContext.addr = text)}
|
onChange={text => {
|
||||||
|
RDTContext.addr = text
|
||||||
|
}}
|
||||||
returnKeyType="done"
|
returnKeyType="done"
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,9 @@ export function InstalledPluginCard({
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
icon={SettingsIcon}
|
icon={SettingsIcon}
|
||||||
onPress={() => navigatePluginSettings(plugin)}
|
onPress={() => {
|
||||||
|
navigatePluginSettings(plugin)
|
||||||
|
}}
|
||||||
disabled={!enabled}
|
disabled={!enabled}
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ const ReloadSetting: SettingsItem = {
|
||||||
parent: Setting.Revenge,
|
parent: Setting.Revenge,
|
||||||
IconComponent: () => <TableRowAssetIcon name="RetryIcon" />,
|
IconComponent: () => <TableRowAssetIcon name="RetryIcon" />,
|
||||||
title: () => 'Reload App',
|
title: () => 'Reload App',
|
||||||
onPress: () => BundleUpdaterManager.reload(),
|
onPress: () => {
|
||||||
|
BundleUpdaterManager.reload()
|
||||||
|
},
|
||||||
type: 'pressable',
|
type: 'pressable',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ const RevengeDiscordSetting: SettingsItem = {
|
||||||
parent: Setting.Revenge,
|
parent: Setting.Revenge,
|
||||||
IconComponent: () => <TableRowAssetIcon name="Discord" />,
|
IconComponent: () => <TableRowAssetIcon name="Discord" />,
|
||||||
title: () => 'Discord Server',
|
title: () => 'Discord Server',
|
||||||
onPress: () => Linking.openURL(DiscordServerURL),
|
onPress: () => {
|
||||||
|
Linking.openURL(DiscordServerURL)
|
||||||
|
},
|
||||||
type: 'pressable',
|
type: 'pressable',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ const RevengeGitHubSetting: SettingsItem = {
|
||||||
<TableRowAssetIcon name="img_account_sync_github_white" />
|
<TableRowAssetIcon name="img_account_sync_github_white" />
|
||||||
),
|
),
|
||||||
title: () => 'GitHub',
|
title: () => 'GitHub',
|
||||||
onPress: () => Linking.openURL(GitHubOrganizationURL),
|
onPress: () => {
|
||||||
|
Linking.openURL(GitHubOrganizationURL)
|
||||||
|
},
|
||||||
type: 'pressable',
|
type: 'pressable',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,13 @@ let enabledCount = 0
|
||||||
for (const plugin of _plugins.values())
|
for (const plugin of _plugins.values())
|
||||||
if (plugin.flags & PluginFlags.Enabled) enabledCount++
|
if (plugin.flags & PluginFlags.Enabled) enabledCount++
|
||||||
|
|
||||||
_emitter.on('disabled', () => enabledCount--)
|
_emitter.on('disabled', () => {
|
||||||
_emitter.on('enabled', () => enabledCount++)
|
enabledCount--
|
||||||
|
})
|
||||||
|
|
||||||
|
_emitter.on('enabled', () => {
|
||||||
|
enabledCount++
|
||||||
|
})
|
||||||
|
|
||||||
export function useUpdateOnPluginStatesChange() {
|
export function useUpdateOnPluginStatesChange() {
|
||||||
const reRender = useReRender()
|
const reRender = useReRender()
|
||||||
|
|
@ -73,7 +78,9 @@ function showReloadRequiredAlertIfNeeded(plugin: InternalPlugin) {
|
||||||
<AlertActionButton
|
<AlertActionButton
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
text="Reload"
|
text="Reload"
|
||||||
onPress={() => BundleUpdaterManager.reload()}
|
onPress={() => {
|
||||||
|
BundleUpdaterManager.reload()
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<AlertActionButton variant="secondary" text="Not now" />
|
<AlertActionButton variant="secondary" text="Not now" />
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ import { PluginFlags } from '@revenge-mod/plugins/constants'
|
||||||
import type { SettingsItem } from '@revenge-mod/discord/modules/settings'
|
import type { SettingsItem } from '@revenge-mod/discord/modules/settings'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
|
|
||||||
onSettingsModulesLoaded(() => require('./register'))
|
onSettingsModulesLoaded(() => {
|
||||||
|
require('./register')
|
||||||
|
})
|
||||||
|
|
||||||
registerPlugin(
|
registerPlugin(
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,9 @@ export default function RevengeCustomPageScreen({
|
||||||
const { render: PageComponent, options } = route.params
|
const { render: PageComponent, options } = route.params
|
||||||
|
|
||||||
// biome-ignore lint/correctness/useExhaustiveDependencies: We only want to set options once
|
// biome-ignore lint/correctness/useExhaustiveDependencies: We only want to set options once
|
||||||
useLayoutEffect(() => options && navigation.setOptions(options), [])
|
useLayoutEffect(() => {
|
||||||
|
if (options) navigation.setOptions(options)
|
||||||
|
}, [])
|
||||||
|
|
||||||
return <PageComponent />
|
return <PageComponent />
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,9 @@ function Screen() {
|
||||||
<Stack direction="horizontal">
|
<Stack direction="horizontal">
|
||||||
<View style={styles.grow}>
|
<View style={styles.grow}>
|
||||||
<SearchInput
|
<SearchInput
|
||||||
onChange={(v: string) => debouncedSetSearch(v)}
|
onChange={(v: string) => {
|
||||||
|
debouncedSetSearch(v)
|
||||||
|
}}
|
||||||
size="md"
|
size="md"
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,9 @@ registerPlugin(
|
||||||
store.initialize()
|
store.initialize()
|
||||||
unpatch()
|
unpatch()
|
||||||
|
|
||||||
setTimeout(() => refreshSettingsOverviewScreen(true))
|
setTimeout(() => {
|
||||||
|
refreshSettingsOverviewScreen(true)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue