mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 15:44:35 +01:00
minimize/maximize on game open/close
This commit is contained in:
@@ -37,6 +37,7 @@ fn main() {
|
|||||||
req_get,
|
req_get,
|
||||||
get_bg_file,
|
get_bg_file,
|
||||||
base64_decode,
|
base64_decode,
|
||||||
|
is_game_running,
|
||||||
system_helpers::run_command,
|
system_helpers::run_command,
|
||||||
system_helpers::run_program,
|
system_helpers::run_program,
|
||||||
system_helpers::run_jar,
|
system_helpers::run_jar,
|
||||||
@@ -91,6 +92,14 @@ fn process_watcher() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn is_game_running() -> bool {
|
||||||
|
// Grab the game process name
|
||||||
|
let proc = WATCH_GAME_PROCESS.lock().unwrap().to_string();
|
||||||
|
|
||||||
|
return !&proc.is_empty();
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn enable_process_watcher(process: String) {
|
fn enable_process_watcher(process: String) {
|
||||||
*WATCH_GAME_PROCESS.lock().unwrap() = process;
|
*WATCH_GAME_PROCESS.lock().unwrap() = process;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import RightBar from './components/RightBar'
|
|||||||
import { getConfigOption, setConfigOption } from '../utils/configuration'
|
import { getConfigOption, setConfigOption } from '../utils/configuration'
|
||||||
import { invoke } from '@tauri-apps/api'
|
import { invoke } from '@tauri-apps/api'
|
||||||
import { dataDir } from '@tauri-apps/api/path'
|
import { dataDir } from '@tauri-apps/api/path'
|
||||||
|
import { appWindow } from '@tauri-apps/api/window'
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
[key: string]: never;
|
[key: string]: never;
|
||||||
@@ -54,6 +55,21 @@ class App extends React.Component<IProps, IState> {
|
|||||||
listen('jar_extracted', ({ payload }) => {
|
listen('jar_extracted', ({ payload }) => {
|
||||||
setConfigOption('grasscutter_path', payload)
|
setConfigOption('grasscutter_path', payload)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let min = false
|
||||||
|
|
||||||
|
// periodically check if we need to min/max based on whether the game is open
|
||||||
|
setInterval(async () => {
|
||||||
|
const gameOpen = await invoke('is_game_running')
|
||||||
|
|
||||||
|
if (gameOpen && !min) {
|
||||||
|
appWindow.minimize()
|
||||||
|
min = true
|
||||||
|
} else if (!gameOpen && min) {
|
||||||
|
appWindow.unminimize()
|
||||||
|
min = false
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
@@ -89,8 +105,6 @@ class App extends React.Component<IProps, IState> {
|
|||||||
this.setState({
|
this.setState({
|
||||||
isDownloading: downloadHandler.getDownloads().filter(d => d.status !== 'finished')?.length > 0
|
isDownloading: downloadHandler.getDownloads().filter(d => d.status !== 'finished')?.length > 0
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(downloadHandler.getDownloads())
|
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,9 +52,6 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
|
|||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const config = await getConfig()
|
const config = await getConfig()
|
||||||
|
|
||||||
console.log(config.last_ip)
|
|
||||||
console.log(config.last_port)
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
grasscutterEnabled: config.toggle_grasscutter,
|
grasscutterEnabled: config.toggle_grasscutter,
|
||||||
buttonLabel: await translate('main.launch_button'),
|
buttonLabel: await translate('main.launch_button'),
|
||||||
|
|||||||
Reference in New Issue
Block a user