From a89288630fbaa13eaecb7a4ecf95e4f1f292488d Mon Sep 17 00:00:00 2001 From: Yakumo Hokori Date: Wed, 25 Feb 2026 22:58:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 0 README.md | 31 ++++- src-tauri/Cargo.lock | 282 ++++++++++++++++++++++++++++++++++++++-- src-tauri/Cargo.toml | 1 + src-tauri/src/config.rs | 32 ++--- src-tauri/src/lib.rs | 17 +++ 6 files changed, 327 insertions(+), 36 deletions(-) delete mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index 2288a95..15f5308 100644 --- a/README.md +++ b/README.md @@ -156,15 +156,34 @@ pnpm tauri build ## 配置说明 ### 数据库配置 -数据库连接配置位于 `src-tauri/src/lib.rs`: -```rust -let db_url = "postgres://tmstools:521707@honulla.com:5432/tmstools"; +本应用使用 **PostgreSQL** 数据库进行数据持久化存储。数据库连接配置通过本地配置文件管理。 + +#### 配置文件位置 +所有平台统一使用 `~/.config/` 目录: +- **macOS**: `~/.config/tms_tools/config.toml` +- **Windows**: `~/.config/tms_tools/config.toml` +- **Linux**: `~/.config/tms_tools/config.toml` + +#### 配置文件格式 + +在启动应用前,需要手动创建配置文件: + +```toml +database_url = "postgres://用户名:密码@主机地址:端口/数据库名" ``` -### 外部 API -- 登录接口: `https://c.baobaot.com/user/ajax_login` -- 工单平台: `https://c.baobaot.com/cinema/workorder` +**示例:** +```toml +database_url = "postgres://tmstools:521707@localhost:5432/tmstools" +``` + +#### 启动检查 + +应用启动时会自动检查配置文件: +- ✅ 配置文件存在且格式正确 → 正常启动 +- ❌ 配置文件不存在 → 弹出错误提示,点击确定后退出 +- ❌ 数据库连接失败 → 在登录时提示错误 ## 开发计划 diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index e58f161..1497ea9 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -75,6 +75,24 @@ version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +[[package]] +name = "ashpd" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd884d7c72877a94102c3715f3b1cd09ff4fac28221add3e57cfbe25c236d093" +dependencies = [ + "async-fs", + "async-net", + "enumflags2", + "futures-channel", + "futures-util", + "rand 0.8.5", + "serde", + "serde_repr", + "url", + "zbus 4.4.0", +] + [[package]] name = "async-broadcast" version = "0.7.2" @@ -113,6 +131,17 @@ dependencies = [ "slab", ] +[[package]] +name = "async-fs" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8034a681df4aed8b8edbd7fbe472401ecf009251c8b40556b304567052e294c5" +dependencies = [ + "async-lock", + "blocking", + "futures-lite", +] + [[package]] name = "async-io" version = "2.4.1" @@ -143,6 +172,17 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "async-net" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b948000fad4873c1c9339d60f2623323a0cfd3816e5181033c6a5cb68b2accf7" +dependencies = [ + "async-io", + "blocking", + "futures-lite", +] + [[package]] name = "async-process" version = "2.3.1" @@ -285,6 +325,12 @@ dependencies = [ "serde", ] +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + [[package]] name = "block-buffer" version = "0.10.4" @@ -2167,6 +2213,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + [[package]] name = "markup5ever" version = "0.12.1" @@ -2338,6 +2393,19 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags 2.9.1", + "cfg-if", + "cfg_aliases", + "libc", + "memoffset", +] + [[package]] name = "nix" version = "0.30.1" @@ -2394,6 +2462,26 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + [[package]] name = "objc-sys" version = "0.3.5" @@ -2608,6 +2696,15 @@ dependencies = [ "objc2-foundation 0.3.1", ] +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + [[package]] name = "object" version = "0.36.7" @@ -2975,6 +3072,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "pollster" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2" + [[package]] name = "postgres-protocol" version = "0.6.8" @@ -3120,9 +3223,9 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.38.0" +version = "0.38.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8927b0664f5c5a98265138b7e3f90aa19a6b21353182469ace36d4ac527b7b1b" +checksum = "b66c2058c55a409d601666cffe35f04333cf1013010882cec174a7467cd4e21c" dependencies = [ "memchr", ] @@ -3383,6 +3486,29 @@ dependencies = [ "web-sys", ] +[[package]] +name = "rfd" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a73a7337fc24366edfca76ec521f51877b114e42dab584008209cca6719251" +dependencies = [ + "ashpd", + "block", + "dispatch", + "js-sys", + "log", + "objc", + "objc-foundation", + "objc_id", + "pollster", + "raw-window-handle", + "urlencoding", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-sys 0.48.0", +] + [[package]] name = "ring" version = "0.17.14" @@ -3798,6 +3924,17 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.9" @@ -4264,7 +4401,7 @@ dependencies = [ "thiserror 2.0.12", "url", "windows", - "zbus", + "zbus 5.8.0", ] [[package]] @@ -4505,6 +4642,7 @@ dependencies = [ "dirs 5.0.1", "lazy_static", "reqwest", + "rfd", "scraper", "serde", "serde_json", @@ -4934,6 +5072,12 @@ dependencies = [ "serde", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "urlpattern" version = "0.3.0" @@ -5811,6 +5955,16 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "xdg-home" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec1cdab258fb55c0da61328dc52c8764709b249011b2cad0454c72f0bf10a1f6" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "yoke" version = "0.8.0" @@ -5835,6 +5989,44 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zbus" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb97012beadd29e654708a0fdb4c84bc046f537aecfde2c3ee0a9e4b4d48c725" +dependencies = [ + "async-broadcast", + "async-executor", + "async-fs", + "async-io", + "async-lock", + "async-process", + "async-recursion", + "async-task", + "async-trait", + "blocking", + "enumflags2", + "event-listener", + "futures-core", + "futures-sink", + "futures-util", + "hex", + "nix 0.29.0", + "ordered-stream", + "rand 0.8.5", + "serde", + "serde_repr", + "sha1", + "static_assertions", + "tracing", + "uds_windows", + "windows-sys 0.52.0", + "xdg-home", + "zbus_macros 4.4.0", + "zbus_names 3.0.0", + "zvariant 4.2.0", +] + [[package]] name = "zbus" version = "5.8.0" @@ -5855,7 +6047,7 @@ dependencies = [ "futures-core", "futures-lite", "hex", - "nix", + "nix 0.30.1", "ordered-stream", "serde", "serde_repr", @@ -5863,9 +6055,22 @@ dependencies = [ "uds_windows", "windows-sys 0.59.0", "winnow 0.7.12", - "zbus_macros", - "zbus_names", - "zvariant", + "zbus_macros 5.8.0", + "zbus_names 4.2.0", + "zvariant 5.6.0", +] + +[[package]] +name = "zbus_macros" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267db9407081e90bbfa46d841d3cbc60f59c0351838c4bc65199ecd79ab1983e" +dependencies = [ + "proc-macro-crate 3.3.0", + "proc-macro2", + "quote", + "syn 2.0.104", + "zvariant_utils 2.1.0", ] [[package]] @@ -5878,9 +6083,20 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.104", - "zbus_names", - "zvariant", - "zvariant_utils", + "zbus_names 4.2.0", + "zvariant 5.6.0", + "zvariant_utils 3.2.0", +] + +[[package]] +name = "zbus_names" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c" +dependencies = [ + "serde", + "static_assertions", + "zvariant 4.2.0", ] [[package]] @@ -5892,7 +6108,7 @@ dependencies = [ "serde", "static_assertions", "winnow 0.7.12", - "zvariant", + "zvariant 5.6.0", ] [[package]] @@ -5975,6 +6191,20 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "zvariant" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2084290ab9a1c471c38fc524945837734fbf124487e105daec2bb57fd48c81fe" +dependencies = [ + "endi", + "enumflags2", + "serde", + "static_assertions", + "url", + "zvariant_derive 4.2.0", +] + [[package]] name = "zvariant" version = "5.6.0" @@ -5985,8 +6215,21 @@ dependencies = [ "enumflags2", "serde", "winnow 0.7.12", - "zvariant_derive", - "zvariant_utils", + "zvariant_derive 5.6.0", + "zvariant_utils 3.2.0", +] + +[[package]] +name = "zvariant_derive" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73e2ba546bda683a90652bac4a279bc146adad1386f25379cf73200d2002c449" +dependencies = [ + "proc-macro-crate 3.3.0", + "proc-macro2", + "quote", + "syn 2.0.104", + "zvariant_utils 2.1.0", ] [[package]] @@ -5999,7 +6242,18 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.104", - "zvariant_utils", + "zvariant_utils 3.2.0", +] + +[[package]] +name = "zvariant_utils" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index e79988e..9d4417c 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -31,4 +31,5 @@ scraper = "0.19.0" tms_service = { path = "./tms_service" } dirs = "5" toml = "0.8" +rfd = "0.14" diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index 8875a66..61e2aa1 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -7,31 +7,27 @@ pub struct Config { pub database_url: String, } -impl Default for Config { - fn default() -> Self { - Config { - database_url: "postgres://tmstools:521707@honulla.com:5432/tmstools".to_string(), - } - } -} - impl Config { /// 获取配置文件路径:~/.config/tms_tools/config.toml + /// 统一使用 ~/.config 目录,跨平台一致 pub fn config_path() -> Result { - let config_dir = dirs::config_dir() - .ok_or_else(|| "无法获取用户配置目录".to_string())?; + let home_dir = dirs::home_dir() + .ok_or_else(|| "无法获取用户主目录".to_string())?; + let config_dir = home_dir.join(".config"); let app_config_dir = config_dir.join("tms_tools"); let config_file = app_config_dir.join("config.toml"); Ok(config_file) } - /// 从配置文件加载配置,如果不存在则返回默认配置 + /// 从配置文件加载配置,如果不存在或解析失败则返回错误 pub fn load() -> Result { let config_path = Self::config_path()?; if !config_path.exists() { - // 配置文件不存在,返回默认配置 - return Ok(Config::default()); + return Err(format!( + "配置文件不存在: {}\n请创建配置文件,例如:\n\n[config]\ndatabase_url = \"postgres://username:password@host:port/database\"", + config_path.display() + )); } let content = fs::read_to_string(&config_path) @@ -40,6 +36,10 @@ impl Config { let config: Config = toml::from_str(&content) .map_err(|e| format!("解析配置文件失败: {}", e))?; + if config.database_url.is_empty() { + return Err("配置文件中的 database_url 不能为空".to_string()); + } + Ok(config) } @@ -77,8 +77,8 @@ mod tests { use super::*; #[test] - fn test_default_config() { - let config = Config::default(); - assert!(!config.database_url.is_empty()); + fn test_config_path() { + let path = Config::config_path(); + assert!(path.is_ok()); } } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 985184b..b0530c0 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -583,6 +583,23 @@ async fn feedback_and_close_today_workorders() -> Result { #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { + // 首先验证配置 + if let Err(e) = config::Config::load() { + // 配置加载失败,显示错误弹窗并退出 + eprintln!("配置错误: {}", e); + + // 使用 rfd 显示错误弹窗(阻塞模式) + rfd::MessageDialog::new() + .set_title("配置错误") + .set_description(&format!("{}\n\n软件将关闭。", e)) + .set_buttons(rfd::MessageButtons::Ok) + .set_level(rfd::MessageLevel::Error) + .show(); + + // 用户点击确定后退出应用 + std::process::exit(1); + } + tauri::Builder::default() .plugin(tauri_plugin_opener::init()) .invoke_handler(tauri::generate_handler![