mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 23:54:48 +01:00
potentially gather installed mods
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React from 'react'
|
||||
import { getMods, ModData } from '../../../utils/gamebanana'
|
||||
import { getInstalledMods, getMods, ModData } from '../../../utils/gamebanana'
|
||||
import { LoadingCircle } from './LoadingCircle'
|
||||
|
||||
import './ModList.css'
|
||||
@@ -11,7 +11,13 @@ interface IProps {
|
||||
}
|
||||
|
||||
interface IState {
|
||||
modList: ModData[]
|
||||
modList: ModData[] | null
|
||||
installedList:
|
||||
| {
|
||||
path: string
|
||||
info: unknown
|
||||
}[]
|
||||
| null
|
||||
}
|
||||
|
||||
export class ModList extends React.Component<IProps, IState> {
|
||||
@@ -20,11 +26,26 @@ export class ModList extends React.Component<IProps, IState> {
|
||||
|
||||
console.log('Getting')
|
||||
|
||||
this.state = {
|
||||
modList: null,
|
||||
installedList: null,
|
||||
}
|
||||
|
||||
this.downloadMod = this.downloadMod.bind(this)
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
if (this.props.mode === 'installed') return
|
||||
if (this.props.mode === 'installed') {
|
||||
const installedMods = await getInstalledMods()
|
||||
|
||||
console.log(installedMods)
|
||||
|
||||
this.setState({
|
||||
installedList: installedMods,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const mods = await getMods(this.props.mode)
|
||||
|
||||
@@ -40,11 +61,14 @@ export class ModList extends React.Component<IProps, IState> {
|
||||
render() {
|
||||
return (
|
||||
<div className="ModList">
|
||||
{this.state && this.state.modList ? (
|
||||
{(this.state.modList && this.props.mode !== 'installed') ||
|
||||
(this.state.installedList && this.props.mode === 'installed') ? (
|
||||
<div className="ModListInner">
|
||||
{this.state.modList.map((mod: ModData) => (
|
||||
<ModTile mod={mod} key={mod.id} onClick={this.downloadMod} />
|
||||
))}
|
||||
{this.props.mode === 'installed'
|
||||
? this.state.installedList?.map((mod) => <></>)
|
||||
: this.state.modList?.map((mod: ModData) => (
|
||||
<ModTile mod={mod} key={mod.id} onClick={this.downloadMod} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<LoadingCircle />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { getConfigOption } from './configuration'
|
||||
|
||||
// Generated with https://transform.tools/json-to-typescript I'm lazy cry about it
|
||||
export interface GamebananaResponse {
|
||||
@@ -115,3 +116,21 @@ export async function formatGamebananaData(obj: GamebananaResponse[]) {
|
||||
})
|
||||
.filter((itm) => itm.type === 'Mod')
|
||||
}
|
||||
|
||||
export async function getInstalledMods() {
|
||||
const migotoPath = await getConfigOption('migoto_path')
|
||||
|
||||
if (!migotoPath) return []
|
||||
|
||||
const mods = (await invoke('list_mods', {
|
||||
path: migotoPath,
|
||||
})) as Record<string, string>
|
||||
|
||||
// These are returned as JSON strings, so we have to parse them
|
||||
return Object.keys(mods).map((path) => {
|
||||
return {
|
||||
path,
|
||||
info: JSON.parse(mods[path]),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user