From d4e7a8b4feca436ae480af1a9b7fb7abb6549a6c Mon Sep 17 00:00:00 2001 From: baiqing Date: Sat, 2 May 2026 11:38:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(windows):=20QA=20=E6=B5=AE=E7=AA=97?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=97=B6=E4=B8=8D=E5=86=8D=E6=8A=A2=E5=89=8D?= =?UTF-8?q?=E5=8F=B0=E7=84=A6=E7=82=B9=20(closes=20#164)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openless-all/app/src-tauri/Cargo.toml | 1 + openless-all/app/src-tauri/src/lib.rs | 46 ++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/openless-all/app/src-tauri/Cargo.toml b/openless-all/app/src-tauri/Cargo.toml index d93315c8..6a69b47a 100644 --- a/openless-all/app/src-tauri/Cargo.toml +++ b/openless-all/app/src-tauri/Cargo.toml @@ -35,6 +35,7 @@ uuid = { version = "1", features = ["v4", "serde"] } chrono = { version = "0.4", features = ["serde"] } bytes = "1" url = "2" +raw-window-handle = "0.6" # Hotkey + audio + insertion global-hotkey = "0.6" diff --git a/openless-all/app/src-tauri/src/lib.rs b/openless-all/app/src-tauri/src/lib.rs index 12056a11..2baeddd3 100644 --- a/openless-all/app/src-tauri/src/lib.rs +++ b/openless-all/app/src-tauri/src/lib.rs @@ -514,7 +514,16 @@ pub(crate) fn show_qa_window(app: &AppHandle, content_kind } }); } - #[cfg(not(target_os = "macos"))] + #[cfg(target_os = "windows")] + { + if !show_qa_window_no_activate(&window) { + log::warn!("[qa] show_no_activate failed; falling back to window.show()"); + if let Err(e) = window.show() { + log::warn!("[qa] show fallback failed: {e}"); + } + } + } + #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))] if let Err(e) = window.show() { log::warn!("[qa] show failed: {e}"); } @@ -560,6 +569,41 @@ pub(crate) fn hide_qa_window(app: &AppHandle) { } } +#[cfg(target_os = "windows")] +fn show_qa_window_no_activate(window: &tauri::WebviewWindow) -> bool { + use raw_window_handle::{HasWindowHandle, RawWindowHandle}; + use windows::Win32::Foundation::HWND; + use windows::Win32::UI::WindowsAndMessaging::{ + SetWindowPos, ShowWindow, HWND_TOPMOST, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOSIZE, + SWP_SHOWWINDOW, SW_SHOWNOACTIVATE, + }; + + let Ok(handle) = window.window_handle() else { + return false; + }; + let RawWindowHandle::Win32(raw) = handle.as_raw() else { + return false; + }; + let hwnd = HWND(raw.hwnd.get() as *mut _); + if hwnd.0.is_null() { + return false; + } + + let _ = unsafe { ShowWindow(hwnd, SW_SHOWNOACTIVATE) }; + let _ = unsafe { + SetWindowPos( + hwnd, + HWND_TOPMOST, + 0, + 0, + 0, + 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE, + ) + }; + true +} + /// 把 capsule 窗口移到屏幕底部居中,与 Swift `CapsuleWindowController.repositionToBottomCenter` 同效。 /// 留 80pt 给 macOS Dock;Windows 任务栏一般在底部 48pt 以内,整体也合适。 pub(crate) fn position_capsule_bottom_center( From 6a915c762fb7b7fda2d97731a672ceff162b3255 Mon Sep 17 00:00:00 2001 From: baiqing Date: Sat, 2 May 2026 11:40:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore(windows):=20=E8=A1=A5=E9=BD=90=20QA?= =?UTF-8?q?=20no-activate=20=E4=BE=9D=E8=B5=96=E9=94=81=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openless-all/app/src-tauri/Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/openless-all/app/src-tauri/Cargo.lock b/openless-all/app/src-tauri/Cargo.lock index 19efbbef..60ac8b5c 100644 --- a/openless-all/app/src-tauri/Cargo.lock +++ b/openless-all/app/src-tauri/Cargo.lock @@ -3270,6 +3270,7 @@ dependencies = [ "objc2-foundation 0.2.2", "once_cell", "parking_lot", + "raw-window-handle", "rdev", "reqwest 0.12.28", "serde",