GeezerVison is showing github.com — desktop: move open_path to rust (#15323) · dotneB/opencode@0da8af8
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src-tauri/src/lib.rs +21-4Lines changed: 21 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -181,14 +181,31 @@ fn resolve_app_path(app_name: &str) -> Option<String> { | 181 | 181 |
| 182 | 182 | #[tauri::command] | 183 | 183 | #[specta::specta] | 184 | | -fn open_in_powershell(path: String) -> Result<(), String> { | | 184 | +fn open_path(_app: AppHandle, path: String, app_name: Option<String>) -> Result<(), String> { | 185 | 185 | #[cfg(target_os = "windows")] | 186 | 186 | { | 187 | | - return os::windows::open_in_powershell(path); | | 187 | + let app_name = app_name.map(|v| os::windows::resolve_windows_app_path(&v).unwrap_or(v)); | | 188 | + let is_powershell = app_name.as_ref().is_some_and(|v| { | | 189 | + std::path::Path::new(v) | | 190 | + .file_name() | | 191 | + .and_then(|name| name.to_str()) | | 192 | + .is_some_and(|name| { | | 193 | + name.eq_ignore_ascii_case("powershell") | | 194 | + || name.eq_ignore_ascii_case("powershell.exe") | | 195 | + }) | | 196 | + }); | | 197 | + | | 198 | + if is_powershell { | | 199 | + return os::windows::open_in_powershell(path); | | 200 | + } | | 201 | + | | 202 | + return tauri_plugin_opener::open_path(path, app_name.as_deref()) | | 203 | + .map_err(|e| format!("Failed to open path: {e}")); | 188 | 204 | } | 189 | 205 |
| 190 | 206 | #[cfg(not(target_os = "windows"))] | 191 | | - Err("PowerShell is only supported on Windows".to_string()) | | 207 | + tauri_plugin_opener::open_path(path, app_name.as_deref()) | | 208 | + .map_err(|e| format!("Failed to open path: {e}")) | 192 | 209 | } | 193 | 210 |
| 194 | 211 | #[cfg(target_os = "macos")] | @@ -386,7 +403,7 @@ fn make_specta_builder() -> tauri_specta::Builder<tauri::Wry> { | 386 | 403 | check_app_exists, | 387 | 404 | wsl_path, | 388 | 405 | resolve_app_path, | 389 | | - open_in_powershell | | 406 | + open_path | 390 | 407 | ]) | 391 | 408 | .events(tauri_specta::collect_events![ | 392 | 409 | LoadingWindowComplete, | |
Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src/bindings.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,7 @@ export const commands = { | 18 | 18 | checkAppExists: (appName: string) => __TAURI_INVOKE<boolean>("check_app_exists", { appName }), | 19 | 19 | wslPath: (path: string, mode: "windows" | "linux" | null) => __TAURI_INVOKE<string>("wsl_path", { path, mode }), | 20 | 20 | resolveAppPath: (appName: string) => __TAURI_INVOKE<string | null>("resolve_app_path", { appName }), | 21 | | - openInPowershell: (path: string) => __TAURI_INVOKE<null>("open_in_powershell", { path }), | | 21 | + openPath: (path: string, appName: string | null) => __TAURI_INVOKE<null>("open_path", { path, appName }), | 22 | 22 | }; | 23 | 23 |
| 24 | 24 | /** Events */ | |
Collapse file Copy file name to clipboardExpand all lines: packages/desktop/src/index.tsx +1-24Lines changed: 1 addition & 24 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,6 @@ import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link" | 17 | 17 | import { open, save } from "@tauri-apps/plugin-dialog" | 18 | 18 | import { fetch as tauriFetch } from "@tauri-apps/plugin-http" | 19 | 19 | import { isPermissionGranted, requestPermission } from "@tauri-apps/plugin-notification" | 20 | | -import { openPath as openerOpenPath } from "@tauri-apps/plugin-opener" | 21 | 20 | import { type as ostype } from "@tauri-apps/plugin-os" | 22 | 21 | import { relaunch } from "@tauri-apps/plugin-process" | 23 | 22 | import { open as shellOpen } from "@tauri-apps/plugin-shell" | @@ -116,29 +115,7 @@ const createPlatform = (): Platform => { | 116 | 115 | void shellOpen(url).catch(() => undefined) | 117 | 116 | }, | 118 | 117 | async openPath(path: string, app?: string) { | 119 | | - const os = ostype() | 120 | | - if (os === "windows") { | 121 | | - const resolvedPath = await (async () => { | 122 | | - if (window.__OPENCODE__?.wsl) { | 123 | | - const converted = await commands.wslPath(path, "windows").catch(() => null) | 124 | | - if (converted) return converted | 125 | | - } | 126 | | - | 127 | | - return path | 128 | | - })() | 129 | | - const resolvedApp = (app && (await commands.resolveAppPath(app))) || app | 130 | | - const isPowershell = (value?: string) => { | 131 | | - if (!value) return false | 132 | | - const name = value.toLowerCase().replaceAll("/", "\\").split("\\").pop() | 133 | | - return name === "powershell" || name === "powershell.exe" | 134 | | - } | 135 | | - if (isPowershell(resolvedApp)) { | 136 | | - await commands.openInPowershell(resolvedPath) | 137 | | - return | 138 | | - } | 139 | | - return openerOpenPath(resolvedPath, resolvedApp) | 140 | | - } | 141 | | - return openerOpenPath(path, app) | | 118 | + await commands.openPath(path, app ?? null) | 142 | 119 | }, | 143 | 120 |
| 144 | 121 | back() { | |
|