From 079577922ed3fe66db67838fb948e2dce918d7d9 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Thu, 23 Oct 2025 00:55:24 +0700 Subject: [PATCH] feat(plugins/settings): notify user on plugin error --- .../components/PluginsFailedToStartAlert.tsx | 63 +++++++++++++++ .../components/PluginsRequireReloadAlert.tsx | 48 +++++++++++ src/plugins/start/settings/plugins.tsx | 80 +++++++------------ 3 files changed, 138 insertions(+), 53 deletions(-) create mode 100644 src/plugins/start/settings/components/PluginsFailedToStartAlert.tsx create mode 100644 src/plugins/start/settings/components/PluginsRequireReloadAlert.tsx diff --git a/src/plugins/start/settings/components/PluginsFailedToStartAlert.tsx b/src/plugins/start/settings/components/PluginsFailedToStartAlert.tsx new file mode 100644 index 0000000..b27bfac --- /dev/null +++ b/src/plugins/start/settings/components/PluginsFailedToStartAlert.tsx @@ -0,0 +1,63 @@ +import { Design } from '@revenge-mod/discord/design' +import { RootNavigationRef } from '@revenge-mod/discord/modules/main_tabs_v2' +import { RouteNames } from '../constants' +import type { AnyPlugin } from '@revenge-mod/plugins/_' + +const { AlertModal, AlertActionButton, Text } = Design + +export default function PluginsFailedToStartAlert({ + plugins, +}: { + plugins: AnyPlugin[] +}) { + const navigation = RootNavigationRef.getRootNavigationRef() + + return ( + + The following plugins encountered errors while starting: + {'\n'} + {plugins.map((plugin, index) => ( + <> + {index ? ', ' : null} + + {plugin.manifest.name} + + + ))} + + } + actions={ + <> + { + const params = { + filter: ['Has Errors'], + } + + if ( + navigation.getCurrentRoute()?.name === + RouteNames.RevengePlugins + ) + navigation.setParams(params) + else + navigation.navigate( + RouteNames.RevengePlugins, + params, + ) + }} + /> + + + } + /> + ) +} diff --git a/src/plugins/start/settings/components/PluginsRequireReloadAlert.tsx b/src/plugins/start/settings/components/PluginsRequireReloadAlert.tsx new file mode 100644 index 0000000..bcf7520 --- /dev/null +++ b/src/plugins/start/settings/components/PluginsRequireReloadAlert.tsx @@ -0,0 +1,48 @@ +import { Design } from '@revenge-mod/discord/design' +import { BundleUpdaterManager } from '@revenge-mod/discord/native' +import type { AnyPlugin } from '@revenge-mod/plugins/_' + +const { AlertModal, AlertActionButton, Text } = Design + +export default function PluginsRequireReloadAlert({ + plugins, +}: { + plugins: AnyPlugin[] +}) { + return ( + + The following plugins require a reload to apply changes: + {'\n'} + {plugins.map((plugin, index) => ( + <> + {index ? ', ' : null} + + {plugin.manifest.name} + + + ))} + + } + actions={ + <> + { + // TODO: Replace with bridge call + BundleUpdaterManager.reload() + }} + /> + + + } + /> + ) +} diff --git a/src/plugins/start/settings/plugins.tsx b/src/plugins/start/settings/plugins.tsx index 375d225..5b642ae 100644 --- a/src/plugins/start/settings/plugins.tsx +++ b/src/plugins/start/settings/plugins.tsx @@ -1,20 +1,18 @@ import TableRowAssetIcon from '@revenge-mod/components/TableRowAssetIcon' import { AlertActionCreators } from '@revenge-mod/discord/actions' -import { Design } from '@revenge-mod/discord/design' import { refreshSettingsNavigator, registerSettingsItem, } from '@revenge-mod/discord/modules/settings' -import { BundleUpdaterManager } from '@revenge-mod/discord/native' import { pEmitter, pList } from '@revenge-mod/plugins/_' import { PluginFlags } from '@revenge-mod/plugins/constants' -import { debounce } from '@revenge-mod/utils/callback' import { useLayoutEffect } from 'react' import defer * as NavigatorHeaderWithIcon from './components/NavigatorHeaderWithIcon' +import PluginsFailedToStartAlert from './components/PluginsFailedToStartAlert' +import PluginsRequireReloadAlert from './components/PluginsRequireReloadAlert' import { Setting } from './constants' import type { StackScreenProps } from '@react-navigation/stack' import type { ReactNavigationParamList } from '@revenge-mod/externals/react-navigation' -import type { AnyPlugin } from '@revenge-mod/plugins/_' import type { PluginApi } from '@revenge-mod/plugins/types' /// SETTINGS ROUTES @@ -71,8 +69,6 @@ pEmitter.on('started', plugin => { /// RELOAD REQUIRED ALERT -const { AlertActionButton, AlertModal, Text } = Design - function showReloadRequiredAlertIfNeeded() { const plugins = [...pList.values()].filter( plugin => plugin.flags & PluginFlags.ReloadRequired, @@ -81,54 +77,32 @@ function showReloadRequiredAlertIfNeeded() { if (!plugins.length) return AlertActionCreators.openAlert( - 'plugin-reload-required', - , + 'plugins-require-reload', + , ) } -pEmitter.on( - 'flagUpdate', - debounce(plugin => { - if (plugin.flags & PluginFlags.ReloadRequired) - showReloadRequiredAlertIfNeeded() - }, 500), -) +function showErrorAlertIfNeeded() { + const plugins = [...pList.values()].filter( + plugin => plugin.flags & PluginFlags.Errored, + ) + + if (!plugins.length) return + + AlertActionCreators.openAlert( + 'plugins-failed-to-start', + , + ) +} + +pEmitter.on('flagUpdate', plugin => { + if (plugin.flags & PluginFlags.ReloadRequired) + showReloadRequiredAlertIfNeeded() +}) + +pEmitter.on('stopped', plugin => { + if (plugin.flags & PluginFlags.Errored) showErrorAlertIfNeeded() +}) + +showErrorAlertIfNeeded() showReloadRequiredAlertIfNeeded() - -function PluginReloadRequiredAlert({ plugins }: { plugins: AnyPlugin[] }) { - return ( - - The following plugins require a reload to apply changes: - {'\n'} - {plugins.map((plugin, index) => ( - <> - {index ? ', ' : null} - - {plugin.manifest.name} - - - ))} - - } - actions={ - <> - { - BundleUpdaterManager.reload() - }} - /> - - - } - /> - ) -}