mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 23:24:35 +01:00
more cleanup
This commit is contained in:
63
src/ui/components/ServerLaunchSection.tsx
Normal file
63
src/ui/components/ServerLaunchSection.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
import React from 'react'
|
||||
import Checkbox from './common/Checkbox'
|
||||
import BigButton from './common/BigButton'
|
||||
import { getConfig, saveConfig } from '../../utils/configuration'
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
|
||||
interface IProps {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
interface IState {
|
||||
grasscutterEnabled: boolean
|
||||
}
|
||||
|
||||
export default class ServerLaunchSection extends React.Component<IProps, IState> {
|
||||
constructor(props: IProps) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
grasscutterEnabled: false
|
||||
}
|
||||
|
||||
this.toggleGrasscutter = this.toggleGrasscutter.bind(this)
|
||||
this.playGame = this.playGame.bind(this)
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
const config = await getConfig()
|
||||
|
||||
this.setState({
|
||||
grasscutterEnabled: config.toggle_grasscutter
|
||||
})
|
||||
}
|
||||
|
||||
async toggleGrasscutter() {
|
||||
const config = await getConfig()
|
||||
|
||||
config.toggle_grasscutter = !config.toggle_grasscutter
|
||||
|
||||
await saveConfig(config)
|
||||
}
|
||||
|
||||
async playGame() {
|
||||
const config = await getConfig()
|
||||
|
||||
if (!config.game_path) return
|
||||
|
||||
// Launch the program
|
||||
await invoke('run_program', { path: config.game_path })
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div id="playButton">
|
||||
<div id="serverControls">
|
||||
<Checkbox label="Connect via Grasscutter" onChange={this.toggleGrasscutter} checked={this.state.grasscutterEnabled}/>
|
||||
</div>
|
||||
<BigButton text="PLAY DA GAME :D" onClick={this.playGame} id="officialPlay" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user