aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src-tauri/src/core
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2026-01-13 17:54:09 +0800
committerHsiangNianian <i@jyunko.cn>2026-01-13 17:54:09 +0800
commitf7cabe5a0388518be50eb225500b7b4800109274 (patch)
tree4e7c06b05a9629e7b5bca013e3b6c5fe64afa63a /src-tauri/src/core
parent893e22ff0ae61a6f50f377078a060cda105d4c7a (diff)
downloadDropOut-f7cabe5a0388518be50eb225500b7b4800109274.tar.gz
DropOut-f7cabe5a0388518be50eb225500b7b4800109274.zip
feat: Add config module
Diffstat (limited to 'src-tauri/src/core')
-rw-r--r--src-tauri/src/core/config.rs58
-rw-r--r--src-tauri/src/core/mod.rs1
2 files changed, 59 insertions, 0 deletions
diff --git a/src-tauri/src/core/config.rs b/src-tauri/src/core/config.rs
new file mode 100644
index 0000000..5558786
--- /dev/null
+++ b/src-tauri/src/core/config.rs
@@ -0,0 +1,58 @@
+use serde::{Deserialize, Serialize};
+use std::fs;
+use std::path::PathBuf;
+use std::sync::Mutex;
+use tauri::{AppHandle, Manager};
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct LauncherConfig {
+ pub min_memory: u32, // in MB
+ pub max_memory: u32, // in MB
+ pub java_path: String,
+ pub width: u32,
+ pub height: u32,
+}
+
+impl Default for LauncherConfig {
+ fn default() -> Self {
+ Self {
+ min_memory: 1024,
+ max_memory: 2048,
+ java_path: "java".to_string(),
+ width: 854,
+ height: 480,
+ }
+ }
+}
+
+pub struct ConfigState {
+ pub config: Mutex<LauncherConfig>,
+ pub file_path: PathBuf,
+}
+
+impl ConfigState {
+ pub fn new(app_handle: &AppHandle) -> Self {
+ let app_dir = app_handle.path().app_data_dir().unwrap();
+ let config_path = app_dir.join("config.json");
+
+ let config = if config_path.exists() {
+ let content = fs::read_to_string(&config_path).unwrap_or_default();
+ serde_json::from_str(&content).unwrap_or_default()
+ } else {
+ LauncherConfig::default()
+ };
+
+ Self {
+ config: Mutex::new(config),
+ file_path: config_path,
+ }
+ }
+
+ pub fn save(&self) -> Result<(), String> {
+ let config = self.config.lock().unwrap();
+ let content = serde_json::to_string_pretty(&*config).map_err(|e| e.to_string())?;
+ fs::create_dir_all(self.file_path.parent().unwrap()).map_err(|e| e.to_string())?;
+ fs::write(&self.file_path, content).map_err(|e| e.to_string())?;
+ Ok(())
+ }
+}
diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs
index c642161..6f7c3fe 100644
--- a/src-tauri/src/core/mod.rs
+++ b/src-tauri/src/core/mod.rs
@@ -3,3 +3,4 @@ pub mod auth;
pub mod downloader;
pub mod game_version;
pub mod rules;
+pub mod config;