快速面板模块
This commit is contained in:
@@ -188,62 +188,32 @@ pub fn quickpanel_reveal_in_explorer(path: String) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 用系统默认程序打开文件(ShellExecuteW)。
|
||||
/// 无关联应用时,自动 fallback 到「打开方式」对话框(verb: openas)。
|
||||
/// 用系统默认程序打开文件/文件夹。
|
||||
/// - 目录:explorer.exe 直接打开(修复索引目录点击后未打开的问题)
|
||||
/// - 文件:ShellExecuteW open,无关联应用时自动 fallback 到「打开方式」对话框(verb: openas)
|
||||
#[tauri::command]
|
||||
pub fn quickpanel_open_file(path: String) -> Result<(), String> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use std::ffi::OsStr;
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use windows_sys::Win32::Foundation::HWND;
|
||||
use windows_sys::Win32::UI::Shell::ShellExecuteW;
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::SW_SHOWNORMAL;
|
||||
super::special_locations::open_path(&path)
|
||||
}
|
||||
|
||||
let normalized = path.replace('/', "\\");
|
||||
let wide_path: Vec<u16> = OsStr::new(&normalized)
|
||||
.encode_wide()
|
||||
.chain(std::iter::once(0))
|
||||
.collect();
|
||||
let wide_open: Vec<u16> = OsStr::new("open")
|
||||
.encode_wide()
|
||||
.chain(std::iter::once(0))
|
||||
.collect();
|
||||
let wide_openas: Vec<u16> = OsStr::new("openas")
|
||||
.encode_wide()
|
||||
.chain(std::iter::once(0))
|
||||
.collect();
|
||||
/// 获取 Windows 常用快捷位置(hosts、回收站、此电脑、用户目录、系统管理工具等)
|
||||
#[tauri::command]
|
||||
pub fn quickpanel_get_special_locations() -> Vec<super::special_locations::SpecialLocation> {
|
||||
super::special_locations::get_special_locations()
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let mut hinst = ShellExecuteW(
|
||||
0 as HWND,
|
||||
wide_open.as_ptr(),
|
||||
wide_path.as_ptr(),
|
||||
std::ptr::null(),
|
||||
std::ptr::null(),
|
||||
SW_SHOWNORMAL,
|
||||
);
|
||||
if hinst <= 32 {
|
||||
hinst = ShellExecuteW(
|
||||
0 as HWND,
|
||||
wide_openas.as_ptr(),
|
||||
wide_path.as_ptr(),
|
||||
std::ptr::null(),
|
||||
std::ptr::null(),
|
||||
SW_SHOWNORMAL,
|
||||
);
|
||||
if hinst <= 32 {
|
||||
return Err(format!("打开文件失败 (code: {})", hinst as i32));
|
||||
}
|
||||
}
|
||||
}
|
||||
/// 打开快捷位置(kind: file | shell | cmd)
|
||||
#[tauri::command]
|
||||
pub fn quickpanel_open_special(
|
||||
kind: String,
|
||||
target: String,
|
||||
args: Vec<String>,
|
||||
) -> Result<(), String> {
|
||||
match kind.as_str() {
|
||||
"shell" => super::special_locations::open_shell(&target),
|
||||
"cmd" => super::special_locations::open_cmd(&target, &args),
|
||||
_ => super::special_locations::open_path(&target),
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let _ = path;
|
||||
return Err(String::from("当前平台不支持"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 删除文件(移到回收站)
|
||||
|
||||
Reference in New Issue
Block a user