diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index f24b6e97..59c41e20 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3623,6 +3623,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "path-slash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" + [[package]] name = "pathdiff" version = "0.2.1" @@ -7628,8 +7634,10 @@ dependencies = [ "command-group", "dunce", "log", + "path-slash", "prost 0.13.1", "rand 0.8.5", + "regex", "reqwest", "serde", "serde_json", diff --git a/src-tauri/yaak_plugin_runtime/Cargo.toml b/src-tauri/yaak_plugin_runtime/Cargo.toml index 9be8ad7f..e4ea9309 100644 --- a/src-tauri/yaak_plugin_runtime/Cargo.toml +++ b/src-tauri/yaak_plugin_runtime/Cargo.toml @@ -20,6 +20,8 @@ tonic = "0.12.1" ts-rs = "9.0.1" thiserror = "1.0.63" yaak_models = {workspace = true} +regex = "1.10.6" +path-slash = "0.2.1" [build-dependencies] tonic-build = "0.12.1" diff --git a/src-tauri/yaak_plugin_runtime/src/plugin.rs b/src-tauri/yaak_plugin_runtime/src/plugin.rs index 2aa271ce..1b31128e 100644 --- a/src-tauri/yaak_plugin_runtime/src/plugin.rs +++ b/src-tauri/yaak_plugin_runtime/src/plugin.rs @@ -1,9 +1,13 @@ +use crate::error::Result; +use crate::events::{InternalEvent, InternalEventPayload}; +use crate::manager::PluginManager; +use crate::server::plugin_runtime::plugin_runtime_server::PluginRuntimeServer; +use crate::server::PluginRuntimeGrpcServer; +use log::info; use std::net::SocketAddr; use std::path::PathBuf; use std::process::exit; use std::time::Duration; - -use log::info; use tauri::path::BaseDirectory; use tauri::plugin::{Builder, TauriPlugin}; use tauri::{Manager, RunEvent, Runtime, State}; @@ -13,12 +17,6 @@ use tokio::sync::Mutex; use tonic::codegen::tokio_stream; use tonic::transport::Server; -use crate::error::Result; -use crate::events::{InternalEvent, InternalEventPayload}; -use crate::manager::PluginManager; -use crate::server::plugin_runtime::plugin_runtime_server::PluginRuntimeServer; -use crate::server::PluginRuntimeGrpcServer; - pub fn init() -> TauriPlugin { Builder::new("yaak_plugin_runtime") .setup(|app, _| { @@ -105,12 +103,34 @@ async fn read_plugins_dir(dir: &PathBuf) -> Result> { let mut dirs: Vec = vec![]; while let Ok(Some(entry)) = result.next_entry().await { if entry.path().is_dir() { - // HACK: Remove UNC prefix for Windows paths to pass to sidecar - let safe_path = dunce::simplified(entry.path().as_path()) - .to_string_lossy() - .to_string(); - dirs.push(safe_path) + #[cfg(target_os = "windows")] + dirs.push(fix_windows_paths(&entry.path())); + #[cfg(not(target_os = "windows"))] + dirs.push(entry.path().to_string_lossy().to_string()); } } Ok(dirs) } + + +#[cfg(target_os = "windows")] +fn fix_windows_paths(p: &PathBuf) -> String { + use dunce; + use regex::Regex; + use path_slash::PathBufExt; + + // 1. Remove UNC prefix for Windows paths to pass to sidecar + let safe_path = dunce::simplified(p.as_path()).to_string_lossy().to_string(); + + // 2. Remove the drive letter + let safe_path = Regex::new("^[a-zA-Z]:") + .unwrap() + .replace(safe_path.as_str(), ""); + + // 3. Convert backslashes to forward + let safe_path = PathBuf::from(safe_path.to_string()) + .to_slash_lossy() + .to_string(); + + safe_path +}