mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-20 08:34:18 +01:00
Better Windows pathing
This commit is contained in:
8
src-tauri/Cargo.lock
generated
8
src-tauri/Cargo.lock
generated
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("yaak_plugin_runtime")
|
||||
.setup(|app, _| {
|
||||
@@ -105,12 +103,34 @@ async fn read_plugins_dir(dir: &PathBuf) -> Result<Vec<String>> {
|
||||
let mut dirs: Vec<String> = 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user