feat(plugins): reset setting screens for plugins that require it
This commit is contained in:
parent
5b3a8bc5ab
commit
44a1496452
4 changed files with 98 additions and 43 deletions
|
|
@ -4,6 +4,7 @@ import {
|
|||
} from '@revenge-mod/discord/modules/settings'
|
||||
import { InternalPluginFlags, registerPlugin } from '@revenge-mod/plugins/_'
|
||||
import { PluginFlags } from '@revenge-mod/plugins/constants'
|
||||
import { resetSettingsScreen } from '../settings'
|
||||
import type { PluginApi } from '@revenge-mod/plugins/types'
|
||||
|
||||
interface Storage {
|
||||
|
|
@ -33,17 +34,23 @@ registerPlugin<Storage>(
|
|||
load: true,
|
||||
default: defaultStorage,
|
||||
},
|
||||
start(api_) {
|
||||
async start(api_) {
|
||||
api = api_
|
||||
|
||||
if (isSettingsModulesLoaded()) require('./register')
|
||||
else onSettingsModulesLoaded(() => require('./register'))
|
||||
if (isSettingsModulesLoaded()) require('./utils').register()
|
||||
else onSettingsModulesLoaded(() => require('./utils').register())
|
||||
|
||||
Promise.all([import('./react-devtools'), api.storage.get()]).then(
|
||||
([rdt, settings]) => {
|
||||
if (settings.devtools.autoConnect) rdt.connectToDevTools()
|
||||
},
|
||||
)
|
||||
if (api_.plugin.flags & PluginFlags.EnabledLate)
|
||||
resetSettingsScreen()
|
||||
|
||||
api_.cleanup(resetSettingsScreen)
|
||||
|
||||
const [rdt, settings] = await Promise.all([
|
||||
import('./react-devtools'),
|
||||
api.storage.get(),
|
||||
])
|
||||
|
||||
if (settings.devtools.autoConnect) rdt.connectToDevTools()
|
||||
},
|
||||
},
|
||||
PluginFlags.Enabled,
|
||||
|
|
|
|||
|
|
@ -12,17 +12,19 @@ import ReactDevToolsDisconnectSetting from './definitions/ReactDevToolsDisconnec
|
|||
import ReactDevToolsVersionSetting from './definitions/ReactDevToolsVersionSetting'
|
||||
import RevengeDeveloperSetting from './definitions/RevengeDeveloperSetting'
|
||||
|
||||
api.cleanup(
|
||||
registerSettingsItems({
|
||||
[MobileSetting.REVENGE_DEVELOPER]: RevengeDeveloperSetting,
|
||||
[MobileSetting.REACT_DEVTOOLS_VERSION]: ReactDevToolsVersionSetting,
|
||||
[MobileSetting.REACT_DEVTOOLS_AUTO_CONNECT]:
|
||||
ReactDevToolsAutoConnectSetting,
|
||||
[MobileSetting.REACT_DEVTOOLS_CONNECT]: ReactDevToolsConnectSetting,
|
||||
[MobileSetting.REACT_DEVTOOLS_DISCONNECT]:
|
||||
ReactDevToolsDisconnectSetting,
|
||||
[MobileSetting.EVALUATE_JAVASCRIPT]: EvaluateJavaScriptSetting,
|
||||
[MobileSetting.ASSET_BROWSER]: AssetBrowserSetting,
|
||||
}),
|
||||
addSettingsItemToSection('REVENGE', MobileSetting.REVENGE_DEVELOPER),
|
||||
)
|
||||
export function register() {
|
||||
api.cleanup(
|
||||
registerSettingsItems({
|
||||
[MobileSetting.REVENGE_DEVELOPER]: RevengeDeveloperSetting,
|
||||
[MobileSetting.REACT_DEVTOOLS_VERSION]: ReactDevToolsVersionSetting,
|
||||
[MobileSetting.REACT_DEVTOOLS_AUTO_CONNECT]:
|
||||
ReactDevToolsAutoConnectSetting,
|
||||
[MobileSetting.REACT_DEVTOOLS_CONNECT]: ReactDevToolsConnectSetting,
|
||||
[MobileSetting.REACT_DEVTOOLS_DISCONNECT]:
|
||||
ReactDevToolsDisconnectSetting,
|
||||
[MobileSetting.EVALUATE_JAVASCRIPT]: EvaluateJavaScriptSetting,
|
||||
[MobileSetting.ASSET_BROWSER]: AssetBrowserSetting,
|
||||
}),
|
||||
addSettingsItemToSection('REVENGE', MobileSetting.REVENGE_DEVELOPER),
|
||||
)
|
||||
}
|
||||
|
|
@ -1,10 +1,14 @@
|
|||
import { _data, _subs } from '@revenge-mod/discord/_/modules/settings'
|
||||
import { onSettingsModulesLoaded } from '@revenge-mod/discord/modules/settings'
|
||||
import { ReactNavigationNative } from '@revenge-mod/externals/react-navigation'
|
||||
import { byName, byProps } from '@revenge-mod/modules/finders/filters'
|
||||
import { waitForModules } from '@revenge-mod/modules/finders/wait'
|
||||
import { after } from '@revenge-mod/patcher'
|
||||
import { InternalPluginFlags, registerPlugin } from '@revenge-mod/plugins/_'
|
||||
import { PluginFlags } from '@revenge-mod/plugins/constants'
|
||||
import { findInTree } from '@revenge-mod/utils/trees'
|
||||
import type { NavigationState } from '@react-navigation/core'
|
||||
import type { StackScreenProps } from '@react-navigation/stack'
|
||||
import type { SettingsItem } from '@revenge-mod/discord/modules/settings'
|
||||
import type { FC } from 'react'
|
||||
|
||||
|
|
@ -19,13 +23,22 @@ registerPlugin(
|
|||
icon: 'SettingsIcon',
|
||||
},
|
||||
{
|
||||
init() {
|
||||
const unsub = waitForModules(
|
||||
byProps('getRootNavigationRef'),
|
||||
exports => {
|
||||
unsub()
|
||||
navigation = exports.getRootNavigationRef()
|
||||
},
|
||||
)
|
||||
},
|
||||
start({ logger }) {
|
||||
const unsubForRendererConfig = waitForModules(
|
||||
const unsubRC = waitForModules(
|
||||
byProps<{
|
||||
SETTING_RENDERER_CONFIG: Record<string, SettingsItem>
|
||||
}>('SETTING_RENDERER_CONFIG'),
|
||||
SettingRendererConfig => {
|
||||
unsubForRendererConfig()
|
||||
unsubRC()
|
||||
|
||||
logger.info(
|
||||
'Settings modules loaded, running subscriptions and patching...',
|
||||
|
|
@ -63,10 +76,10 @@ registerPlugin(
|
|||
},
|
||||
)
|
||||
|
||||
const unsubForSettingsOverviewScreen = waitForModules(
|
||||
const unsubSOS = waitForModules(
|
||||
byName('SettingsOverviewScreen'),
|
||||
exports => {
|
||||
unsubForSettingsOverviewScreen()
|
||||
unsubSOS()
|
||||
|
||||
const customSections = _data[0]
|
||||
|
||||
|
|
@ -114,3 +127,50 @@ registerPlugin(
|
|||
PluginFlags.Enabled,
|
||||
InternalPluginFlags.Internal | InternalPluginFlags.Essential,
|
||||
)
|
||||
|
||||
let navigation: ReturnType<
|
||||
typeof ReactNavigationNative.useNavigation<
|
||||
StackScreenProps<
|
||||
{
|
||||
tabs: undefined
|
||||
settings:
|
||||
| {
|
||||
screen: string
|
||||
params?: Record<string, unknown>
|
||||
}
|
||||
| undefined
|
||||
},
|
||||
'settings'
|
||||
>['navigation']
|
||||
>
|
||||
>
|
||||
|
||||
export function resetSettingsScreen() {
|
||||
const prevState = navigation.getState()
|
||||
const settings = findInTree(prevState, node => node.name === 'settings') as
|
||||
| { state: NavigationState }
|
||||
| undefined
|
||||
|
||||
// We're currently not on the settings screen, so we don't need to reset
|
||||
if (!settings) return
|
||||
|
||||
navigation.navigate('tabs')
|
||||
|
||||
setTimeout(() => {
|
||||
navigation.dispatch(
|
||||
ReactNavigationNative.CommonActions.reset(prevState),
|
||||
)
|
||||
|
||||
// Re-push all routes, because resetting does not keep them for some reason
|
||||
|
||||
if (settings)
|
||||
for (const route of settings.state.routes) {
|
||||
navigation.dispatch(
|
||||
ReactNavigationNative.StackActions.push(
|
||||
route.name,
|
||||
route.params,
|
||||
),
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import { AlertActionCreators } from '@revenge-mod/discord/actions'
|
||||
import { getStore, Stores } from '@revenge-mod/discord/common/flux'
|
||||
import { Design } from '@revenge-mod/discord/design'
|
||||
import { byProps } from '@revenge-mod/modules/finders/filters'
|
||||
import { getModule } from '@revenge-mod/modules/finders/get'
|
||||
import { instead } from '@revenge-mod/patcher'
|
||||
import { InternalPluginFlags, registerPlugin } from '@revenge-mod/plugins/_'
|
||||
import { PluginFlags } from '@revenge-mod/plugins/constants'
|
||||
import { resetSettingsScreen } from '../settings'
|
||||
|
||||
registerPlugin(
|
||||
{
|
||||
|
|
@ -17,7 +16,7 @@ registerPlugin(
|
|||
},
|
||||
{
|
||||
start({ cleanup, logger, plugin }) {
|
||||
if (plugin.flags & PluginFlags.EnabledLate) showNoticeAlert()
|
||||
if (plugin.flags & PluginFlags.EnabledLate) resetSettingsScreen()
|
||||
|
||||
function reinitDEStore() {
|
||||
cleanup(
|
||||
|
|
@ -58,23 +57,10 @@ registerPlugin(
|
|||
reinitDEStore()
|
||||
}),
|
||||
reinitDEStore,
|
||||
showNoticeAlert,
|
||||
resetSettingsScreen,
|
||||
)
|
||||
},
|
||||
},
|
||||
PluginFlags.Enabled,
|
||||
InternalPluginFlags.Internal,
|
||||
)
|
||||
|
||||
function showNoticeAlert() {
|
||||
AlertActionCreators.openAlert(
|
||||
'staff-settings-notice',
|
||||
<Design.AlertModal
|
||||
actions={
|
||||
<Design.AlertActionButton text="Got it" variant="secondary" />
|
||||
}
|
||||
content="Close and open the Settings page again to apply changes."
|
||||
title="Notice"
|
||||
/>,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue