diff --git a/desktop/src/main.rs b/desktop/src/main.rs index a5f490a..b58643f 100644 --- a/desktop/src/main.rs +++ b/desktop/src/main.rs @@ -594,6 +594,11 @@ impl QftApp { ui.columns(2, |cols| { cols[0].group(|ui| { ui.heading("手机扫码 · QFTPAIR2"); + // Direct AP 的虚拟网卡最容易被防火墙拦住,把检测结果放在 + // 二维码旁边——用户在这里停留最久,也正是在这一步失败的。 + let listen_port = self.receive.server.as_ref().map(|s| s.port).unwrap_or(receiver::PREFERRED_PORT); + self.firewall_panel(ui, listen_port); + ui.add_space(8.0); if let Some(texture) = &self.receive.pair_texture { let side = ui.available_width().min(420.0).max(260.0); ui.vertical_centered(|ui| { let side = snap_to_physical(side, ui.ctx().pixels_per_point()); @@ -965,6 +970,9 @@ impl QftApp { } fn start_receiver(&mut self, ctx: &egui::Context) { + // Direct AP 会新建一块虚拟网卡,其网络类型往往与主网卡不同, + // 因此每次启动接收都重新检测一次,而不是沿用上次结果。 + self.refresh_firewall(); let Some(save_dir) = self.receive.save_dir.clone() else { return }; self.stop_receiver(); self.receive.status = "正在初始化接收服务…".into(); @@ -1418,6 +1426,46 @@ impl QftApp { }); } + /// 防火墙状态面板。手机接收(Direct AP)与电脑互传都要用, + /// 因此抽出来共用——此前只有电脑互传页有,而 Direct AP 恰恰是 + /// 最容易被防火墙拦住的路径:ICS 虚拟网卡有自己独立的网络类型, + /// 只覆盖专用/域网络的规则在它上面完全不生效。 + fn firewall_panel(&mut self, ui: &mut egui::Ui, port: u16) { + let blocked = self.pc.firewall.needs_action(); + ui.group(|ui| { + ui.horizontal_wrapped(|ui| { + if blocked { + ui.colored_label( + egui::Color32::from_rgb(220, 140, 60), + "⚠ 防火墙规则未覆盖当前网络类型,手机可能连不上", + ); + } else { + ui.colored_label(egui::Color32::from_rgb(80, 200, 120), "● 防火墙"); + } + if !self.pc.firewall_note.is_empty() { + ui.label(&self.pc.firewall_note); + } + }); + if blocked { + ui.small( + "Direct AP 会新建一块虚拟网卡,Windows 常把它归类为「公用网络」。\ + 只覆盖专用/域网络的规则在这块网卡上不生效,表现就是手机连上了 Wi-Fi 却找不到电脑。", + ); + } + ui.horizontal_wrapped(|ui| { + if ui.button("放行防火墙(需要管理员授权)").clicked() { + self.request_firewall_grant(); + } + if ui.small_button("复制手动放行命令").clicked() { + ui.ctx().copy_text(firewall::manual_instructions(port)); + } + if ui.small_button("重新检测").clicked() { + self.refresh_firewall(); + } + }); + }); + } + /// 只做**只读检测**,不申请任何权限。 /// /// 早先版本会在启动接收时自动弹 UAC。实际用下来这太侵入: