end of using REFS

This commit is contained in:
poslop
2024-06-06 00:11:57 -05:00
parent c60c8fee4b
commit f064e3eb9a
15 changed files with 192 additions and 131 deletions

View File

@@ -0,0 +1,45 @@
use tokio::fs;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
pub struct Config {
pub cslol_dir: String,
pub wad_dir: String,
pub extract_dir: String,
}
#[tauri::command]
pub async fn init_config() {
// Check if the config file exists asynchronously
if fs::metadata("config.toml").await.is_err() {
let config = Config {
cslol_dir: "".to_string(),
wad_dir: "C:\\Riot Games\\League of Legends\\Game\\DATA\\FINAL\\Champions".to_string(),
extract_dir: "".to_string(),
};
write_config(config).await; // Call the async version of write_config
}
}
#[tauri::command]
pub async fn load_config() -> Config {
// Read the config file asynchronously
let config = fs::read_to_string("config.toml").await
.expect("Failed to read config.toml file");
// Parse the config synchronously as before (no async TOML parser by default)
toml::from_str(&config)
.expect("Failed to parse config.toml file")
}
#[tauri::command]
pub async fn write_config(config: Config) {
// Serialize the config synchronously (no async TOML serializer by default)
let config_content = toml::to_string(&config)
.expect("Failed to serialize config");
// Write the config file asynchronously
fs::write("config.toml", config_content).await
.expect("Failed to write to config.toml file");
}

View File

@@ -1,7 +1,9 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
mod config_settings;
use config_settings::*;
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
@@ -9,7 +11,7 @@ fn greet(name: &str) -> String {
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.invoke_handler(tauri::generate_handler![greet, init_config, load_config, write_config])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}