fix: improve QR direct connection reliability and speed

This commit is contained in:
zhy200308
2026-08-12 11:14:34 +08:00
parent 9c16cc1690
commit f9e25819ee
8 changed files with 152 additions and 13 deletions
+12 -1
View File
@@ -7,7 +7,8 @@ use anyhow::Context;
use windows::{
core::HSTRING,
Devices::WiFiDirect::{
WiFiDirectAdvertisementPublisher, WiFiDirectAdvertisementPublisherStatus,
WiFiDirectAdvertisementListenStateDiscoverability, WiFiDirectAdvertisementPublisher,
WiFiDirectAdvertisementPublisherStatus,
},
Security::Credentials::PasswordCredential,
};
@@ -32,6 +33,16 @@ impl DirectAp {
.context("创建 Wi-Fi Direct publisher 失败")?;
let ad = publisher.Advertisement()
.context("读取 Wi-Fi Direct advertisement 失败")?;
// WinRT defaults this property to `None`, which still lets the
// publisher report `Started` but does not make the AP discoverable.
// Android then waits in the system Wi-Fi picker until it times out,
// exactly as if the hotspot had never been started. Intensive keeps
// the legacy SSID discoverable even when the desktop window is not
// foregrounded during the phone-side connection flow.
ad.SetListenStateDiscoverability(
WiFiDirectAdvertisementListenStateDiscoverability::Intensive,
)
.context("启用 QFT Wi-Fi Direct 可发现性失败")?;
ad.SetIsAutonomousGroupOwnerEnabled(true)
.context("启用 Autonomous Group Owner 失败")?;
let legacy = ad.LegacySettings()
+15 -2
View File
@@ -849,9 +849,22 @@ impl QftApp {
.as_ref()
.map(|server| server.port)
.unwrap_or(sender::PREFERRED_PORT);
self.firewall_panel(ui, listen_port);
// 宽屏下把连接信息放到防火墙右侧:这两块都是扫码失败时要一起核对的
// 诊断信息,并排后不必在控制区里上下寻找。最小窗口下仍改回纵向,
// 给防火墙按钮和较长的 endpoint 留出足够宽度。
if ui.available_width() >= 860.0 {
ui.columns(2, |cols| {
self.firewall_panel(&mut cols[0], listen_port);
self.send_connection_panel(&mut cols[1], listen_port);
});
} else {
self.firewall_panel(ui, listen_port);
ui.add_space(6.0);
self.send_connection_panel(ui, listen_port);
}
}
ui.add_space(6.0);
fn send_connection_panel(&mut self, ui: &mut egui::Ui, listen_port: u16) {
ui.group(|ui| {
ui.collapsing("二维码广播的地址", |ui| {
for endpoint in
+4 -1
View File
@@ -452,7 +452,6 @@ fn receive_parallel_chunk(
let mut out = OpenOptions::new().write(true).open(&part_path)?;
out.seek(SeekFrom::Start(offset))?;
copy_exact(reader, &mut out, content_len)?;
out.sync_data()?;
let received = {
let mut session = session_arc.lock().map_err(|_| anyhow::anyhow!("上传会话损坏"))?;
@@ -503,6 +502,10 @@ fn finish_parallel_upload(
)
};
// Per-chunk FlushFileBuffers serializes otherwise independent upload lanes
// and is especially costly on Windows. The in-memory session cannot resume
// across a desktop-process crash anyway, so commit once after all chunks.
OpenOptions::new().write(true).open(&part_path)?.sync_data()?;
let sha = hash_file(&part_path)?;
if final_path.exists() { bail!("目标文件已存在,请重新初始化上传") }
fs::rename(&part_path, &final_path).context("完成文件重命名失败")?;