summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrendan Allan <[email protected]>2026-02-27 14:17:24 +0800
committerGitHub <[email protected]>2026-02-27 06:17:24 +0000
commit0da8af8a28658d155646725a4b1190cb7bd15784 (patch)
tree96f95c3c52cc12a26e298c0a09c283de8a91fa40
parent2a4ed495515ff6470f08e628350d4fe55272f4d3 (diff)
downloadopencode-0da8af8a28658d155646725a4b1190cb7bd15784.tar.gz
opencode-0da8af8a28658d155646725a4b1190cb7bd15784.zip
desktop: move open_path to rust (#15323)
-rw-r--r--packages/desktop/src-tauri/src/lib.rs25
-rw-r--r--packages/desktop/src/bindings.ts2
-rw-r--r--packages/desktop/src/index.tsx25
3 files changed, 23 insertions, 29 deletions
diff --git a/packages/desktop/src-tauri/src/lib.rs b/packages/desktop/src-tauri/src/lib.rs
index 879732121..137692cdf 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.ts
index 8e1b4127a..80548173e 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.tsx
index 188a37eb8..17b4638bd 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() {