fix(desktop): 防火墙提权改为手动触发;构建前检测占用;清理警告
三个问题一起处理。 1. 提权改为手动 上一版会在点「启动接收」时自动弹 UAC。实际用下来太侵入——多数人 只是想收个文件,却先被要求管理员授权。现在: - 检测保持自动,但**只读**,无任何副作用 - 提权只在用户点「放行防火墙(需要管理员授权)」时发生 - 按钮无条件保留,不再只在"检测到被拦"时出现:检测可能不准, 而用户遇到「对方连不上」时需要有地方可点 - 同时移除了拒绝标记的持久化——提权已不自动发生,无需记忆 2. Windows 构建报 os error 5 error: failed to remove file `...\target\release\qft-desktop.exe` Caused by: 拒绝访问。 (os error 5) 原因是 QFT 窗口还开着,运行中的 exe 锁住了产物文件,而 cargo 的报错 完全看不出这一层。VERIFY_WINDOWS_HOST.ps1 现在会在构建前检测 qft-desktop 进程,列出 PID 并询问是否结束;README 也补了说明 (含 Defender 扫描导致的偶发同类报错)。 3. 构建警告 15 → 5 长期堆积的警告会训练人忽略所有警告,所以逐条处理: - 真实问题:if 条件多余的括号,已修 - 为后续里程碑准备但尚未接线的 API(client::ping、download_file、 platform::direct_ap_support/ensure_dir),加 #[allow(dead_code)] 并注明将在哪个阶段使用 - 仅特定平台构造的项(firewall::RULE_NAME 只用于 Windows, FirewallStatus::Unsupported 只在 Linux 返回),改用 #[cfg_attr(not(...), allow(dead_code))],避免无条件放行 剩余 5 个均为本次改动之前既有(cache_mib、v/transport、security、 path),不属本次范围,未改动。 验证:cargo test 35/35,release 构建 5 个警告且全部是既有的。
This commit is contained in:
+7
-32
@@ -18,6 +18,8 @@ use anyhow::{bail, Context, Result};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// 规则显示名。检测与添加都用它,改名会导致旧规则失效。
|
||||
// 仅 Windows 分支使用;其余平台整段被 cfg 编译掉
|
||||
#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
|
||||
pub const RULE_NAME: &str = "QFT Desktop";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@@ -28,7 +30,8 @@ pub enum FirewallStatus {
|
||||
Missing,
|
||||
/// 查不出来(命令不可用、输出无法解析等),不要据此吓唬用户
|
||||
Unknown(String),
|
||||
/// 本平台不做自动放行
|
||||
/// 本平台不做自动放行(目前只有 Linux 会返回)
|
||||
#[cfg_attr(not(all(unix, not(target_os = "macos"))), allow(dead_code))]
|
||||
Unsupported(&'static str),
|
||||
}
|
||||
|
||||
@@ -38,27 +41,6 @@ impl FirewallStatus {
|
||||
}
|
||||
}
|
||||
|
||||
/// 用户拒绝过提权的标记。存在则不再自动弹窗。
|
||||
fn declined_marker() -> PathBuf {
|
||||
crate::platform::config_dir().join("firewall-declined")
|
||||
}
|
||||
|
||||
pub fn was_declined() -> bool {
|
||||
declined_marker().is_file()
|
||||
}
|
||||
|
||||
pub fn remember_declined() {
|
||||
let path = declined_marker();
|
||||
if let Some(parent) = path.parent() {
|
||||
let _ = crate::platform::ensure_dir(parent);
|
||||
}
|
||||
let _ = std::fs::write(&path, b"1");
|
||||
}
|
||||
|
||||
pub fn forget_declined() {
|
||||
let _ = std::fs::remove_file(declined_marker());
|
||||
}
|
||||
|
||||
fn current_exe() -> Result<PathBuf> {
|
||||
std::env::current_exe().context("无法获取本程序路径")
|
||||
}
|
||||
@@ -286,16 +268,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn declined_marker_round_trips() {
|
||||
// 记住/遗忘的状态必须能持久化,否则每次启动都会重新弹窗
|
||||
let existed = was_declined();
|
||||
remember_declined();
|
||||
assert!(was_declined(), "记录拒绝后应能读回");
|
||||
forget_declined();
|
||||
assert!(!was_declined(), "清除后应恢复");
|
||||
if existed {
|
||||
remember_declined();
|
||||
}
|
||||
fn status_is_read_only_and_repeatable() {
|
||||
// 检测必须无副作用:连续调用结果一致,且不改动任何系统设置
|
||||
assert_eq!(status(), status());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user