优化调整

This commit is contained in:
zhongluofeng
2026-08-14 17:47:06 +08:00
parent 6c7897bf47
commit 7d49a7395f
50 changed files with 2805 additions and 259 deletions
+25 -4
View File
@@ -20,6 +20,8 @@ use tauri::window::{Effect, EffectsBuilder};
use crate::win32_util::{get_cursor_pos, get_work_area_at_point, get_dpi_for_point};
use super::explorer;
use specta::Type;
/// 弹窗窗口标签
@@ -29,6 +31,24 @@ pub const POPUP_LABEL: &str = "quick-panel";
const WIN_W: f64 = 600.0;
const WIN_H: f64 = 420.0;
/// `quickpanel-show` 事件负载:携带快捷键按下时检测到的 Explorer 当前目录,
/// 前端据此渲染"当前目录"文件操作分组。
#[derive(Clone, Serialize)]
pub struct QuickPanelShowPayload {
pub dir: Option<String>,
}
/// 检测前台 Explorer 目录并连同 show 事件一起下发。
/// 必须在快捷键回调内调用:此时前台窗口仍是 Explorer,面板尚未抢焦点。
fn emit_show(app: &AppHandle) {
let dir = explorer::detect_explorer_folder();
crate::logger::log_info("quickpanel", &format!("show_popup: explorer_dir={:?}", dir));
let _ = app.emit(
crate::constants::events::QUICKPANEL_SHOW,
QuickPanelShowPayload { dir },
);
}
/// 标志:show_popup 兜底创建路径设为 true,前端 onMounted 回调 show_window 时据此判断是否显示。
/// 预创建路径不设置,避免应用启动时弹窗自动弹出。
static POPUP_PENDING_SHOW: AtomicBool = AtomicBool::new(false);
@@ -226,14 +246,15 @@ pub fn show_popup(app: &AppHandle) {
// 窗口已存在:移动 + 显示 + 请求焦点
if let Some(win) = app.get_webview_window(POPUP_LABEL) {
// 必须先于窗口显示/聚焦检测 Explorer 目录:show/set_focus 会立即抢走前台焦点,
// 之后调用 GetForegroundWindow 拿到的就是面板自身了。
emit_show(app);
let _ = win.set_position(tauri::Position::Physical(tauri::PhysicalPosition {
x: x as i32,
y: y as i32,
}));
let _ = win.show();
let _ = win.set_focus();
// 通知前端刷新数据
let _ = app.emit(crate::constants::events::QUICKPANEL_SHOW, ());
return;
}
@@ -261,10 +282,10 @@ pub fn show_window(app: &AppHandle) {
y: y as i32,
}));
}
// 同样先检测 Explorer 目录再显示,避免面板抢焦点导致检测失败。
emit_show(app);
let _ = win.show();
let _ = win.set_focus();
// 通知前端刷新数据
let _ = app.emit(crate::constants::events::QUICKPANEL_SHOW, ());
}
}