From 10e9529509aedea1e4683fcf05188b2cca89590b Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Fri, 13 May 2022 21:15:24 -0700 Subject: [PATCH] open jar and game properly --- lang/en.json | 2 +- src-tauri/src/main.rs | 16 +++++++++++++++- src/ui/components/ServerLaunchSection.css | 22 ++++++++++++++++++++++ src/ui/components/ServerLaunchSection.tsx | 18 +++++++++++++++++- src/ui/components/common/BigButton.tsx | 4 ++-- 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/lang/en.json b/lang/en.json index 99deb31..1a3d70f 100644 --- a/lang/en.json +++ b/lang/en.json @@ -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..." diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 2727613..c773c18 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -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), + }; } \ No newline at end of file diff --git a/src/ui/components/ServerLaunchSection.css b/src/ui/components/ServerLaunchSection.css index 0331be3..f0a0424 100644 --- a/src/ui/components/ServerLaunchSection.css +++ b/src/ui/components/ServerLaunchSection.css @@ -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%); } \ No newline at end of file diff --git a/src/ui/components/ServerLaunchSection.tsx b/src/ui/components/ServerLaunchSection.tsx index 4f8e121..d1efd5f 100644 --- a/src/ui/components/ServerLaunchSection.tsx +++ b/src/ui/components/ServerLaunchSection.tsx @@ -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 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 (
- +
+ {this.state.buttonLabel} + + + +
+
) } diff --git a/src/ui/components/common/BigButton.tsx b/src/ui/components/common/BigButton.tsx index e05d29f..3d3c248 100644 --- a/src/ui/components/common/BigButton.tsx +++ b/src/ui/components/common/BigButton.tsx @@ -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 { render() { return (
-
{this.props.text}
+
{this.props.children}
) }