Skip to content

Commit

Permalink
Launch args from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
NotThorny committed Sep 17, 2023
1 parent cebed5c commit 8fd7a3a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src-tauri/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"redirect_more": "Also redirect other MHY games",
"check_aagl": "For more options, check the other launcher",
"grasscutter_elevation": "Method of running GC on restricted ports",
"web_cache": "Delete webCaches folder"
"web_cache": "Delete webCaches folder",
"launch_args": "Launch Args"
},
"downloads": {
"grasscutter_fullbuild": "Download Grasscutter All-in-One",
Expand Down
9 changes: 8 additions & 1 deletion src/ui/components/ServerLaunchSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface IState {
migotoSet: boolean

unElevated: boolean
launchArgs: string
}

export default class ServerLaunchSection extends React.Component<IProps, IState> {
Expand All @@ -64,6 +65,7 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
akebiSet: false,
migotoSet: false,
unElevated: false,
launchArgs: '',
}

this.toggleGrasscutter = this.toggleGrasscutter.bind(this)
Expand Down Expand Up @@ -95,6 +97,7 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
akebiSet: config.akebi_path !== '',
migotoSet: config.migoto_path !== '',
unElevated: config.un_elevated || false,
launchArgs: config.launch_args || '',
})
}

Expand Down Expand Up @@ -214,9 +217,13 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
if (config.un_elevated) {
await invoke('run_un_elevated', {
path: config.game_install_path,
args: config.launch_args,
})
} else {
await invoke('run_program_relative', { path: exe || config.game_install_path })
await invoke('run_program_relative', {
path: exe || config.game_install_path,
args: config.launch_args,
})
}
else alert('Game not found! At: ' + (exe || config.game_install_path))
}
Expand Down
23 changes: 23 additions & 0 deletions src/ui/components/menu/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as meta from '../../../utils/rsa'
import HelpButton from '../common/HelpButton'
import SmallButton from '../common/SmallButton'
import { confirm } from '@tauri-apps/api/dialog'
import TextInput from '../common/TextInput'

export enum GrasscutterElevation {
None = 'None',
Expand Down Expand Up @@ -50,6 +51,7 @@ interface IState {
platform: string
un_elevated: boolean
redirect_more: boolean
launch_args: string

// Linux stuff
grasscutter_elevation: string
Expand Down Expand Up @@ -85,6 +87,7 @@ export default class Options extends React.Component<IProps, IState> {
platform: '',
un_elevated: false,
redirect_more: false,
launch_args: '',

// Linux stuff
grasscutter_elevation: GrasscutterElevation.None,
Expand All @@ -107,6 +110,7 @@ export default class Options extends React.Component<IProps, IState> {
this.deleteWebCache = this.deleteWebCache.bind(this)
this.addMigotoDelay = this.addMigotoDelay.bind(this)
this.toggleUnElevatedGame = this.toggleUnElevatedGame.bind(this)
this.setLaunchArgs = this.setLaunchArgs.bind(this)
}

async componentDidMount() {
Expand Down Expand Up @@ -142,6 +146,7 @@ export default class Options extends React.Component<IProps, IState> {
platform,
un_elevated: config.un_elevated || false,
redirect_more: config.redirect_more || false,
launch_args: config.launch_args || '',

// Linux stuff
grasscutter_elevation: config.grasscutter_elevation || GrasscutterElevation.None,
Expand Down Expand Up @@ -371,6 +376,14 @@ export default class Options extends React.Component<IProps, IState> {
})
}

async setLaunchArgs(value: string) {
await setConfigOption('launch_args', value)

this.setState({
launch_args: value,
})
}

render() {
return (
<Menu closeFn={this.props.closeFn} className="Options" heading="Options">
Expand Down Expand Up @@ -682,6 +695,16 @@ export default class Options extends React.Component<IProps, IState> {
<Tr text="components.delete" />
</BigButton>
</div>
<div className="OptionLabel" id="menuOptionsLaunchArgs">
<Tr text="options.launch_args" />
</div>
<TextInput
id="launch_args"
key="launch_args"
placeholder={'-arg=value'}
onChange={this.setLaunchArgs}
initalValue={this.state.launch_args}
/>
</div>
</Menu>
)
Expand Down
2 changes: 2 additions & 0 deletions src/utils/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let defaultConfig: Configuration
auto_mongodb: false,
un_elevated: false,
redirect_more: false,
launch_args: '',

// Linux stuff
grasscutter_elevation: 'None',
Expand Down Expand Up @@ -62,6 +63,7 @@ export interface Configuration {
auto_mongodb: boolean
un_elevated: boolean
redirect_more: boolean
launch_args: string

// Linux stuff
grasscutter_elevation: string
Expand Down

0 comments on commit 8fd7a3a

Please sign in to comment.