The open source coding agent.
TypeScript
desktop: move open_path to rust (#15323)
Brendan Allan0da8af8a2865
diff --git a/packages/desktop/src-tauri/src/lib.rs b/packages/desktop/src-tauri/src/lib.rsindex 87973212147..137692cdf73 100644--- a/packages/desktop/src-tauri/src/lib.rs+++ b/packages/desktop/src-tauri/src/lib.rs@@ -181,14 +181,31 @@ fn resolve_app_path(app_name: &str) -> Option<String> {#[tauri::command]#[specta::specta]-fn open_in_powershell(path: String) -> Result<(), String> {+fn open_path(_app: AppHandle, path: String, app_name: Option<String>) -> Result<(), String> {#[cfg(target_os = "windows")]{- return os::windows::open_in_powershell(path);+ let app_name = app_name.map(|v| os::windows::resolve_windows_app_path(&v).unwrap_or(v));+ let is_powershell = app_name.as_ref().is_some_and(|v| {+ std::path::Path::new(v)+ .file_name()+ .and_then(|name| name.to_str())+ .is_some_and(|name| {+ name.eq_ignore_ascii_case("powershell")+ || name.eq_ignore_ascii_case("powershell.exe")+ })+ });++ if is_powershell {+ return os::windows::open_in_powershell(path);+ }++ return tauri_plugin_opener::open_path(path, app_name.as_deref())+ .map_err(|e| format!("Failed to open path: {e}"));}#[cfg(not(target_os = "windows"))]- Err("PowerShell is only supported on Windows".to_string())+ tauri_plugin_opener::open_path(path, app_name.as_deref())+ .map_err(|e| format!("Failed to open path: {e}"))}#[cfg(target_os = "macos")]@@ -386,7 +403,7 @@ fn make_specta_builder() -> tauri_specta::Builder<tauri::Wry> {check_app_exists,wsl_path,resolve_app_path,- open_in_powershell+ open_path]).events(tauri_specta::collect_events![LoadingWindowComplete,diff --git a/packages/desktop/src/bindings.ts b/packages/desktop/src/bindings.tsindex 8e1b4127a54..80548173e92 100644--- a/packages/desktop/src/bindings.ts+++ b/packages/desktop/src/bindings.ts@@ -18,7 +18,7 @@ export const commands = {checkAppExists: (appName: string) => __TAURI_INVOKE<boolean>("check_app_exists", { appName }),wslPath: (path: string, mode: "windows" | "linux" | null) => __TAURI_INVOKE<string>("wsl_path", { path, mode }),resolveAppPath: (appName: string) => __TAURI_INVOKE<string | null>("resolve_app_path", { appName }),- openInPowershell: (path: string) => __TAURI_INVOKE<null>("open_in_powershell", { path }),+ openPath: (path: string, appName: string | null) => __TAURI_INVOKE<null>("open_path", { path, appName }),};/** Events */diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsxindex 188a37eb87d..17b4638bd14 100644--- a/packages/desktop/src/index.tsx+++ b/packages/desktop/src/index.tsx@@ -17,7 +17,6 @@ import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link"import { open, save } from "@tauri-apps/plugin-dialog"import { fetch as tauriFetch } from "@tauri-apps/plugin-http"import { isPermissionGranted, requestPermission } from "@tauri-apps/plugin-notification"-import { openPath as openerOpenPath } from "@tauri-apps/plugin-opener"import { type as ostype } from "@tauri-apps/plugin-os"import { relaunch } from "@tauri-apps/plugin-process"import { open as shellOpen } from "@tauri-apps/plugin-shell"@@ -116,29 +115,7 @@ const createPlatform = (): Platform => {void shellOpen(url).catch(() => undefined)},async openPath(path: string, app?: string) {- const os = ostype()- if (os === "windows") {- const resolvedPath = await (async () => {- if (window.__OPENCODE__?.wsl) {- const converted = await commands.wslPath(path, "windows").catch(() => null)- if (converted) return converted- }-- return path- })()- const resolvedApp = (app && (await commands.resolveAppPath(app))) || app- const isPowershell = (value?: string) => {- if (!value) return false- const name = value.toLowerCase().replaceAll("/", "\\").split("\\").pop()- return name === "powershell" || name === "powershell.exe"- }- if (isPowershell(resolvedApp)) {- await commands.openInPowershell(resolvedPath)- return- }- return openerOpenPath(resolvedPath, resolvedApp)- }- return openerOpenPath(path, app)+ await commands.openPath(path, app ?? null)},back() {