fix: Windows platform compilation errors

- Add conditional compilation for Unix-specific code in file_browser_service.rs
- Add missing imports for Windows-specific code in wsl_connection.rs
  - std::io::{Read, Write}
  - std::sync::Mutex
  - TerminalOutputEvent, TerminalStatusEvent, SessionStatus
  - BASE64 encoder

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
coso
2026-01-08 16:25:09 +08:00
co-authored by Claude Opus 4.5
parent 73c7906768
commit 64ba28a10c
2 changed files with 29 additions and 5 deletions
+15 -5
View File
@@ -11,6 +11,7 @@
use serde::{Deserialize, Serialize};
use std::fs::{self, Metadata};
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
@@ -93,6 +94,7 @@ fn is_hidden_file(name: &str) -> bool {
}
/// 将 Unix 文件模式转换为权限字符串(如 -rw-r--r--)
#[cfg(unix)]
fn mode_to_string(mode: u32, is_dir: bool, is_symlink: bool) -> String {
let mut result = String::with_capacity(10);
@@ -371,9 +373,17 @@ pub fn list_directory(path: &str) -> DirectoryListing {
get_file_extension(&path)
};
// 获取文件权限
let mode = metadata.permissions().mode();
let mode_str = mode_to_string(mode & 0o777, metadata.is_dir(), is_symlink);
// 获取文件权限(仅 Unix)
#[cfg(unix)]
let (mode, mode_str) = {
let m = metadata.permissions().mode();
(
Some(m & 0o777),
Some(mode_to_string(m & 0o777, metadata.is_dir(), is_symlink)),
)
};
#[cfg(not(unix))]
let (mode, mode_str): (Option<u32>, Option<String>) = (None, None);
// 获取 MIME 类型
let mime_type = get_mime_type(&path, &metadata);
@@ -386,8 +396,8 @@ pub fn list_directory(path: &str) -> DirectoryListing {
modified_at,
file_type,
is_hidden: is_hidden_file(&name),
mode_str: Some(mode_str),
mode: Some(mode & 0o777),
mode_str,
mode,
mime_type: Some(mime_type),
is_symlink,
})
@@ -18,6 +18,11 @@
use std::sync::atomic::{AtomicBool, AtomicI32, AtomicI64, Ordering};
use std::sync::Arc;
#[cfg(target_os = "windows")]
use std::io::{Read, Write};
#[cfg(target_os = "windows")]
use std::sync::Mutex;
use parking_lot::RwLock;
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc;
@@ -26,7 +31,16 @@ use crate::terminal::block_controller::{BlockInputUnion, BlockMeta};
use crate::terminal::connections::{ConnStatus, ConnectionState};
use crate::terminal::error::TerminalError;
use crate::terminal::events::event_names;
#[cfg(target_os = "windows")]
use crate::terminal::events::{TerminalOutputEvent, TerminalStatusEvent};
use crate::terminal::persistence::BlockFile;
#[cfg(target_os = "windows")]
use crate::terminal::SessionStatus;
#[cfg(target_os = "windows")]
use base64::engine::general_purpose::STANDARD as BASE64;
#[cfg(target_os = "windows")]
use base64::Engine;
/// WSL 连接前缀
pub const WSL_CONN_PREFIX: &str = "wsl://";