fix(app): open in powershell (#15112)
This commit is contained in:
@@ -179,6 +179,18 @@ fn resolve_app_path(app_name: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
fn open_in_powershell(path: String) -> Result<(), String> {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
return os::windows::open_in_powershell(path);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
Err("PowerShell is only supported on Windows".to_string())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn check_macos_app(app_name: &str) -> bool {
|
||||
// Check common installation locations
|
||||
@@ -373,7 +385,8 @@ fn make_specta_builder() -> tauri_specta::Builder<tauri::Wry> {
|
||||
markdown::parse_markdown_command,
|
||||
check_app_exists,
|
||||
wsl_path,
|
||||
resolve_app_path
|
||||
resolve_app_path,
|
||||
open_in_powershell
|
||||
])
|
||||
.events(tauri_specta::collect_events![
|
||||
LoadingWindowComplete,
|
||||
|
||||
@@ -6,9 +6,12 @@ use std::{
|
||||
};
|
||||
use windows_sys::Win32::{
|
||||
Foundation::ERROR_SUCCESS,
|
||||
System::Registry::{
|
||||
HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, REG_EXPAND_SZ, REG_SZ, RRF_RT_REG_EXPAND_SZ,
|
||||
RRF_RT_REG_SZ, RegGetValueW,
|
||||
System::{
|
||||
Registry::{
|
||||
RegGetValueW, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, REG_EXPAND_SZ, REG_SZ,
|
||||
RRF_RT_REG_EXPAND_SZ, RRF_RT_REG_SZ,
|
||||
},
|
||||
Threading::{CREATE_NEW_CONSOLE, CREATE_NO_WINDOW},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -310,7 +313,7 @@ pub fn resolve_windows_app_path(app_name: &str) -> Option<String> {
|
||||
|
||||
let resolve_where = |query: &str| -> Option<String> {
|
||||
let output = Command::new("where")
|
||||
.creation_flags(0x08000000)
|
||||
.creation_flags(CREATE_NO_WINDOW)
|
||||
.arg(query)
|
||||
.output()
|
||||
.ok()?;
|
||||
@@ -437,3 +440,24 @@ pub fn resolve_windows_app_path(app_name: &str) -> Option<String> {
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn open_in_powershell(path: String) -> Result<(), String> {
|
||||
let path = PathBuf::from(path);
|
||||
let dir = if path.is_dir() {
|
||||
path
|
||||
} else if let Some(parent) = path.parent() {
|
||||
parent.to_path_buf()
|
||||
} else {
|
||||
std::env::current_dir()
|
||||
.map_err(|e| format!("Failed to determine current directory: {e}"))?
|
||||
};
|
||||
|
||||
Command::new("powershell.exe")
|
||||
.creation_flags(CREATE_NEW_CONSOLE)
|
||||
.current_dir(dir)
|
||||
.args(["-NoExit"])
|
||||
.spawn()
|
||||
.map_err(|e| format!("Failed to start PowerShell: {e}"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user