mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 15:44:35 +01:00
Add an option that allows binding port 443
Kinda everts some changes of "Implement MongoDB autostart and GC watching". This commit makes launching MongoDB async
This commit is contained in:
@@ -4,7 +4,7 @@ import React from 'react'
|
||||
import TopBar from './components/TopBar'
|
||||
import ServerLaunchSection from './components/ServerLaunchSection'
|
||||
import MainProgressBar from './components/common/MainProgressBar'
|
||||
import Options from './components/menu/Options'
|
||||
import Options, { GrasscutterElevation } from './components/menu/Options'
|
||||
import MiniDialog from './components/MiniDialog'
|
||||
import DownloadList from './components/common/DownloadList'
|
||||
import Downloads from './components/menu/Downloads'
|
||||
@@ -15,7 +15,7 @@ import { ExtrasMenu } from './components/menu/ExtrasMenu'
|
||||
import Notification from './components/common/Notification'
|
||||
import GamePathNotify from './components/menu/GamePathNotify'
|
||||
|
||||
import { getConfigOption, setConfigOption } from '../utils/configuration'
|
||||
import { getConfig, getConfigOption, setConfigOption } from '../utils/configuration'
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { getVersion } from '@tauri-apps/api/app'
|
||||
import { listen } from '@tauri-apps/api/event'
|
||||
@@ -102,10 +102,28 @@ export class Main extends React.Component<IProps, IState> {
|
||||
// Emitted for automatic processes
|
||||
listen('grasscutter_closed', async () => {
|
||||
const autoService = await getConfigOption('auto_mongodb')
|
||||
const config = await getConfig()
|
||||
|
||||
if (autoService) {
|
||||
await invoke('stop_service', { service: 'MongoDB' })
|
||||
}
|
||||
|
||||
if ((await invoke('get_platform')) === 'linux') {
|
||||
switch (config.grasscutter_elevation) {
|
||||
case GrasscutterElevation.None:
|
||||
break
|
||||
|
||||
case GrasscutterElevation.Capability:
|
||||
await invoke('jvm_remove_cap', {
|
||||
javaPath: config.java_path,
|
||||
})
|
||||
break
|
||||
|
||||
default:
|
||||
console.error('Invalid grasscutter_elevation')
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let min = false
|
||||
|
||||
@@ -12,6 +12,7 @@ import Plus from '../../resources/icons/plus.svg'
|
||||
|
||||
import './ServerLaunchSection.css'
|
||||
import { dataDir } from '@tauri-apps/api/path'
|
||||
import { GrasscutterElevation } from './menu/Options'
|
||||
import { getGameExecutable, getGameVersion, getGrasscutterJar } from '../../utils/game'
|
||||
import { patchGame, unpatchGame } from '../../utils/rsa'
|
||||
import { listen } from '@tauri-apps/api/event'
|
||||
@@ -210,11 +211,12 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
|
||||
|
||||
if (!config.grasscutter_path) return alert('Grasscutter not installed or set!')
|
||||
|
||||
const grasscutter_jar = await getGrasscutterJar()
|
||||
await invoke('enable_grasscutter_watcher', {
|
||||
process: proc_name || grasscutter_jar,
|
||||
})
|
||||
|
||||
if (config.auto_mongodb) {
|
||||
const grasscutter_jar = await getGrasscutterJar()
|
||||
await invoke('enable_grasscutter_watcher', {
|
||||
process: proc_name || grasscutter_jar,
|
||||
})
|
||||
// Check if MongoDB is running and start it if not
|
||||
invoke('service_status', { service: 'MongoDB' })
|
||||
}
|
||||
@@ -227,8 +229,31 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
|
||||
jarFolder = jarFolder.substring(0, config.grasscutter_path.lastIndexOf('\\'))
|
||||
}
|
||||
|
||||
let cmd = 'run_jar'
|
||||
|
||||
if ((await invoke('get_platform')) === 'linux') {
|
||||
switch (config.grasscutter_elevation) {
|
||||
case GrasscutterElevation.None:
|
||||
break
|
||||
|
||||
case GrasscutterElevation.Capability:
|
||||
await invoke('jvm_add_cap', {
|
||||
javaPath: config.java_path,
|
||||
})
|
||||
break
|
||||
|
||||
case GrasscutterElevation.Root:
|
||||
cmd = 'run_jar_root'
|
||||
break
|
||||
|
||||
default:
|
||||
console.error('Invalid grasscutter_elevation')
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Launch the jar
|
||||
await invoke('run_jar', {
|
||||
await invoke(cmd, {
|
||||
path: config.grasscutter_path,
|
||||
executeIn: jarFolder,
|
||||
javaPath: config.java_path || '',
|
||||
|
||||
@@ -17,6 +17,12 @@ import * as meta from '../../../utils/rsa'
|
||||
import HelpButton from '../common/HelpButton'
|
||||
import SmallButton from '../common/SmallButton'
|
||||
|
||||
export enum GrasscutterElevation {
|
||||
None = 'None',
|
||||
Capability = 'Capability',
|
||||
Root = 'Root',
|
||||
}
|
||||
|
||||
interface IProps {
|
||||
closeFn: () => void
|
||||
downloadManager: DownloadHandler
|
||||
@@ -44,6 +50,9 @@ interface IState {
|
||||
un_elevated: boolean
|
||||
redirect_more: boolean
|
||||
|
||||
// Linux stuff
|
||||
grasscutter_elevation: string
|
||||
|
||||
// Swag stuff
|
||||
akebi_path: string
|
||||
migoto_path: string
|
||||
@@ -76,6 +85,9 @@ export default class Options extends React.Component<IProps, IState> {
|
||||
un_elevated: false,
|
||||
redirect_more: false,
|
||||
|
||||
// Linux stuff
|
||||
grasscutter_elevation: GrasscutterElevation.None,
|
||||
|
||||
// Swag stuff
|
||||
akebi_path: '',
|
||||
migoto_path: '',
|
||||
@@ -132,6 +144,9 @@ export default class Options extends React.Component<IProps, IState> {
|
||||
un_elevated: config.un_elevated || false,
|
||||
redirect_more: config.redirect_more || false,
|
||||
|
||||
// Linux stuff
|
||||
grasscutter_elevation: config.grasscutter_elevation || GrasscutterElevation.None,
|
||||
|
||||
// Swag stuff
|
||||
akebi_path: config.akebi_path || '',
|
||||
migoto_path: config.migoto_path || '',
|
||||
@@ -297,6 +312,14 @@ export default class Options extends React.Component<IProps, IState> {
|
||||
})
|
||||
}
|
||||
|
||||
async setGCElevation(value: string) {
|
||||
setConfigOption('grasscutter_elevation', value)
|
||||
|
||||
this.setState({
|
||||
grasscutter_elevation: value,
|
||||
})
|
||||
}
|
||||
|
||||
async removeRSA() {
|
||||
await meta.unpatchGame()
|
||||
}
|
||||
@@ -437,6 +460,25 @@ export default class Options extends React.Component<IProps, IState> {
|
||||
{this.state.platform === 'linux' && (
|
||||
<>
|
||||
<Divider />
|
||||
<div className="OptionSection" id="menuOptionsContainerGCElevation">
|
||||
<div className="OptionLabel" id="menuOptionsLabelGCElevation">
|
||||
<Tr text="options.grasscutter_elevation" />
|
||||
<HelpButton contents="help.grasscutter_elevation_help_text" />
|
||||
</div>
|
||||
<select
|
||||
value={this.state.grasscutter_elevation}
|
||||
id="menuOptionsSelectGCElevation"
|
||||
onChange={(event) => {
|
||||
this.setGCElevation(event.target.value)
|
||||
}}
|
||||
>
|
||||
{Object.keys(GrasscutterElevation).map((t) => (
|
||||
<option key={t} value={t}>
|
||||
{t}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="OptionSection" id="menuOptionsContainerCheckAAGL">
|
||||
<div className="OptionLabel" id="menuOptionsLabelCheckAAGL">
|
||||
<Tr text="options.check_aagl" />
|
||||
|
||||
@@ -28,6 +28,9 @@ let defaultConfig: Configuration
|
||||
auto_mongodb: false,
|
||||
un_elevated: false,
|
||||
redirect_more: false,
|
||||
|
||||
// Linux stuff
|
||||
grasscutter_elevation: 'None',
|
||||
}
|
||||
})()
|
||||
|
||||
@@ -60,6 +63,9 @@ export interface Configuration {
|
||||
un_elevated: boolean
|
||||
redirect_more: boolean
|
||||
|
||||
// Linux stuff
|
||||
grasscutter_elevation: string
|
||||
|
||||
// Swag stuff
|
||||
akebi_path?: string
|
||||
migoto_path?: string
|
||||
|
||||
Reference in New Issue
Block a user