allow custom java set

This commit is contained in:
SpikeHD
2022-05-16 16:58:02 -07:00
parent bcffcb3fdc
commit f5147239ae
5 changed files with 32 additions and 4 deletions

View File

@@ -12,6 +12,7 @@
"options": {
"game_exec": "Set Game Executable",
"grasscutter_jar": "Set Grasscutter Jar",
"java_path": "Set Custom Java Path",
"grasscutter_with_game": "Automatically launch Grasscutter with game"
},
"downloads": {

View File

@@ -71,9 +71,15 @@ fn run_program(path: String) {
}
#[tauri::command]
fn run_jar(path: String, execute_in: String) {
fn run_jar(path: String, execute_in: String, java_path: String) {
let mut command = if java_path.is_empty() {
format!("java -jar {}", path)
} else {
format!("\"{}\" -jar {}", java_path, path)
};
// Open the program from the specified path.
match open::with(format!("/k cd /D \"{}\" & java -jar {}", &execute_in, &path).to_string(), "C:\\Windows\\System32\\cmd.exe") {
match open::with(format!("/k cd /D \"{}\" & {}", &execute_in, &command).to_string(), "C:\\Windows\\System32\\cmd.exe") {
Ok(_) => (),
Err(e) => println!("Failed to open jar ({} from {}): {}", &path, &execute_in, e),
};

View File

@@ -106,7 +106,8 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
// Launch the jar
await invoke('run_jar', {
path: config.grasscutter_path,
executeIn: jarFolder
executeIn: jarFolder,
javaPath: config.java_path || ''
})
}

View File

@@ -14,6 +14,7 @@ interface IProps {
interface IState {
game_install_path: string
grasscutter_path: string
java_path: string
grasscutter_with_game: boolean
}
@@ -24,6 +25,7 @@ export default class Options extends React.Component<IProps, IState> {
this.state = {
game_install_path: '',
grasscutter_path: '',
java_path: '',
grasscutter_with_game: false
}
}
@@ -33,6 +35,7 @@ export default class Options extends React.Component<IProps, IState> {
this.setState({
game_install_path: config.game_install_path || '',
grasscutter_path: config.grasscutter_path || '',
java_path: config.java_path || '',
grasscutter_with_game: config.grasscutter_with_game || false
})
})
@@ -48,6 +51,10 @@ export default class Options extends React.Component<IProps, IState> {
setConfigOption('grasscutter_path', value)
}
setJavaPath(value: string) {
setConfigOption('java_path', value)
}
async toggleGrasscutterWithGame() {
setConfigOption('grasscutter_with_game', !(await getConfigOption('grasscutter_with_game')))
}
@@ -82,6 +89,17 @@ export default class Options extends React.Component<IProps, IState> {
<Checkbox onChange={this.toggleGrasscutterWithGame} checked={this.state?.grasscutter_with_game} id="gcWithGame" />
</div>
</div>
<Divider />
<div className='OptionSection'>
<div className='OptionLabel'>
<Tr text="options.java_path" />
</div>
<div className='OptionValue'>
<DirInput onChange={this.setJavaPath} value={this.state?.java_path} extensions={['exe']} />
</div>
</div>
</Menu>
)
}

View File

@@ -12,7 +12,8 @@ let defaultConfig: Configuration
toggle_grasscutter: false,
game_install_path: 'C:\\Program Files\\Genshin Impact\\Genshin Impact game\\Genshin Impact.exe',
grasscutter_with_game: false,
grasscutter_path: roamingAppData + '\\cultivation\\grasscutter.jar',
grasscutter_path: roamingAppData + '\\cultivation\\grasscutter\\grasscutter.jar',
java_path: '',
close_action: 0,
startup_launch: false,
last_ip: '',
@@ -28,6 +29,7 @@ export interface Configuration {
game_install_path: string
grasscutter_with_game: boolean
grasscutter_path: string
java_path: string
close_action: number
startup_launch: boolean
last_ip: string