Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e444cf55d |
3 changed files with 117 additions and 118 deletions
|
|
@ -499,6 +499,7 @@ export namespace DiscordModules {
|
|||
extends TableRowGroupProps {
|
||||
children: ReactNode
|
||||
onChange: (value: T) => void
|
||||
value?: T
|
||||
defaultValue?: T
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import {
|
|||
} from '@revenge-mod/plugins/_'
|
||||
import {
|
||||
listRepoPlugins,
|
||||
listRepos,
|
||||
refreshRepo,
|
||||
} from '@revenge-mod/plugins/_/repositories'
|
||||
import { PluginStatus } from '@revenge-mod/plugins/constants'
|
||||
|
|
@ -39,7 +38,11 @@ import {
|
|||
showPluginClearDataConfirmation,
|
||||
showPluginUninstallConfirmation,
|
||||
} from '../utils/alerts'
|
||||
import { messageOf, runInstallFlow, showErrorToast } from '../utils/repos'
|
||||
import {
|
||||
messageOf,
|
||||
runInstallFlowWithInternalRepos,
|
||||
showErrorToast,
|
||||
} from '../utils/repos'
|
||||
import { InstalledPluginSwitch, PluginInfo } from './PluginCard'
|
||||
import { usePluginEnabled, usePluginStatus } from './PluginStateProvider'
|
||||
import PluginTooltipsProvider, {
|
||||
|
|
@ -47,7 +50,6 @@ import PluginTooltipsProvider, {
|
|||
usePluginTooltip,
|
||||
} from './TooltipProvider'
|
||||
import type { AnyPlugin } from '@revenge-mod/plugins/_'
|
||||
import type { RepoPluginListing } from '@revenge-mod/plugins/_/repositories'
|
||||
|
||||
export interface PluginOptionsActionSheetProps {
|
||||
plugin: AnyPlugin
|
||||
|
|
@ -131,7 +133,8 @@ function PluginOptions({ plugin, sheetKey }: PluginOptionsActionSheetProps) {
|
|||
}}
|
||||
/>
|
||||
<StatusSection plugin={plugin} />
|
||||
<AdvancedSection plugin={plugin} sheetKey={sheetKey} />
|
||||
<ChannelSection plugin={plugin} />
|
||||
<AdvancedSection plugin={plugin} />
|
||||
</Stack>
|
||||
)
|
||||
}
|
||||
|
|
@ -173,92 +176,72 @@ function StatusSection({ plugin }: { plugin: AnyPlugin }) {
|
|||
|
||||
function ChannelSection({
|
||||
plugin,
|
||||
sheetKey,
|
||||
}: {
|
||||
plugin: AnyPlugin
|
||||
sheetKey: string
|
||||
}) {
|
||||
const meta = getInternalPluginMeta(plugin)
|
||||
const source = meta.source
|
||||
if (isPluginInternal(meta) || !source?.repo) return null
|
||||
|
||||
const [listing, setListing] = useState<RepoPluginListing | null>(null)
|
||||
const [resetKey, setResetKey] = useState(0)
|
||||
const [channels, setChannels] = useState<Record<string, string>>({})
|
||||
const [selected, setSelected] = useState(source.channel)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
try {
|
||||
const listings = await listRepoPlugins(source.repo)
|
||||
const found = listings.find(l => l.id === plugin.manifest.id)
|
||||
if (found && !cancelled) setListing(found)
|
||||
} catch {
|
||||
try {
|
||||
await refreshRepo(source.repo)
|
||||
const listings = await listRepoPlugins(source.repo)
|
||||
const found = listings.find(l => l.id === plugin.manifest.id)
|
||||
if (found && !cancelled) setListing(found)
|
||||
} catch {}
|
||||
}
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
listRepoPlugins(source.repo)
|
||||
.then(listings => {
|
||||
const listing = listings.find(l => l.id === plugin.manifest.id)
|
||||
if (listing) setChannels(listing.channels)
|
||||
})
|
||||
.catch(() =>
|
||||
refreshRepo(source.repo)
|
||||
.then(() => listRepoPlugins(source.repo))
|
||||
.then(listings => {
|
||||
const listing = listings.find(
|
||||
l => l.id === plugin.manifest.id,
|
||||
)
|
||||
if (listing) setChannels(listing.channels)
|
||||
})
|
||||
.catch(() => {}),
|
||||
)
|
||||
}, [source.repo, plugin.manifest.id])
|
||||
|
||||
if (!listing || Object.keys(listing.channels).length === 0) return null
|
||||
if (Object.keys(channels).length === 0) return null
|
||||
|
||||
const handleChange = async (selected: string) => {
|
||||
if (selected === source.channel) return
|
||||
|
||||
const targetVersion = listing.channels[selected]
|
||||
if (!targetVersion) return
|
||||
const handleChange = (value: string) => {
|
||||
setSelected(value)
|
||||
|
||||
const targetVersion = channels[value]!
|
||||
if (targetVersion === plugin.manifest.version) {
|
||||
setResetKey(k => k + 1)
|
||||
ToastActionCreators.open({
|
||||
key: 'REVENGE_PLUGIN_CHANNEL_UP_TO_DATE',
|
||||
content: 'This channel is already installed',
|
||||
key: 'REVENGE_PLUGIN_VERSION_ALREADY_INSTALLED',
|
||||
content: 'This version is already installed',
|
||||
IconComponent: () => <TableRowAssetIcon name="CircleCheckIcon" />,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const repos = await listRepos()
|
||||
const internalUrls = repos
|
||||
.filter(r => r.internal)
|
||||
.map(r => r.url)
|
||||
|
||||
ActionSheetActionCreators.hideActionSheet(sheetKey)
|
||||
runInstallFlow(
|
||||
runInstallFlowWithInternalRepos(
|
||||
plugin.manifest.id,
|
||||
undefined,
|
||||
selected,
|
||||
[...internalUrls, source.repo],
|
||||
value,
|
||||
source.repo,
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<TableRadioGroup
|
||||
key={resetKey}
|
||||
title="Channel"
|
||||
defaultValue={source.channel}
|
||||
value={selected}
|
||||
onChange={v => handleChange(v as string)}
|
||||
>
|
||||
{Object.keys(listing.channels).map(c => (
|
||||
{Object.keys(channels).map(c => (
|
||||
<TableRadioRow key={c} label={c} value={c} />
|
||||
))}
|
||||
</TableRadioGroup>
|
||||
)
|
||||
}
|
||||
|
||||
function AdvancedSection({
|
||||
plugin,
|
||||
sheetKey,
|
||||
}: {
|
||||
plugin: AnyPlugin
|
||||
sheetKey: string
|
||||
}) {
|
||||
function AdvancedSection({ plugin }: { plugin: AnyPlugin }) {
|
||||
const meta = getInternalPluginMeta(plugin)
|
||||
const dependents = getPluginDependents(plugin, true)
|
||||
const dependencies = getPluginDependencies(plugin, false)
|
||||
|
|
@ -266,8 +249,6 @@ function AdvancedSection({
|
|||
const { id, name } = plugin.manifest
|
||||
|
||||
return (
|
||||
<>
|
||||
<ChannelSection plugin={plugin} sheetKey={sheetKey} />
|
||||
<TableRowGroup title="Advanced">
|
||||
<IdRow id={id} />
|
||||
<RepositoryRow
|
||||
|
|
@ -332,7 +313,6 @@ function AdvancedSection({
|
|||
/>
|
||||
)}
|
||||
</TableRowGroup>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -170,3 +170,21 @@ export async function runInstallFlow(
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link runInstallFlow}, but automatically includes every internal repository plus
|
||||
* the target repository in `filteredRepos`, so repo-installed plugins can be updated in place.
|
||||
*/
|
||||
export async function runInstallFlowWithInternalRepos(
|
||||
id: string,
|
||||
version?: string,
|
||||
channel?: string,
|
||||
repo?: string,
|
||||
): Promise<boolean> {
|
||||
const repos = await listRepos()
|
||||
const filteredRepos = repos
|
||||
.filter(r => r.internal)
|
||||
.map(r => r.url)
|
||||
if (repo) filteredRepos.push(repo)
|
||||
return runInstallFlow(id, version, channel, filteredRepos)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue