open jar and game properly

This commit is contained in:
SpikeHD
2022-05-13 21:15:24 -07:00
parent a6b5891857
commit 10e9529509
5 changed files with 57 additions and 5 deletions

View File

@@ -8,7 +8,7 @@
"options": {
"game_exec": "Set Game Executable",
"grasscutter_jar": "Set Grasscutter Jar",
"grasscutter_with_game": "Automatically launch Grasscutter with the game"
"grasscutter_with_game": "Automatically launch Grasscutter with game"
},
"components": {
"select_file": "Select file or folder..."

View File

@@ -3,6 +3,7 @@ all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use std::process::Command;
use open;
mod downloader;
@@ -15,6 +16,7 @@ fn main() {
connect,
disconnect,
run_program,
run_jar,
downloader::download_file,
downloader::stop_download,
lang::get_lang
@@ -44,5 +46,17 @@ fn disconnect() {
#[tauri::command]
fn run_program(path: String) {
// Open the program from the specified path.
open::that(path).expect("Failed to open program");
match open::that(path) {
Ok(_) => (),
Err(e) => println!("Failed to open program: {}", e),
};
}
#[tauri::command]
fn run_jar(path: String) {
// Open the program from the specified path.
match open::with("/k java -jar ".to_string() + &path, "C:\\Windows\\System32\\cmd.exe") {
Ok(_) => (),
Err(e) => println!("Failed to open jar ({}): {}", &path, e),
};
}

View File

@@ -14,4 +14,26 @@
#serverControls .Checkbox label {
color: #fff;
font-weight: bold;
}
.ServerLaunchButtons {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
height: 100%;
}
#officialPlay {
width: 60%
}
#serverLaunch {
width: 5%;
}
.ServerIcon {
height: 20px;
filter: invert(28%) sepia(28%) saturate(1141%) hue-rotate(352deg) brightness(96%) contrast(88%);
}

View File

@@ -5,6 +5,7 @@ import { getConfig, saveConfig } from '../../utils/configuration'
import { translate } from '../../utils/language'
import { invoke } from '@tauri-apps/api/tauri'
import Server from '../../resources/icons/server.svg'
import './ServerLaunchSection.css'
interface IProps {
@@ -61,13 +62,28 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
await invoke('run_program', { path: config.game_path })
}
async launchServer() {
const config = await getConfig()
if (!config.grasscutter_path) return
// Launch the jar
await invoke('run_jar', { path: config.grasscutter_path })
}
render() {
return (
<div id="playButton">
<div id="serverControls">
<Checkbox id="enableGC" label={this.state.checkboxLabel} onChange={this.toggleGrasscutter} checked={this.state.grasscutterEnabled}/>
</div>
<BigButton text={this.state.buttonLabel} onClick={this.playGame} id="officialPlay" />
<div className="ServerLaunchButtons">
<BigButton onClick={this.playGame} id="officialPlay">{this.state.buttonLabel}</BigButton>
<BigButton onClick={this.launchServer} id="serverLaunch">
<img className="ServerIcon" src={Server} />
</BigButton>
</div>
</div>
)
}

View File

@@ -2,7 +2,7 @@ import React from 'react'
import './BigButton.css'
interface IProps {
text: string;
children: React.ReactNode;
onClick: () => any;
id: string;
}
@@ -21,7 +21,7 @@ export default class BigButton extends React.Component<IProps, never> {
render() {
return (
<div className="BigButton" onClick={this.handleClick} id={this.props.id}>
<div className="BigButtonText">{this.props.text}</div>
<div className="BigButtonText">{this.props.children}</div>
</div>
)
}