mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 08:04:52 +01:00
open jar and game properly
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
"options": {
|
"options": {
|
||||||
"game_exec": "Set Game Executable",
|
"game_exec": "Set Game Executable",
|
||||||
"grasscutter_jar": "Set Grasscutter Jar",
|
"grasscutter_jar": "Set Grasscutter Jar",
|
||||||
"grasscutter_with_game": "Automatically launch Grasscutter with the game"
|
"grasscutter_with_game": "Automatically launch Grasscutter with game"
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"select_file": "Select file or folder..."
|
"select_file": "Select file or folder..."
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ all(not(debug_assertions), target_os = "windows"),
|
|||||||
windows_subsystem = "windows"
|
windows_subsystem = "windows"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
use std::process::Command;
|
||||||
use open;
|
use open;
|
||||||
|
|
||||||
mod downloader;
|
mod downloader;
|
||||||
@@ -15,6 +16,7 @@ fn main() {
|
|||||||
connect,
|
connect,
|
||||||
disconnect,
|
disconnect,
|
||||||
run_program,
|
run_program,
|
||||||
|
run_jar,
|
||||||
downloader::download_file,
|
downloader::download_file,
|
||||||
downloader::stop_download,
|
downloader::stop_download,
|
||||||
lang::get_lang
|
lang::get_lang
|
||||||
@@ -44,5 +46,17 @@ fn disconnect() {
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn run_program(path: String) {
|
fn run_program(path: String) {
|
||||||
// Open the program from the specified path.
|
// 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),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -14,4 +14,26 @@
|
|||||||
#serverControls .Checkbox label {
|
#serverControls .Checkbox label {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-weight: bold;
|
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%);
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import { getConfig, saveConfig } from '../../utils/configuration'
|
|||||||
import { translate } from '../../utils/language'
|
import { translate } from '../../utils/language'
|
||||||
import { invoke } from '@tauri-apps/api/tauri'
|
import { invoke } from '@tauri-apps/api/tauri'
|
||||||
|
|
||||||
|
import Server from '../../resources/icons/server.svg'
|
||||||
import './ServerLaunchSection.css'
|
import './ServerLaunchSection.css'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
@@ -61,13 +62,28 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
|
|||||||
await invoke('run_program', { path: config.game_path })
|
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() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div id="playButton">
|
<div id="playButton">
|
||||||
<div id="serverControls">
|
<div id="serverControls">
|
||||||
<Checkbox id="enableGC" label={this.state.checkboxLabel} onChange={this.toggleGrasscutter} checked={this.state.grasscutterEnabled}/>
|
<Checkbox id="enableGC" label={this.state.checkboxLabel} onChange={this.toggleGrasscutter} checked={this.state.grasscutterEnabled}/>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import './BigButton.css'
|
import './BigButton.css'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
text: string;
|
children: React.ReactNode;
|
||||||
onClick: () => any;
|
onClick: () => any;
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ export default class BigButton extends React.Component<IProps, never> {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="BigButton" onClick={this.handleClick} id={this.props.id}>
|
<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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user