mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 23:24:35 +01:00
toggle encryption in options
This commit is contained in:
9
src-tauri/Cargo.lock
generated
9
src-tauri/Cargo.lock
generated
@@ -2104,12 +2104,6 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "minisign-verify"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "933dca44d65cdd53b355d0b73d380a2ff5da71f87f036053188bf1eab6a19881"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.5.1"
|
||||
@@ -3893,7 +3887,6 @@ checksum = "a34cef4a0ebee0230baaa319b1709c4336f4add550149d2b005a9a5dc5d33617"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"attohttpc",
|
||||
"base64",
|
||||
"bincode",
|
||||
"cocoa",
|
||||
"dirs-next",
|
||||
@@ -3907,7 +3900,6 @@ dependencies = [
|
||||
"heck 0.4.0",
|
||||
"http",
|
||||
"ignore",
|
||||
"minisign-verify",
|
||||
"notify-rust",
|
||||
"objc",
|
||||
"once_cell",
|
||||
@@ -3939,7 +3931,6 @@ dependencies = [
|
||||
"webkit2gtk",
|
||||
"webview2-com",
|
||||
"windows 0.30.0",
|
||||
"zip 0.6.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -16,7 +16,7 @@ tauri-build = { version = "1.0.0-rc.8", features = [] }
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tauri = { version = "1.0.0-rc.9", features = ["api-all", "updater"] }
|
||||
tauri = { version = "1.0.0-rc.9", features = ["api-all"] }
|
||||
|
||||
# Access system process info.
|
||||
sysinfo = "0.23.12"
|
||||
|
||||
@@ -11,8 +11,11 @@
|
||||
"files_extracting": "Files Extracting: "
|
||||
},
|
||||
"options": {
|
||||
"enabled": "Enabled",
|
||||
"disabled": "Disabled",
|
||||
"game_exec": "Set Game Executable",
|
||||
"grasscutter_jar": "Set Grasscutter JAR",
|
||||
"toggle_encryption": "Toggle Encryption",
|
||||
"java_path": "Set Custom Java Path",
|
||||
"grasscutter_with_game": "Automatically launch Grasscutter with game",
|
||||
"language": "Select Language",
|
||||
|
||||
@@ -3,11 +3,12 @@ import { invoke } from '@tauri-apps/api'
|
||||
import { dataDir } from '@tauri-apps/api/path'
|
||||
import DirInput from '../common/DirInput'
|
||||
import Menu from './Menu'
|
||||
import Tr, { getLanguages } from '../../../utils/language'
|
||||
import Tr, { getLanguages, translate } from '../../../utils/language'
|
||||
import { setConfigOption, getConfig, getConfigOption } from '../../../utils/configuration'
|
||||
import Checkbox from '../common/Checkbox'
|
||||
import Divider from './Divider'
|
||||
import { getThemeList } from '../../../utils/themes'
|
||||
import * as server from '../../../utils/server'
|
||||
|
||||
import './Options.css'
|
||||
|
||||
@@ -25,6 +26,7 @@ interface IState {
|
||||
bg_url_or_path: string
|
||||
themes: string[]
|
||||
theme: string
|
||||
encryption: boolean
|
||||
}
|
||||
|
||||
export default class Options extends React.Component<IProps, IState> {
|
||||
@@ -40,7 +42,8 @@ export default class Options extends React.Component<IProps, IState> {
|
||||
current_language: 'en',
|
||||
bg_url_or_path: '',
|
||||
themes: ['default'],
|
||||
theme: ''
|
||||
theme: '',
|
||||
encryption: false
|
||||
}
|
||||
|
||||
this.setGameExec = this.setGameExec.bind(this)
|
||||
@@ -48,11 +51,16 @@ export default class Options extends React.Component<IProps, IState> {
|
||||
this.setJavaPath = this.setJavaPath.bind(this)
|
||||
this.toggleGrasscutterWithGame = this.toggleGrasscutterWithGame.bind(this)
|
||||
this.setCustomBackground = this.setCustomBackground.bind(this)
|
||||
this.toggleEncryption = this.toggleEncryption.bind(this)
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
const config = await getConfig()
|
||||
const languages = await getLanguages()
|
||||
|
||||
// Remove jar from path
|
||||
const path = config.grasscutter_path.replace(/\\/g, '/')
|
||||
const folderPath = path.substring(0, path.lastIndexOf('/'))
|
||||
|
||||
this.setState({
|
||||
game_install_path: config.game_install_path || '',
|
||||
@@ -63,7 +71,8 @@ export default class Options extends React.Component<IProps, IState> {
|
||||
current_language: config.language || 'en',
|
||||
bg_url_or_path: config.customBackground || '',
|
||||
themes: (await getThemeList()).map(t => t.name),
|
||||
theme: config.theme || 'default'
|
||||
theme: config.theme || 'default',
|
||||
encryption: await server.encryptionEnabled(folderPath + '/config.json') || false
|
||||
})
|
||||
|
||||
this.forceUpdate()
|
||||
@@ -136,6 +145,26 @@ export default class Options extends React.Component<IProps, IState> {
|
||||
}
|
||||
}
|
||||
|
||||
async toggleEncryption() {
|
||||
const config = await getConfig()
|
||||
|
||||
// Check if grasscutter path is set
|
||||
if (!config.grasscutter_path) {
|
||||
alert('Grasscutter not set!')
|
||||
return
|
||||
}
|
||||
|
||||
// Remove jar from path
|
||||
const path = config.grasscutter_path.replace(/\\/g, '/')
|
||||
const folderPath = path.substring(0, path.lastIndexOf('/'))
|
||||
|
||||
await server.toggleEncryption(folderPath + '/config.json')
|
||||
|
||||
this.setState({
|
||||
encryption: !this.state.encryption
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Menu closeFn={this.props.closeFn} className="Options" heading="Options">
|
||||
@@ -155,6 +184,20 @@ export default class Options extends React.Component<IProps, IState> {
|
||||
<DirInput onChange={this.setGrasscutterJar} value={this.state?.grasscutter_path} extensions={['jar']} />
|
||||
</div>
|
||||
</div>
|
||||
<div className='OptionSection'>
|
||||
<div className='OptionLabel'>
|
||||
<Tr text="options.toggle_encryption" />
|
||||
</div>
|
||||
<div className='OptionValue'>
|
||||
<button onClick={this.toggleEncryption}>
|
||||
{
|
||||
this.state.encryption ?
|
||||
<Tr text="options.enabled" /> :
|
||||
<Tr text="options.disabled" />
|
||||
}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Divider />
|
||||
|
||||
|
||||
36
src/utils/server.ts
Normal file
36
src/utils/server.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { fs } from '@tauri-apps/api'
|
||||
|
||||
export async function toggleEncryption(path: string) {
|
||||
let serverConf
|
||||
|
||||
try {
|
||||
serverConf = JSON.parse(await fs.readTextFile(path))
|
||||
} catch(e) {
|
||||
console.log(`Server config at ${path} not found or invalid`)
|
||||
return
|
||||
}
|
||||
|
||||
const enabled = serverConf.server.http.encryption.useEncryption
|
||||
|
||||
serverConf.server.http.encryption.useEncryption = !enabled
|
||||
serverConf.server.http.encryption.useInRouting = !enabled
|
||||
|
||||
// Write file
|
||||
await fs.writeFile({
|
||||
path,
|
||||
contents: JSON.stringify(serverConf)
|
||||
})
|
||||
}
|
||||
|
||||
export async function encryptionEnabled(path: string) {
|
||||
let serverConf
|
||||
|
||||
try {
|
||||
serverConf = JSON.parse(await fs.readTextFile(path))
|
||||
} catch(e) {
|
||||
console.log(`Server config at ${path} not found or invalid`)
|
||||
return false
|
||||
}
|
||||
|
||||
return serverConf.server.http.encryption.useEncryption
|
||||
}
|
||||
Reference in New Issue
Block a user