mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 15:44:35 +01:00
configuration
This commit is contained in:
@@ -3,12 +3,16 @@ import logo from './logo.svg'
|
||||
import './App.css'
|
||||
import './custom.css'
|
||||
|
||||
// Config
|
||||
import { getConfigOption } from '../utils/configuration'
|
||||
|
||||
// Major Components
|
||||
import Topbar from './components/TopBar'
|
||||
import BigButton from './components/common/BigButton'
|
||||
|
||||
function playGame() {
|
||||
alert('cum')
|
||||
getConfigOption('test')
|
||||
}
|
||||
|
||||
function App() {
|
||||
|
||||
@@ -4,10 +4,22 @@ import './TopBar.css'
|
||||
import closeIcon from '../../resources/icons/close.svg'
|
||||
import minIcon from '../../resources/icons/min.svg'
|
||||
import cogBtn from '../../resources/icons/cog.svg'
|
||||
import { app } from '@tauri-apps/api'
|
||||
|
||||
export default class TopBar extends React.Component {
|
||||
constructor(props: unknown[]) {
|
||||
interface IProps {
|
||||
[key: string]: never
|
||||
}
|
||||
|
||||
interface IState {
|
||||
version: string
|
||||
}
|
||||
export default class TopBar extends React.Component<IProps, IState> {
|
||||
constructor(props: Record<string, never>) {
|
||||
super(props)
|
||||
|
||||
app.getVersion().then(version => {
|
||||
this.setState({ version })
|
||||
})
|
||||
}
|
||||
|
||||
handleClose() {
|
||||
@@ -22,8 +34,8 @@ export default class TopBar extends React.Component {
|
||||
return (
|
||||
<div className="TopBar" data-tauri-drag-region >
|
||||
<div id="title">
|
||||
<span>Cultivation</span>
|
||||
<span id="version">v0.1.0</span>
|
||||
<span data-tauri-drag-region>Cultivation</span>
|
||||
<span data-tauri-drag-region id="version">{this.state?.version}</span>
|
||||
</div>
|
||||
<div className="TopBtns">
|
||||
<div id="closeBtn" onClick={this.handleClose} className='TopButton'>
|
||||
|
||||
63
src/utils/configuration.ts
Normal file
63
src/utils/configuration.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { fs } from '@tauri-apps/api'
|
||||
import { dataDir } from '@tauri-apps/api/path'
|
||||
|
||||
let configFilePath: string
|
||||
|
||||
export async function setConfigOption(key: string, value: any): Promise<void> {
|
||||
return
|
||||
}
|
||||
|
||||
export async function getConfigOption(key: string): Promise<any> {
|
||||
const config = await getConfig()
|
||||
}
|
||||
|
||||
export async function getConfig() {
|
||||
const raw = await readConfigFile()
|
||||
let parsed
|
||||
|
||||
try {
|
||||
parsed = JSON.parse(raw)
|
||||
} catch(e) {
|
||||
// We could not open the file
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
return parsed
|
||||
}
|
||||
|
||||
export async function saveConfig(obj: { [key: string]: any }) {
|
||||
return
|
||||
}
|
||||
|
||||
async function readConfigFile() {
|
||||
const local = await dataDir()
|
||||
|
||||
if (!configFilePath) configFilePath = local + 'cultivation\\configuration.json'
|
||||
|
||||
// Ensure Cultivation dir exists
|
||||
const dirs = await fs.readDir(local)
|
||||
|
||||
if (!dirs.find((fileOrDir) => fileOrDir?.name === 'cultivation')) {
|
||||
// Create dir
|
||||
await fs.createDir(local + 'cultivation')
|
||||
}
|
||||
|
||||
const dataFiles = await fs.readDir(local + 'cultivation')
|
||||
|
||||
// Ensure config exists
|
||||
if (!dataFiles.find((fileOrDir) => fileOrDir?.name === 'configuration.json')) {
|
||||
// Create config file
|
||||
const file: fs.FsTextFileOption = {
|
||||
path: local + 'cultivation\\configuration.json',
|
||||
contents: '{}'
|
||||
}
|
||||
}
|
||||
|
||||
// Finally read the file
|
||||
|
||||
return await fs.readTextFile(local + 'cultivation\\configuration.json')
|
||||
}
|
||||
|
||||
async function writeConfigFile() {
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user