feat(tauri): 添加文件修改时间查询命令
- 新增 get_file_mtime 命令 - 支持检测文件外部修改
This commit is contained in:
@@ -254,6 +254,25 @@ pub fn read_file_as_base64(file_path: String) -> Result<String, String> {
|
|||||||
Ok(general_purpose::STANDARD.encode(&file_content))
|
Ok(general_purpose::STANDARD.encode(&file_content))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get file modification time (milliseconds since UNIX epoch)
|
||||||
|
/// 获取文件修改时间(Unix 纪元以来的毫秒数)
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn get_file_mtime(path: String) -> Result<u64, String> {
|
||||||
|
let metadata = fs::metadata(&path)
|
||||||
|
.map_err(|e| format!("Failed to get metadata for {}: {}", path, e))?;
|
||||||
|
|
||||||
|
let modified = metadata
|
||||||
|
.modified()
|
||||||
|
.map_err(|e| format!("Failed to get modified time for {}: {}", path, e))?;
|
||||||
|
|
||||||
|
let millis = modified
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.map_err(|e| format!("Time error: {}", e))?
|
||||||
|
.as_millis() as u64;
|
||||||
|
|
||||||
|
Ok(millis)
|
||||||
|
}
|
||||||
|
|
||||||
/// Copy file from source to destination
|
/// Copy file from source to destination
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn copy_file(src: String, dst: String) -> Result<(), String> {
|
pub fn copy_file(src: String, dst: String) -> Result<(), String> {
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ fn main() {
|
|||||||
commands::scan_directory,
|
commands::scan_directory,
|
||||||
commands::read_file_as_base64,
|
commands::read_file_as_base64,
|
||||||
commands::copy_file,
|
commands::copy_file,
|
||||||
|
commands::get_file_mtime,
|
||||||
// Dialog operations
|
// Dialog operations
|
||||||
commands::open_folder_dialog,
|
commands::open_folder_dialog,
|
||||||
commands::open_file_dialog,
|
commands::open_file_dialog,
|
||||||
@@ -183,18 +184,27 @@ fn handle_project_protocol(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get MIME type based on file extension
|
/// Get MIME type based on file extension
|
||||||
|
/// 根据文件扩展名获取 MIME 类型
|
||||||
fn get_mime_type(file_path: &str) -> &'static str {
|
fn get_mime_type(file_path: &str) -> &'static str {
|
||||||
if file_path.ends_with(".ts") || file_path.ends_with(".tsx") {
|
if file_path.ends_with(".ts") || file_path.ends_with(".tsx") {
|
||||||
"application/javascript"
|
"application/javascript"
|
||||||
} else if file_path.ends_with(".js") {
|
} else if file_path.ends_with(".js") || file_path.ends_with(".mjs") {
|
||||||
"application/javascript"
|
"application/javascript"
|
||||||
} else if file_path.ends_with(".json") {
|
} else if file_path.ends_with(".json") {
|
||||||
"application/json"
|
"application/json"
|
||||||
|
} else if file_path.ends_with(".wasm") {
|
||||||
|
"application/wasm"
|
||||||
} else if file_path.ends_with(".css") {
|
} else if file_path.ends_with(".css") {
|
||||||
"text/css"
|
"text/css"
|
||||||
} else if file_path.ends_with(".html") {
|
} else if file_path.ends_with(".html") {
|
||||||
"text/html"
|
"text/html"
|
||||||
|
} else if file_path.ends_with(".png") {
|
||||||
|
"image/png"
|
||||||
|
} else if file_path.ends_with(".jpg") || file_path.ends_with(".jpeg") {
|
||||||
|
"image/jpeg"
|
||||||
|
} else if file_path.ends_with(".svg") {
|
||||||
|
"image/svg+xml"
|
||||||
} else {
|
} else {
|
||||||
"text/plain"
|
"application/octet-stream"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,8 @@
|
|||||||
{
|
{
|
||||||
"identifier": "main",
|
"identifier": "main",
|
||||||
"windows": [
|
"windows": [
|
||||||
"main"
|
"main",
|
||||||
|
"frame-debugger"
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"core:default",
|
"core:default",
|
||||||
@@ -91,6 +92,9 @@
|
|||||||
"core:window:allow-toggle-maximize",
|
"core:window:allow-toggle-maximize",
|
||||||
"core:window:allow-close",
|
"core:window:allow-close",
|
||||||
"core:window:allow-is-maximized",
|
"core:window:allow-is-maximized",
|
||||||
|
"core:window:allow-create",
|
||||||
|
"core:webview:allow-create-webview",
|
||||||
|
"core:webview:allow-create-webview-window",
|
||||||
"shell:default",
|
"shell:default",
|
||||||
"dialog:default",
|
"dialog:default",
|
||||||
"updater:default",
|
"updater:default",
|
||||||
|
|||||||
Reference in New Issue
Block a user