remove test download button

This commit is contained in:
SpikeHD
2022-05-14 00:47:30 -07:00
parent 530990b38f
commit 3c68b67aff
5 changed files with 82 additions and 26 deletions

View File

@@ -27,19 +27,6 @@ interface IState {
const downloadHandler = new DownloadHandler() const downloadHandler = new DownloadHandler()
async function download(url: string, filename: string, path: string) {
const completePath = `${path}/${filename}`
downloadHandler.addDownload(url, completePath)
}
async function TESTDOWNLOAD() {
download(
'https://github.com/Koko-boya/Grasscutter_Resources/archive/refs/heads/main.zip',
'resources.zip',
'S:\\Cultivation'
)
}
class App extends React.Component<IProps, IState> { class App extends React.Component<IProps, IState> {
constructor(props: IProps) { constructor(props: IProps) {
super(props) super(props)
@@ -90,8 +77,6 @@ class App extends React.Component<IProps, IState> {
this.state.optionsOpen ? <Options closeFn={() => this.setState({ optionsOpen: !this.state.optionsOpen })}/> : null this.state.optionsOpen ? <Options closeFn={() => this.setState({ optionsOpen: !this.state.optionsOpen })}/> : null
} }
<button onClick={TESTDOWNLOAD}>download file test</button>
<ServerLaunchSection /> <ServerLaunchSection />
<div id="DownloadProgress" <div id="DownloadProgress"

View File

@@ -5,22 +5,39 @@ interface IProps {
children: React.ReactNode; children: React.ReactNode;
onClick: () => any; onClick: () => any;
id: string; id: string;
disabled?: boolean;
} }
export default class BigButton extends React.Component<IProps, never> { interface IState {
disabled?: boolean;
}
export default class BigButton extends React.Component<IProps, IState> {
constructor(props: IProps) { constructor(props: IProps) {
super(props) super(props)
this.state = {
disabled: this.props.disabled
}
this.handleClick = this.handleClick.bind(this) this.handleClick = this.handleClick.bind(this)
} }
static getDerivedStateFromProps(props: IProps, state: IState) {
return {
disabled: props.disabled
}
}
handleClick() { handleClick() {
if (this.state.disabled) return
this.props.onClick() this.props.onClick()
} }
render() { render() {
return ( return (
<div className="BigButton" onClick={this.handleClick} id={this.props.id}> <div className={'BigButton ' + (this.state.disabled ? 'disabled' : '')} onClick={this.handleClick} id={this.props.id}>
<div className="BigButtonText">{this.props.children}</div> <div className="BigButtonText">{this.props.children}</div>
</div> </div>
) )

View File

@@ -2,7 +2,7 @@
width: 40%; width: 40%;
} }
.DownloadSection { .DownloadMenuSection {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;

View File

@@ -6,6 +6,11 @@ import BigButton from '../common/BigButton'
import './Downloads.css' import './Downloads.css'
import Divider from './Divider' import Divider from './Divider'
import { getConfigOption } from '../../../utils/configuration'
const STABLE_DOWNLOAD = 'https://nightly.link/Grasscutters/Grasscutter/workflows/build/stable/Grasscutter.zip'
const DEV_DOWNLOAD = 'https://nightly.link/Grasscutters/Grasscutter/workflows/build/development/Grasscutter.zip'
const RESOURCES_DOWNLOAD = 'https://github.com/Koko-boya/Grasscutter_Resources/archive/refs/heads/main.zip'
interface IProps { interface IProps {
closeFn: () => void; closeFn: () => void;
@@ -22,30 +27,69 @@ export default class Downloads extends React.Component<IProps, IState> {
super(props) super(props)
this.state = { this.state = {
grasscutter_downloading: false, grasscutter_downloading: this.props.downloadManager.downloadingJar(),
resources_downloading: false resources_downloading: this.props.downloadManager.downloadingResources()
} }
this.getGrasscutterFolder = this.getGrasscutterFolder.bind(this)
this.downloadGrasscutterStable = this.downloadGrasscutterStable.bind(this)
this.downloadGrasscutterLatest = this.downloadGrasscutterLatest.bind(this)
this.downloadResources = this.downloadResources.bind(this)
}
async getGrasscutterFolder() {
const path = await getConfigOption('grasscutter_path')
let folderPath
if (path.includes('/')) {
folderPath = path.substring(0, path.lastIndexOf('/'))
} else {
folderPath = path.substring(0, path.lastIndexOf('\\'))
}
// Set states since we know we are downloading something if this is called
this.setState({
grasscutter_downloading: this.props.downloadManager.downloadingJar(),
resources_downloading: this.props.downloadManager.downloadingResources()
})
return folderPath
}
async downloadGrasscutterStable() {
const folder = await this.getGrasscutterFolder()
this.props.downloadManager.addDownload(STABLE_DOWNLOAD, folder + '\\grasscutter.jar')
}
async downloadGrasscutterLatest() {
const folder = await this.getGrasscutterFolder()
this.props.downloadManager.addDownload(DEV_DOWNLOAD, folder + '\\grasscutter.jar')
}
async downloadResources() {
const folder = await this.getGrasscutterFolder()
this.props.downloadManager.addDownload(RESOURCES_DOWNLOAD, folder + '\\resources.zip')
} }
render() { render() {
return ( return (
<Menu closeFn={this.props.closeFn} className="Downloads" heading="Downloads"> <Menu closeFn={this.props.closeFn} className="Downloads" heading="Downloads">
<div className='DownloadSection'> <div className='DownloadMenuSection'>
<div className='DownloadLabel'> <div className='DownloadLabel'>
<Tr text="downloads.grasscutter_stable" /> <Tr text="downloads.grasscutter_stable" />
</div> </div>
<div className='DownloadValue'> <div className='DownloadValue'>
<BigButton onClick={() => console.log('download')} id="grasscutterStableBtn" > <BigButton disabled={this.state.grasscutter_downloading} onClick={this.downloadGrasscutterStable} id="grasscutterStableBtn" >
<Tr text="components.download" /> <Tr text="components.download" />
</BigButton> </BigButton>
</div> </div>
</div> </div>
<div className='DownloadSection'> <div className='DownloadMenuSection'>
<div className='DownloadLabel'> <div className='DownloadLabel'>
<Tr text="downloads.grasscutter_latest" /> <Tr text="downloads.grasscutter_latest" />
</div> </div>
<div className='DownloadValue'> <div className='DownloadValue'>
<BigButton onClick={() => console.log('download')} id="grasscutterLatestBtn" > <BigButton disabled={this.state.grasscutter_downloading} onClick={this.downloadGrasscutterLatest} id="grasscutterLatestBtn" >
<Tr text="components.download" /> <Tr text="components.download" />
</BigButton> </BigButton>
</div> </div>
@@ -53,12 +97,12 @@ export default class Downloads extends React.Component<IProps, IState> {
<Divider /> <Divider />
<div className='DownloadSection'> <div className='DownloadMenuSection'>
<div className='DownloadLabel'> <div className='DownloadLabel'>
<Tr text="downloads.resources" /> <Tr text="downloads.resources" />
</div> </div>
<div className='DownloadValue'> <div className='DownloadValue'>
<BigButton onClick={() => console.log('download')} id="resourcesBtn" > <BigButton disabled={this.state.resources_downloading} onClick={this.downloadResources} id="resourcesBtn" >
<Tr text="components.download" /> <Tr text="components.download" />
</BigButton> </BigButton>
</div> </div>

View File

@@ -63,6 +63,16 @@ export default class DownloadHandler {
getDownloads() { getDownloads() {
return this.downloads return this.downloads
} }
downloadingJar() {
// Kinda hacky but it works
return this.downloads.some(d => d.path.includes('grasscutter'))
}
downloadingResources() {
// Kinda hacky but it works
return this.downloads.some(d => d.path.includes('resources'))
}
addDownload(url: string, path: string) { addDownload(url: string, path: string) {
// Begin download from rust backend, don't add if the download addition fails // Begin download from rust backend, don't add if the download addition fails