From 17a155e9d29b0a5799b28d2dcd1c3cb9d289cb3b Mon Sep 17 00:00:00 2001 From: Werner <52450442+GoldenWRaft@users.noreply.github.com> Date: Sat, 25 May 2024 14:27:00 +0200 Subject: [PATCH 1/7] Bug fixes. --- src-tauri/src/main.rs | 35 +++++++++++++++++++++++++++-------- src/gateway.js | 3 ++- src/main.js | 10 +++++++++- src/utils.js | 7 +++---- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 00cb79d..8b55307 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -27,8 +27,7 @@ struct Child { } lazy_static! { - static ref PATH: Mutex = - Mutex::new("C:/Users/User/Documents/GitHub/text-editor/Folder".to_string()); + static ref PATH: Mutex = Mutex::new("%USERPROFILE%/Desktop".to_string()); } #[tauri::command] @@ -72,15 +71,19 @@ fn save_config() { #[tauri::command] fn delete_file(path: String) -> u8 { - delete_child(&path.replace(".md", "")); + update_opened(path.clone(), false); let path = PathBuf::from(PATH.lock().unwrap().clone()).join(path); - let _ = fs::remove_file(&path); + if path.to_str().unwrap().contains("Untitled") { + let _ = fs::remove_file(&path).unwrap_or_else(|error| { + println!("Failed to remove file: {:?}", error); + }); - println!("Removed file: {:?}", path); - - return 0; + return 0; + } else { + return 1; + } } #[tauri::command] @@ -193,6 +196,8 @@ fn get_theme() -> String { #[tauri::command] fn delete_child(path: &str) { + delete_file(format!("{}.md", path)); + let json_path: PathBuf = PathBuf::from(PATH.lock().unwrap().clone()).join("config.json"); let contents = fs::read_to_string(&json_path).expect("Failed to read configuration."); @@ -271,6 +276,7 @@ fn update_opened(path: String, add: bool) -> Value { let mut json_contents: Value = serde_json::from_str(&contents).expect("Failed to parse JSON"); let mut opened = json_contents["opened"].clone(); + let mut children = json_contents["children"].clone(); if add { let id = &Value::String(child_id.clone()); @@ -286,11 +292,20 @@ fn update_opened(path: String, add: bool) -> Value { } } else { if let Some(array) = opened.as_array_mut() { - array.retain(|x| x.as_str() != Some(&child_id)); + array.retain(|x| { + return x.as_str() != Some(&child_id); + }); + } + + if let Some(child_array) = children.as_array_mut() { + child_array.retain(|x| { + return x["id"].as_str() != Some(&child_id); + }); } } json_contents["opened"] = opened.clone(); + json_contents["children"] = children.clone(); // Serialize the modified JSON back to a string let updated_json = @@ -318,6 +333,10 @@ fn save_title(old_path: String, new_path: String) { let old_path_buf = PathBuf::from(PATH.lock().unwrap().clone()).join(&old_path); let new_path_buf = PathBuf::from(PATH.lock().unwrap().clone()).join(&new_path); + if old_path == new_path { + return; + } + let path = PathBuf::from(PATH.lock().unwrap().clone()).join("config.json"); let contents = String::from_utf8_lossy(&fs::read(&path).expect("Failed to read configuration.")) diff --git a/src/gateway.js b/src/gateway.js index 74921ec..9aa4bac 100644 --- a/src/gateway.js +++ b/src/gateway.js @@ -76,7 +76,8 @@ async function ask_for_file() { const result = await tauri.dialog.open({ title: "Choose a file to open.", multiple: false, - defaultPath: 'C:/Users/User/Documents/GitHub/text-editor/Folder/', + // Not working + //defaultPath: 'C:/Users/User/Documents/GitHub/text-editor/Folder/', filters: [ { name: 'Markdown', diff --git a/src/main.js b/src/main.js index 226a532..c73e3ad 100644 --- a/src/main.js +++ b/src/main.js @@ -175,7 +175,15 @@ $("body").keydown(async (e) => { if (content === "Switch file") { handleCommandPrompt(content, 1); // default to switch to 1st tab - } else handleCommandPrompt(content); + } + else if (content === "Open file") { + const arg = await ask_for_file(); + handleCommandPrompt(content, arg); + } + else handleCommandPrompt(content); + + animateDiv(true, popup); // force exit command pallet + animateDiv(true, $("#cssStyling")); // force exit themes } }); diff --git a/src/utils.js b/src/utils.js index 5a888b6..57c7ae7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -70,6 +70,7 @@ async function manage_new_file() { window.path = info[0]; let tabs_ = await get_tabs(); + await manage_tabs(tabs_); update_active(tabs_.length); } @@ -133,12 +134,10 @@ function update_words(content) { async function handle_open_file(path) { if (!path) return; - path = path.split('\\'); - path = path[path.length - 1]; - let info = await open_file(path); - window.title.val(info[0]); + let extracted_title = info[0].split('\\'); + window.title.val(extracted_title[extracted_title.length - 1]); window.editor.setData(info[1]); window.path = info[0]; From 0e47695acffaff99ebf9ab9b1aae69ade6446d1c Mon Sep 17 00:00:00 2001 From: Werner <52450442+GoldenWRaft@users.noreply.github.com> Date: Sat, 25 May 2024 15:56:51 +0200 Subject: [PATCH 2/7] Offline Version --- package-lock.json | 4 ++-- src/index.html | 11 +++++------ src/jquery-3.7.1.min.js | 2 ++ src/popper.min.js | 6 ++++++ src/tippy-bundle.umd.min.js | 2 ++ src/toastify-js.js | 15 +++++++++++++++ 6 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 src/jquery-3.7.1.min.js create mode 100644 src/popper.min.js create mode 100644 src/tippy-bundle.umd.min.js create mode 100644 src/toastify-js.js diff --git a/package-lock.json b/package-lock.json index dcd1ecc..4c18d2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "texteditor", - "version": "1.0.4", + "version": "1.1.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "texteditor", - "version": "1.0.4", + "version": "1.1.4", "dependencies": { "@ckeditor/ckeditor5-markdown-gfm": "^40.0.0", "codemirror": "^5.65.15", diff --git a/src/index.html b/src/index.html index 7a4fedf..a58a2cc 100644 --- a/src/index.html +++ b/src/index.html @@ -9,13 +9,12 @@ Fextify - + - - + + - + @@ -42,7 +41,7 @@