end of using REFS
This commit is contained in:
1
src-tauri/.gitignore
vendored
1
src-tauri/.gitignore
vendored
@@ -5,3 +5,4 @@
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
|
||||
|
||||
1
src-tauri/.taurignore
Normal file
1
src-tauri/.taurignore
Normal file
@@ -0,0 +1 @@
|
||||
config.toml
|
||||
@@ -11,9 +11,12 @@ edition = "2021"
|
||||
tauri-build = { version = "1", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "1", features = ["shell-open"] }
|
||||
tauri = { version = "1", features = [ "api-all"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
toml = "0.5"
|
||||
tokio = "1.38.0"
|
||||
serde-wasm-bindgen = "0.4"
|
||||
|
||||
[features]
|
||||
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
|
||||
|
||||
3
src-tauri/config.toml
Normal file
3
src-tauri/config.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
cslol_dir = "WHY U FUCK NO WORK"
|
||||
wad_dir = ""
|
||||
extract_dir = ""
|
||||
45
src-tauri/src/config_settings.rs
Normal file
45
src-tauri/src/config_settings.rs
Normal 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");
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -12,10 +12,16 @@
|
||||
},
|
||||
"tauri": {
|
||||
"allowlist": {
|
||||
"all": false,
|
||||
"all": true,
|
||||
"shell": {
|
||||
"all": false,
|
||||
"open": true
|
||||
},
|
||||
"fs": {
|
||||
"all": true
|
||||
},
|
||||
"window": {
|
||||
"all": true
|
||||
}
|
||||
},
|
||||
"windows": [
|
||||
|
||||
Reference in New Issue
Block a user