read and write server config via backend

This commit is contained in:
SpikeHD
2022-07-16 16:36:05 -07:00
parent 8faaba2849
commit ffc37cc203
3 changed files with 56 additions and 5 deletions

View File

@@ -1,10 +1,12 @@
import { fs } from '@tauri-apps/api'
import { fs, invoke } from '@tauri-apps/api'
export async function toggleEncryption(path: string) {
let serverConf
try {
serverConf = JSON.parse(await fs.readTextFile(path))
serverConf = JSON.parse(await invoke('read_file', {
path,
}))
} catch(e) {
console.log(`Server config at ${path} not found or invalid`)
return
@@ -16,7 +18,7 @@ export async function toggleEncryption(path: string) {
serverConf.server.http.encryption.useInRouting = !enabled
// Write file
await fs.writeFile({
await invoke('write_file', {
path,
contents: JSON.stringify(serverConf, null, 2),
})
@@ -26,7 +28,9 @@ export async function encryptionEnabled(path: string) {
let serverConf
try {
serverConf = JSON.parse(await fs.readTextFile(path))
serverConf = JSON.parse(await invoke('read_file', {
path,
}))
} catch(e) {
console.log(`Server config at ${path} not found or invalid`)
return false