diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 96e6fc1..0bb7961 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -12,8 +12,8 @@ android { applicationId = "com.qft.optical" minSdk = 24 targetSdk = 35 - versionCode = 21 - versionName = "0.4.9" + versionCode = 22 + versionName = "0.4.10" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/android/app/src/main/java/com/qft/optical/MainActivity.kt b/android/app/src/main/java/com/qft/optical/MainActivity.kt index 80bb408..33b1959 100644 --- a/android/app/src/main/java/com/qft/optical/MainActivity.kt +++ b/android/app/src/main/java/com/qft/optical/MainActivity.kt @@ -17,6 +17,7 @@ import android.util.Size import android.view.Gravity import android.view.MotionEvent import android.view.ScaleGestureDetector +import android.view.View import android.view.ViewGroup import android.widget.Button import android.widget.FrameLayout @@ -79,15 +80,17 @@ class MainActivity : ComponentActivity() { @Volatile private var connectedNetwork: Network? = null private var connectedBaseUrl: String? = null private val selectedFiles = mutableListOf() - private var managingFilesForPair: PairingPayload? = null - private var managingFilesForBaseUrl: String? = null private var sendStatusText: TextView? = null private var sendFilesText: TextView? = null + private var sendFilesContainer: LinearLayout? = null + private var sendAddButton: Button? = null + private var sendClearButton: Button? = null private var sendProgress: ProgressBar? = null private var sendButton: Button? = null private var connectingStatusText: TextView? = null private var downloadStatusText: TextView? = null @Volatile private var downloadRunning = false + @Volatile private var uploadRunning = false /** 非 null 表示当前传输应立刻中止(QFT 临时网络断开等)。 * 下载线程每读一个缓冲区就检查一次,避免在 readTimeout 上白等。 */ @Volatile private var transferAbortReason: String? = null @@ -117,18 +120,16 @@ class MainActivity : ComponentActivity() { } private val pickFiles = registerForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { uris -> + if (uploadRunning) { + sendStatusText?.text = "传输已经开始,当前队列已锁定" + return@registerForActivityResult + } var unknown = 0 for (uri in uris) { val file = UploadClient.describeFile(contentResolver, uri) if (file != null && selectedFiles.none { it.uri == file.uri }) selectedFiles += file else if (file == null) unknown++ } renderSelectedFiles() - val pair = managingFilesForPair - val baseUrl = managingFilesForBaseUrl - if (pair != null && baseUrl != null) { - showFileSelection(pair, baseUrl) - return@registerForActivityResult - } if (unknown > 0) { sendStatusText?.text = "有 $unknown 个文件无法确定大小,已跳过" } else if (selectedFiles.isNotEmpty()) { @@ -159,8 +160,14 @@ class MainActivity : ComponentActivity() { downloadRunning = false downloadStatusText = null selectedFiles.clear() - managingFilesForPair = null - managingFilesForBaseUrl = null + uploadRunning = false + sendFilesContainer = null + sendAddButton = null + sendClearButton = null + sendFilesText = null + sendStatusText = null + sendProgress = null + sendButton = null val root = pageColumn() root.addView(text("QFT", 30f, Color.WHITE, true)) @@ -195,7 +202,7 @@ class MainActivity : ComponentActivity() { ) { showReceivedFiles() }) root.addView(space(22)) root.addView(text("本机设备:$receiverDeviceLabel", 13f, MUTED)) - root.addView(text("QFT v0.4.9 · Android 7+ 到最新", 12f, MUTED)) + root.addView(text("QFT v0.4.10 · Android 7+ 到最新", 12f, MUTED)) setContentView(ScrollView(this).apply { setBackgroundColor(BG); addView(root) }) } @@ -811,12 +818,34 @@ class MainActivity : ComponentActivity() { }) root.addView(space(14)) root.addView(card().apply { - addView(text("选择文件", 17f, Color.WHITE, true)) + addView(text("传输队列", 17f, Color.WHITE, true)) sendFilesText = text("请先选择需要传输的文件", 14f, WARNING) addView(sendFilesText, matchWrap(top = 8)) - addView(button("选择文件(可多选)").apply { - setOnClickListener { showFileSelection(pair, baseUrl) } - }, matchWrap(top = 12)) + sendFilesContainer = LinearLayout(this@MainActivity).apply { + orientation = LinearLayout.VERTICAL + } + addView(sendFilesContainer, matchWrap(top = 6)) + val actions = LinearLayout(this@MainActivity).apply { + orientation = LinearLayout.HORIZONTAL + gravity = Gravity.CENTER_VERTICAL + } + sendAddButton = button("添加文件").apply { + setOnClickListener { pickFiles.launch(arrayOf("*/*")) } + } + sendClearButton = button("清空").apply { + setOnClickListener { + if (!uploadRunning) { + selectedFiles.clear() + renderSelectedFiles() + } + } + } + actions.addView(sendAddButton, LinearLayout.LayoutParams(0, dp(48), 1f).apply { + marginEnd = dp(8) + }) + actions.addView(sendClearButton, LinearLayout.LayoutParams(dp(96), dp(48))) + addView(actions, matchWrap(top = 12)) + addView(text("按住“拖动”上下移动可调整发送优先级;传输开始后队列会锁定。", 12f, MUTED), matchWrap(top = 8)) }) root.addView(space(14)) root.addView(card().apply { @@ -826,10 +855,9 @@ class MainActivity : ComponentActivity() { sendProgress = ProgressBar(this@MainActivity, null, android.R.attr.progressBarStyleHorizontal).apply { max = 1000; progress = 0 } addView(sendProgress, LinearLayout.LayoutParams(-1, dp(9)).apply { topMargin = dp(12) }) sendButton = button("选择传输文件").apply { - isEnabled = connectedBaseUrl != null + isEnabled = false setOnClickListener { - if (selectedFiles.isEmpty()) showFileSelection(pair, baseUrl) - else startUploads(pair, baseUrl) + startUploads(pair, baseUrl) } } addView(sendButton, matchWrap(top = 14)) @@ -1008,95 +1036,117 @@ class MainActivity : ComponentActivity() { setContentView(ScrollView(this).apply { setBackgroundColor(BG); addView(root) }) } - private fun showFileSelection(pair: PairingPayload, baseUrl: String) { - managingFilesForPair = pair - managingFilesForBaseUrl = baseUrl - val root = pageColumn() - root.addView(text("选择发送文件", 28f, Color.WHITE, true)) - root.addView(text("可多次添加文件,并在列表中单独移除。", 14f, MUTED)) - root.addView(space(14)) - val total = selectedFiles.sumOf { it.size } - root.addView(card().apply { - addView(text("已选 ${selectedFiles.size} 个 · ${humanBytes(total)}", 16f, ACCENT, true)) - if (selectedFiles.isEmpty()) { - addView(text("请先选择需要传输的文件", 14f, WARNING), matchWrap(top = 8)) - } else { - selectedFiles.toList().forEach { file -> - val row = LinearLayout(this@MainActivity).apply { - orientation = LinearLayout.HORIZONTAL - gravity = Gravity.CENTER_VERTICAL - } - row.addView( - text("${file.name}\n${humanBytes(file.size)}", 14f, Color.WHITE), - LinearLayout.LayoutParams(0, -2, 1f).apply { marginEnd = dp(8) }, - ) - row.addView(button("移除").apply { - setOnClickListener { - selectedFiles.removeAll { it.uri == file.uri } - showFileSelection(pair, baseUrl) - } - }, LinearLayout.LayoutParams(dp(82), dp(44))) - addView(row, matchWrap(top = 10)) - } - } - }) - root.addView(space(14)) - root.addView(button("添加文件(可多选)").apply { - setOnClickListener { pickFiles.launch(arrayOf("*/*")) } - }) - if (selectedFiles.isNotEmpty()) { - root.addView(space(10)) - root.addView(button("清空选择").apply { - setOnClickListener { - selectedFiles.clear() - showFileSelection(pair, baseUrl) - } - }) - } - root.addView(space(10)) - root.addView(button("完成并返回传输").apply { - isEnabled = selectedFiles.isNotEmpty() - setOnClickListener { - managingFilesForPair = null - managingFilesForBaseUrl = null - showSendReady(pair, baseUrl) - } - }) - root.addView(space(10)) - root.addView(button("取消并返回传输").apply { - setOnClickListener { - managingFilesForPair = null - managingFilesForBaseUrl = null - showSendReady(pair, baseUrl) - } - }) - setContentView(ScrollView(this).apply { setBackgroundColor(BG); addView(root) }) - } - private fun renderSelectedFiles() { val total = selectedFiles.sumOf { it.size } sendFilesText?.text = if (selectedFiles.isEmpty()) { "请先选择需要传输的文件" } else { - buildString { - selectedFiles.take(8).forEach { append("• ${it.name} ${humanBytes(it.size)}\n") } - if (selectedFiles.size > 8) append("…另外 ${selectedFiles.size - 8} 个文件\n") - append("共 ${selectedFiles.size} 个 · ${humanBytes(total)}") - }.trim() + "已选 ${selectedFiles.size} 个 · ${humanBytes(total)} · 按列表顺序发送" + } + sendFilesText?.setTextColor(if (selectedFiles.isEmpty()) WARNING else ACCENT) + + val container = sendFilesContainer + container?.removeAllViews() + selectedFiles.toList().forEachIndexed { index, file -> + val row = LinearLayout(this).apply { + orientation = LinearLayout.HORIZONTAL + gravity = Gravity.CENTER_VERTICAL + setPadding(0, dp(4), 0, dp(4)) + } + val drag = button("拖动").apply { + isEnabled = !uploadRunning + textSize = 12f + } + row.addView(drag, LinearLayout.LayoutParams(dp(76), dp(44)).apply { + marginEnd = dp(8) + }) + row.addView( + text("${index + 1}. ${file.name}\n${humanBytes(file.size)}", 14f, Color.WHITE), + LinearLayout.LayoutParams(0, -2, 1f).apply { marginEnd = dp(8) }, + ) + row.addView(button("删除").apply { + isEnabled = !uploadRunning + textSize = 12f + setOnClickListener { + if (!uploadRunning) { + selectedFiles.removeAll { it.uri == file.uri } + renderSelectedFiles() + } + } + }, LinearLayout.LayoutParams(dp(76), dp(44))) + container?.addView(row, matchWrap(top = if (index == 0) 2 else 4)) + if (container != null && !uploadRunning) { + installFileQueueDrag(drag, row, file, container) + } + } + + sendAddButton?.isEnabled = !uploadRunning + sendClearButton?.isEnabled = !uploadRunning && selectedFiles.isNotEmpty() + sendButton?.text = when { + uploadRunning -> "传输中 · 队列已锁定" + selectedFiles.isEmpty() -> "请先添加文件" + else -> "开始传输 ${selectedFiles.size} 个文件" + } + sendButton?.isEnabled = connectedBaseUrl != null && selectedFiles.isNotEmpty() && !uploadRunning + } + + private fun installFileQueueDrag( + handle: View, + row: View, + file: SelectedFile, + container: LinearLayout, + ) { + handle.setOnTouchListener { view, event -> + if (uploadRunning) return@setOnTouchListener false + when (event.actionMasked) { + MotionEvent.ACTION_DOWN -> { + view.parent?.requestDisallowInterceptTouchEvent(true) + row.alpha = 0.72f + true + } + MotionEvent.ACTION_MOVE -> { + val location = IntArray(2) + container.getLocationOnScreen(location) + val y = event.rawY - location[1] + var target = container.childCount - 1 + for (index in 0 until container.childCount) { + val child = container.getChildAt(index) + if (y < child.top + child.height / 2f) { + target = index + break + } + } + val current = selectedFiles.indexOfFirst { it.uri == file.uri } + if (moveQueueItem(selectedFiles, current, target)) { + container.removeView(row) + container.addView(row, target) + } + true + } + MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { + view.parent?.requestDisallowInterceptTouchEvent(false) + row.alpha = 1f + view.performClick() + renderSelectedFiles() + true + } + else -> false + } } - sendButton?.text = if (selectedFiles.isEmpty()) "选择传输文件" else "开始传输" - sendButton?.isEnabled = connectedBaseUrl != null } private fun startUploads(pair: PairingPayload, baseUrl: String) { + if (uploadRunning) return if (selectedFiles.isEmpty()) { sendStatusText?.setTextColor(WARNING) sendStatusText?.text = "请先选择需要传输的文件" - showFileSelection(pair, baseUrl) + pickFiles.launch(arrayOf("*/*")) return } val files = selectedFiles.toList() - sendButton?.isEnabled = false + uploadRunning = true + transferAbortReason = null + renderSelectedFiles() wifiConnector.acquireHighPerfLock() transferExecutor.execute { try { @@ -1132,15 +1182,17 @@ class MainActivity : ComponentActivity() { runOnUiThread { sendProgress?.progress = 1000 sendStatusText?.text = "全部完成 · 已发送 ${files.size} 个文件" - sendButton?.isEnabled = true } } catch (e: Exception) { runOnUiThread { sendStatusText?.text = "传输失败:${e.message}" - sendButton?.isEnabled = true } } finally { wifiConnector.releaseHighPerfLock() + runOnUiThread { + uploadRunning = false + renderSelectedFiles() + } } } } diff --git a/android/app/src/main/java/com/qft/optical/TransferQueue.kt b/android/app/src/main/java/com/qft/optical/TransferQueue.kt new file mode 100644 index 0000000..de41fb1 --- /dev/null +++ b/android/app/src/main/java/com/qft/optical/TransferQueue.kt @@ -0,0 +1,8 @@ +package com.qft.optical + +/** Move one item while preserving every other item's relative order. */ +internal fun moveQueueItem(items: MutableList, from: Int, to: Int): Boolean { + if (from !in items.indices || to !in items.indices || from == to) return false + items.add(to, items.removeAt(from)) + return true +} diff --git a/android/app/src/test/java/com/qft/optical/TransferQueueTest.kt b/android/app/src/test/java/com/qft/optical/TransferQueueTest.kt new file mode 100644 index 0000000..fed5d93 --- /dev/null +++ b/android/app/src/test/java/com/qft/optical/TransferQueueTest.kt @@ -0,0 +1,26 @@ +package com.qft.optical + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class TransferQueueTest { + @Test + fun movesFilesInBothDirectionsWithoutLosingItems() { + val queue = mutableListOf("A", "B", "C", "D") + assertTrue(moveQueueItem(queue, 0, 2)) + assertEquals(listOf("B", "C", "A", "D"), queue) + assertTrue(moveQueueItem(queue, 3, 1)) + assertEquals(listOf("B", "D", "C", "A"), queue) + } + + @Test + fun rejectsInvalidOrNoOpMoves() { + val queue = mutableListOf("A", "B") + assertFalse(moveQueueItem(queue, -1, 0)) + assertFalse(moveQueueItem(queue, 0, 2)) + assertFalse(moveQueueItem(queue, 1, 1)) + assertEquals(listOf("A", "B"), queue) + } +} diff --git a/desktop/Cargo.lock b/desktop/Cargo.lock index 92d2043..258f949 100644 --- a/desktop/Cargo.lock +++ b/desktop/Cargo.lock @@ -2587,7 +2587,7 @@ checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea" [[package]] name = "qft-desktop" -version = "0.4.14" +version = "0.4.15" dependencies = [ "anyhow", "base64", diff --git a/desktop/Cargo.toml b/desktop/Cargo.toml index 354d593..ddcd39b 100644 --- a/desktop/Cargo.toml +++ b/desktop/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "qft-desktop" -version = "0.4.14" +version = "0.4.15" edition = "2024" rust-version = "1.95" diff --git a/desktop/src/main.rs b/desktop/src/main.rs index 2b3c1b6..df8883f 100644 --- a/desktop/src/main.rs +++ b/desktop/src/main.rs @@ -111,7 +111,6 @@ struct SendState { status: String, connected_device: String, qr_focus: bool, - qr_controls_height: f32, qr_zoom: f32, } @@ -241,7 +240,6 @@ impl QftApp { status: "选择文件后生成二维码;手机扫码会自动配网并开始下载。".into(), connected_device: "等待 Android 扫码".into(), qr_focus: false, - qr_controls_height: 220.0, qr_zoom: 1.0, }, pc: PcPeerState { @@ -574,6 +572,7 @@ impl QftApp { } let running = self.receive.server.is_some(); + if !running { ui.group(|ui| { ui.heading("1 · 保存位置"); ui.horizontal_wrapped(|ui| { @@ -629,17 +628,16 @@ impl QftApp { }); ui.label(&self.receive.status); }); + } if self.receive.server.is_some() { ui.add_space(10.0); + let listen_port = self.receive.server.as_ref() + .map(|server| server.port) + .unwrap_or(receiver::PREFERRED_PORT); 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 qr_zoom = self.receive.qr_zoom; ui.vertical_centered(|ui| { @@ -670,7 +668,12 @@ impl QftApp { } }); cols[1].group(|ui| { - ui.heading("接收状态 · Parallel v2"); + ui.horizontal_wrapped(|ui| { + ui.heading("接收状态 · Parallel v2"); + if ui.button("停止接收").clicked() { + self.stop_receiver(); + } + }); ui.label(format!("电脑:{}", self.local_device)); ui.label(format!("手机:{}", self.receive.connected_device)); ui.separator(); @@ -688,6 +691,8 @@ impl QftApp { ui.label(format!("最近保存:{}", self.receive.last_saved)); if !self.receive.last_sha256.is_empty() { ui.small(format!("SHA-256:{}", self.receive.last_sha256)); } }); + cols[1].add_space(8.0); + self.firewall_panel(&mut cols[1], listen_port); }); } } @@ -783,51 +788,19 @@ impl QftApp { } fn pc_to_phone_resizable_qr_ui(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) { - const DIVIDER_HEIGHT: f32 = 10.0; - let available_height = ui.available_height(); - let min_controls_height = 150.0; - let min_qr_height = 260.0_f32.min((available_height * 0.55).max(180.0)); - let max_controls_height = (available_height - min_qr_height - DIVIDER_HEIGHT) - .max(min_controls_height); - self.send.qr_controls_height = self - .send - .qr_controls_height - .clamp(min_controls_height, max_controls_height); - - ui.allocate_ui_with_layout( - egui::vec2(ui.available_width(), self.send.qr_controls_height), - egui::Layout::top_down(egui::Align::Min), - |ui| { - egui::ScrollArea::vertical().show(ui, |ui| { - self.pc_to_phone_running_controls(ui); - }); - }, - ); - - let (divider_rect, divider_response) = ui.allocate_exact_size( - egui::vec2(ui.available_width(), DIVIDER_HEIGHT), - egui::Sense::drag(), - ); - let divider_response = divider_response.on_hover_cursor(egui::CursorIcon::ResizeVertical); - let divider_color = if divider_response.dragged() || divider_response.hovered() { - ui.visuals().widgets.active.bg_fill + let _ = ctx; + if ui.available_width() >= 820.0 { + ui.columns(2, |cols| { + self.pc_to_phone_qr_panel(&mut cols[0], false); + egui::ScrollArea::vertical() + .auto_shrink([false, false]) + .show(&mut cols[1], |ui| self.pc_to_phone_running_controls(ui)); + }); } else { - ui.visuals().widgets.inactive.bg_fill - }; - ui.painter().rect_filled( - divider_rect.shrink2(egui::vec2(0.0, 3.0)), - 3.0, - divider_color, - ); - if divider_response.dragged() { - let delta_y = ui.input(|input| input.pointer.delta().y); - self.send.qr_controls_height = (self.send.qr_controls_height + delta_y) - .clamp(min_controls_height, max_controls_height); - ctx.request_repaint(); + self.pc_to_phone_qr_panel(ui, false); + ui.add_space(8.0); + self.pc_to_phone_running_controls(ui); } - divider_response.on_hover_text("上下拖动,调整控制区和二维码区域的高度"); - - self.pc_to_phone_qr_panel(ui, false); } fn pc_to_phone_running_controls(&mut self, ui: &mut egui::Ui) { @@ -869,7 +842,7 @@ impl QftApp { ui.label(format!("文件:{} · {}", file.display(), human_bytes(self.send.file_size))); } ui.label(&self.send.status); - ui.small("拖动下方分隔条可为二维码腾出更多高度;也可切换到“专注二维码”。"); + ui.small("二维码与控制区已并排显示;需要更大画面时可手动切换“专注二维码”。"); }); } @@ -949,28 +922,18 @@ impl QftApp { return; } - ui.columns(2, |cols| { - cols[0].group(|ui| { - ui.heading("手机扫码 · QFTSEND2"); - if let Some(texture) = &self.send.pair_texture { - let available = ui.available_size(); - let max_side = available.x.min((available.y - 42.0).max(1.0)); - let side = (max_side * self.send.qr_zoom).max(1.0).min(max_side); - let side = snap_to_physical(side, ui.ctx().pixels_per_point()); - ui.vertical_centered(|ui| { - ui.image((texture.id(), egui::vec2(side, side))); - }); - } - ui.set_min_height(panel_height); - }); - cols[1].group(|ui| { - ui.heading("发送状态"); - ui.label(format!("电脑:{}", self.local_device)); - ui.label(format!("手机:{}", self.send.connected_device)); - ui.label(self.send.file.as_ref().map(|file| format!("文件:{}", file.display())).unwrap_or_default()); - ui.small("二维码只在本次直传会话有效;停止直传后立即失效。"); - ui.set_min_height(panel_height); - }); + ui.group(|ui| { + ui.heading("手机扫码 · QFTSEND2"); + if let Some(texture) = &self.send.pair_texture { + let available = ui.available_size(); + let max_side = available.x.min((available.y - 42.0).max(1.0)); + let side = (max_side * self.send.qr_zoom).max(1.0).min(max_side); + let side = snap_to_physical(side, ui.ctx().pixels_per_point()); + ui.vertical_centered(|ui| { + ui.image((texture.id(), egui::vec2(side, side))); + }); + } + ui.small("二维码只在本次直传会话有效;停止直传后立即失效。"); }); } @@ -1143,9 +1106,9 @@ impl QftApp { self.receive.direct_ap = direct_ap; self.receive.events = Some(rx); self.receive.pair_texture = Some(ctx.load_texture("qft-pair-code", image, TextureOptions::NEAREST)); - // 扫码是启动后的唯一下一步,默认把窗口让给大二维码;用户仍可退出 - // 专注模式查看防火墙、地址和接收状态。 - self.receive.focus_qr = true; + // 保持普通布局,让用户同时看到二维码、连接状态和防火墙诊断;只有 + // 用户主动点击“专注二维码”时才隐藏其余信息。 + self.receive.focus_qr = false; self.receive.session_token = token; self.receive.connected_device = "等待 Android 扫码".into(); self.receive.current_file = "—".into(); @@ -1236,9 +1199,8 @@ impl QftApp { self.send.direct_ap = direct_ap; self.send.events = Some(rx); self.send.pair_texture = Some(ctx.load_texture("qft-send-code", image, TextureOptions::NEAREST)); - // QFTSEND2 往往还带文件名、大小和 SHA-256,比接收码更密;生成后 - // 直接放大显示,避免控制区把模块压到手机相机的识别下限附近。 - self.send.qr_focus = true; + // 启动后保持二维码与状态并排;专注模式由用户手动进入。 + self.send.qr_focus = false; self.send.session_token = token; self.send.connected_device = "等待 Android 扫码".into(); self.send.status = if self.send.use_direct_ap { @@ -2201,6 +2163,33 @@ mod font_tests { ); } + #[test] + fn running_send_qr_starts_beside_controls_without_forced_focus() { + let app = QftApp::bare(String::new()); + assert!(!app.send.qr_focus, "扫码直传不应默认进入专注二维码"); + assert!(!app.receive.focus_qr, "扫码接收不应默认进入专注二维码"); + + let positions = rendered_text_positions(|ui| { + let context = ui.ctx().clone(); + let mut app = QftApp::bare(String::new()); + app.pc_to_phone_resizable_qr_ui(ui, &context); + }); + let qr_y = positions + .iter() + .find(|(text, _)| text.contains("手机扫码 · QFTSEND2")) + .map(|(_, y)| *y) + .expect("应绘制二维码面板"); + let controls_y = positions + .iter() + .find(|(text, _)| text.contains("直传控制")) + .map(|(_, y)| *y) + .expect("应绘制控制面板"); + assert!( + (qr_y - controls_y).abs() <= 8.0, + "二维码和控制区应从同一行开始,实际 qr={qr_y}, controls={controls_y}" + ); + } + /// 接收页运行态(非专注模式)同样必须有防火墙入口。 #[test] fn receive_running_page_renders_the_firewall_panel() { diff --git a/scripts/android_compat_selftest.py b/scripts/android_compat_selftest.py index f9fd95b..adfab64 100644 --- a/scripts/android_compat_selftest.py +++ b/scripts/android_compat_selftest.py @@ -6,6 +6,7 @@ gradle=(ROOT/'android/app/build.gradle.kts').read_text(); manifest=(ROOT/'androi wifi=(ROOT/'android/app/src/main/java/com/qft/optical/WifiConnector.kt').read_text(); upload=(ROOT/'android/app/src/main/java/com/qft/optical/UploadClient.kt').read_text() download=(ROOT/'android/app/src/main/java/com/qft/optical/DownloadClient.kt').read_text() main=(ROOT/'android/app/src/main/java/com/qft/optical/MainActivity.kt').read_text(); analyzer=(ROOT/'android/app/src/main/java/com/qft/optical/QrAnalyzer.kt').read_text() +queue=(ROOT/'android/app/src/main/java/com/qft/optical/TransferQueue.kt').read_text() gray=(ROOT/'android/app/src/main/java/com/qft/optical/GrayFrame.kt').read_text(); protocol=(ROOT/'android/app/src/main/java/com/qft/optical/Protocol.kt').read_text(); base45=(ROOT/'android/app/src/main/java/com/qft/optical/Base45.kt').read_text(); overlay=(ROOT/'android/app/src/main/java/com/qft/optical/QrLockOverlay.kt').read_text(); security=(ROOT/'android/app/src/main/res/xml/network_security_config.xml').read_text() assert re.search(r'minSdk\s*=\s*24',gradle) assert 'WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"' in manifest @@ -15,7 +16,7 @@ assert 'Build.VERSION.SDK_INT >= 29' in wifi and 'connectLegacy' in wifi and 'su assert 'MAX_WORKERS = 8' in upload and 'QFTDISC2:' in upload assert 'MAX_WORKERS = 8' in download and 'bytes=$start-$end' in download and 'completionMapFile' in download assert 'requestNetwork(request, cb)' in wifi and 'delivered.set(false)' in wifi -assert 'val targetSize = Size(640, 480)' in main and 'Size(960, 540)' not in main +assert 'if (mode == ScannerMode.PAIR) Size(960, 720) else Size(640, 480)' in main and 'Size(960, 540)' not in main assert 'Camera2Interop.Extender' in main and 'CONTROL_AE_TARGET_FPS_RANGE' in main and 'STRATEGY_KEEP_ONLY_LATEST' in main assert '设备拒绝显式高帧率请求' in main and 'fallbackAnalysis' in main assert 'OPTICAL_LOCKED' in analyzer and 'OPTICAL_MULTI' not in analyzer and 'QRCodeReader' in analyzer and 'MultiFormatReader' not in analyzer @@ -24,7 +25,9 @@ assert 'GrayFrameBuffer' in gray and 'scratch = ByteArray(0)' in gray assert 'Base45.decode' in protocol and 'QFT2' in protocol and 'looksLikeBinaryFrame' not in protocol assert 'lockedCenterInView' in overlay and 'postInvalidateDelayed' in overlay and 'maybeRefocusLockedQr' in main assert 'assembler.acceptText(code.text)' in main and 'acceptBinary' not in main +assert 'showFileSelection' not in main and 'pickFiles.launch(arrayOf("*/*"))' in main +assert 'installFileQueueDrag' in main and 'uploadRunning' in main and 'moveQueueItem' in queue assert 'BB8' in base45 or 'ALPHABET' in base45 all_kotlin='\n'.join(path.read_text() for path in (ROOT/'android/app/src/main/java/com/qft/optical').glob('*.kt')) assert 'java.util.Base64' not in all_kotlin -print('PASS Android static guards: API24+, 640x480 single-QR ROI, reusable luma buffer, QFT2/Base45 text parse, dynamic lock/refocus, Camera2 FPS request, legacy/new Wi-Fi compatibility') +print('PASS Android static guards: API24+, fast-pair/640x480 optical ROI, inline sortable upload queue, QFT2/Base45, dynamic lock/refocus, legacy/new Wi-Fi compatibility') diff --git a/scripts/kotlin_host_smoke.py b/scripts/kotlin_host_smoke.py index 4d903fa..5032737 100644 --- a/scripts/kotlin_host_smoke.py +++ b/scripts/kotlin_host_smoke.py @@ -26,10 +26,10 @@ with tempfile.TemporaryDirectory() as td: import java.util.zip.CRC32 fun b45e(data: ByteArray): String { val a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; val o=StringBuilder(); var i=0; while(i+1