diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index 7e8c121..ffa4216 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -91,7 +91,7 @@ pub fn get_open_file_path(app_handle: tauri::AppHandle) -> Option { let open_file_path = config.core_cfg.current_file.clone(); return open_file_path.map(|p| p.to_string_lossy().into_owned()); } -pub fn set_open_file_path(app_handle: tauri::AppHandle, path: &String) { +pub fn set_open_file_path(app_handle: tauri::AppHandle, path: &str) { let mut config = app_handle.state::>(); // Lock the mutex to get mutable access: diff --git a/src-tauri/src/file_handler.rs b/src-tauri/src/file_handler.rs index 231785d..07c2d16 100644 --- a/src-tauri/src/file_handler.rs +++ b/src-tauri/src/file_handler.rs @@ -4,7 +4,7 @@ use crate::{ get_basepath, }; use diff_match_patch_rs::{Compat, DiffMatchPatch, Error, PatchInput}; -use std::fs::read_to_string; +use std::{fs::read_to_string, path::PathBuf}; use std::path::Path; use tauri::{ipc::RuntimeCapability, App, AssetResolver, Manager, Url}; @@ -22,17 +22,18 @@ fn compare_content(old_content: &str, new_content: &str) -> Result Result<(), String> { if let Some(path) = get_open_file_path(app_handle.clone()) { - if let Ok(file_content) = load_file(app_handle, path).await { - // store_diff(&app_handle, &path, file_name, diff); + if let Ok(file_content) = load_file(app_handle.clone(), &path).await { + store_diff(&app_handle, &path.clone(), &PathBuf::from(path).file_name().unwrap().to_string_lossy(), compare_content(&file_content, &content).map_err(|e| format!("{e:?}"))?); println!("{:?}", compare_content(&file_content, &content)); } } + Ok(()) } #[tauri::command] -pub async fn load_file(app_handle: tauri::AppHandle, path: String) -> Result { - set_open_file_path(app_handle, &path); +pub async fn load_file(app_handle: tauri::AppHandle, path: &str) -> Result { + set_open_file_path(app_handle, path); read_to_string(path).map_err(|e| e.to_string()) }