generate and install cert based on config setting

This commit is contained in:
SpikeHD
2022-05-22 21:55:59 -07:00
parent 94e0faba6c
commit 805a9914be
3 changed files with 24 additions and 6 deletions

View File

@@ -16,6 +16,7 @@ import NewsSection from './components/news/NewsSection'
import RightBar from './components/RightBar'
import { getConfigOption, setConfigOption } from '../utils/configuration'
import { invoke } from '@tauri-apps/api'
import { dataDir } from '@tauri-apps/api/path'
interface IProps {
[key: string]: never;
@@ -52,6 +53,7 @@ class App extends React.Component<IProps, IState> {
}
async componentDidMount() {
const cert_generated = await getConfigOption('cert_generated')
const game_exe = await getConfigOption('game_install_path')
const game_path = game_exe.substring(0, game_exe.lastIndexOf('\\'))
const root_path = game_path.substring(0, game_path.lastIndexOf('\\'))
@@ -68,6 +70,15 @@ class App extends React.Component<IProps, IState> {
})
}
}
if (!cert_generated) {
// Generate the certificate
await invoke('generate_ca_files', {
path: await dataDir() + 'cultivation'
})
await setConfigOption('cert_generated', true)
}
}
render() {

View File

@@ -17,6 +17,7 @@ let defaultConfig: Configuration
last_port: '',
language: 'en',
customBackground: '',
cert_generated: false,
}
})()
@@ -35,6 +36,7 @@ export interface Configuration {
last_port: string
language: string
customBackground: string
cert_generated: boolean
}
export async function setConfigOption(key: string, value: any): Promise<void> {
@@ -94,7 +96,6 @@ async function readConfigFile() {
await fs.createDir(local + 'cultivation\\grasscutter')
}
const dataFiles = await fs.readDir(local + 'cultivation')
// Ensure config exists