mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2026-02-04 17:32:10 +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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "minisign-verify"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "933dca44d65cdd53b355d0b73d380a2ff5da71f87f036053188bf1eab6a19881"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miniz_oxide"
|
name = "miniz_oxide"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
@@ -3893,7 +3887,6 @@ checksum = "a34cef4a0ebee0230baaa319b1709c4336f4add550149d2b005a9a5dc5d33617"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"attohttpc",
|
"attohttpc",
|
||||||
"base64",
|
|
||||||
"bincode",
|
"bincode",
|
||||||
"cocoa",
|
"cocoa",
|
||||||
"dirs-next",
|
"dirs-next",
|
||||||
@@ -3907,7 +3900,6 @@ dependencies = [
|
|||||||
"heck 0.4.0",
|
"heck 0.4.0",
|
||||||
"http",
|
"http",
|
||||||
"ignore",
|
"ignore",
|
||||||
"minisign-verify",
|
|
||||||
"notify-rust",
|
"notify-rust",
|
||||||
"objc",
|
"objc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@@ -3939,7 +3931,6 @@ dependencies = [
|
|||||||
"webkit2gtk",
|
"webkit2gtk",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"windows 0.30.0",
|
"windows 0.30.0",
|
||||||
"zip 0.6.2",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ tauri-build = { version = "1.0.0-rc.8", features = [] }
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
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.
|
# Access system process info.
|
||||||
sysinfo = "0.23.12"
|
sysinfo = "0.23.12"
|
||||||
|
|||||||
@@ -11,8 +11,11 @@
|
|||||||
"files_extracting": "Files Extracting: "
|
"files_extracting": "Files Extracting: "
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
|
"enabled": "Enabled",
|
||||||
|
"disabled": "Disabled",
|
||||||
"game_exec": "Set Game Executable",
|
"game_exec": "Set Game Executable",
|
||||||
"grasscutter_jar": "Set Grasscutter JAR",
|
"grasscutter_jar": "Set Grasscutter JAR",
|
||||||
|
"toggle_encryption": "Toggle Encryption",
|
||||||
"java_path": "Set Custom Java Path",
|
"java_path": "Set Custom Java Path",
|
||||||
"grasscutter_with_game": "Automatically launch Grasscutter with game",
|
"grasscutter_with_game": "Automatically launch Grasscutter with game",
|
||||||
"language": "Select Language",
|
"language": "Select Language",
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import { invoke } from '@tauri-apps/api'
|
|||||||
import { dataDir } from '@tauri-apps/api/path'
|
import { dataDir } from '@tauri-apps/api/path'
|
||||||
import DirInput from '../common/DirInput'
|
import DirInput from '../common/DirInput'
|
||||||
import Menu from './Menu'
|
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 { setConfigOption, getConfig, getConfigOption } from '../../../utils/configuration'
|
||||||
import Checkbox from '../common/Checkbox'
|
import Checkbox from '../common/Checkbox'
|
||||||
import Divider from './Divider'
|
import Divider from './Divider'
|
||||||
import { getThemeList } from '../../../utils/themes'
|
import { getThemeList } from '../../../utils/themes'
|
||||||
|
import * as server from '../../../utils/server'
|
||||||
|
|
||||||
import './Options.css'
|
import './Options.css'
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ interface IState {
|
|||||||
bg_url_or_path: string
|
bg_url_or_path: string
|
||||||
themes: string[]
|
themes: string[]
|
||||||
theme: string
|
theme: string
|
||||||
|
encryption: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Options extends React.Component<IProps, IState> {
|
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',
|
current_language: 'en',
|
||||||
bg_url_or_path: '',
|
bg_url_or_path: '',
|
||||||
themes: ['default'],
|
themes: ['default'],
|
||||||
theme: ''
|
theme: '',
|
||||||
|
encryption: false
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setGameExec = this.setGameExec.bind(this)
|
this.setGameExec = this.setGameExec.bind(this)
|
||||||
@@ -48,12 +51,17 @@ export default class Options extends React.Component<IProps, IState> {
|
|||||||
this.setJavaPath = this.setJavaPath.bind(this)
|
this.setJavaPath = this.setJavaPath.bind(this)
|
||||||
this.toggleGrasscutterWithGame = this.toggleGrasscutterWithGame.bind(this)
|
this.toggleGrasscutterWithGame = this.toggleGrasscutterWithGame.bind(this)
|
||||||
this.setCustomBackground = this.setCustomBackground.bind(this)
|
this.setCustomBackground = this.setCustomBackground.bind(this)
|
||||||
|
this.toggleEncryption = this.toggleEncryption.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const config = await getConfig()
|
const config = await getConfig()
|
||||||
const languages = await getLanguages()
|
const languages = await getLanguages()
|
||||||
|
|
||||||
|
// Remove jar from path
|
||||||
|
const path = config.grasscutter_path.replace(/\\/g, '/')
|
||||||
|
const folderPath = path.substring(0, path.lastIndexOf('/'))
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
game_install_path: config.game_install_path || '',
|
game_install_path: config.game_install_path || '',
|
||||||
grasscutter_path: config.grasscutter_path || '',
|
grasscutter_path: config.grasscutter_path || '',
|
||||||
@@ -63,7 +71,8 @@ export default class Options extends React.Component<IProps, IState> {
|
|||||||
current_language: config.language || 'en',
|
current_language: config.language || 'en',
|
||||||
bg_url_or_path: config.customBackground || '',
|
bg_url_or_path: config.customBackground || '',
|
||||||
themes: (await getThemeList()).map(t => t.name),
|
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()
|
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() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Menu closeFn={this.props.closeFn} className="Options" heading="Options">
|
<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']} />
|
<DirInput onChange={this.setGrasscutterJar} value={this.state?.grasscutter_path} extensions={['jar']} />
|
||||||
</div>
|
</div>
|
||||||
</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 />
|
<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