From 8fa739093234b232bd6967dbd094d5e3b4d31e15 Mon Sep 17 00:00:00 2001 From: ori raisfeld Date: Sun, 21 Apr 2024 21:00:50 +0300 Subject: [PATCH] I'm going to take back the past I lost! --- src-tauri/Cargo.toml | 2 +- src-tauri/src/data/json.rs | 1 + src-tauri/src/fs/commands.rs | 10 ++++++++++ src-tauri/src/main.rs | 2 +- src-tauri/tauri.conf.json | 3 ++- .../internal_apps/apps/file_system/file_system.tsx | 14 ++++++++++---- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index e3cbc24..fe12605 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -14,7 +14,7 @@ embed-resource = "*" [dependencies] -tauri = { version = "1", features = [ "dialog-message", "dialog-open", "dialog-save", "window-close", "window-set-fullscreen"] } +tauri = { version = "1", features = [ "dialog-confirm", "dialog-message", "dialog-open", "dialog-save", "window-close", "window-set-fullscreen"] } serde = { version = "1", features = ["derive"] } base64 = "*" rust-crypto ="*" diff --git a/src-tauri/src/data/json.rs b/src-tauri/src/data/json.rs index 6b5ada4..2a942d0 100644 --- a/src-tauri/src/data/json.rs +++ b/src-tauri/src/data/json.rs @@ -49,6 +49,7 @@ pub fn system_get<'a>(key: String) -> &'a Value { }; } +#[allow(non_snake_case)] #[tauri::command] pub fn create_value(valType: String, val: String) -> Value { let result = match valType.to_ascii_lowercase().as_str(){ diff --git a/src-tauri/src/fs/commands.rs b/src-tauri/src/fs/commands.rs index db54ba6..0e7e00e 100644 --- a/src-tauri/src/fs/commands.rs +++ b/src-tauri/src/fs/commands.rs @@ -203,6 +203,16 @@ impl File{ } +#[tauri::command] +pub fn file_exists(file_name: String) -> bool { + for file in unsafe{FS.current_dir.files.iter()}{ + if file.name() == &file_name{ + return true; + } + } + return false; +} + #[test] fn test_fs() { unsafe{FS.init_fs();} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3f7e4a1..8458817 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -11,6 +11,6 @@ mod data; fn main() { tauri::Builder::default().invoke_handler(tauri::generate_handler![ first_init, console, user_get, authenticate_user, save_user, user_exists, load_user, ls, pwd, cd, create_user, - create_value, mkdir, system_get, system_make, user_make, close_app, mk, upload_file, cd_back, rm + create_value, mkdir, system_get, system_make, user_make, close_app, mk, upload_file, cd_back, rm, file_exists ]).run(tauri::generate_context!()).expect("failed to run the code"); } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 87b69b1..59bfd4a 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -23,7 +23,8 @@ "dialog": { "open": true, "save": true, - "message": true + "message": true, + "confirm": true } }, "windows": [ diff --git a/src/pages/main_page/internal_apps/apps/file_system/file_system.tsx b/src/pages/main_page/internal_apps/apps/file_system/file_system.tsx index 3398635..c5694c5 100644 --- a/src/pages/main_page/internal_apps/apps/file_system/file_system.tsx +++ b/src/pages/main_page/internal_apps/apps/file_system/file_system.tsx @@ -1,10 +1,10 @@ import App, {AppInterface} from '../../App'; import { invoke } from '@tauri-apps/api'; +import { dialog } from '@tauri-apps/api'; import { useState, useEffect, Dispatch } from 'react'; -import img from '../../../assets/folder.png'; import { open } from '@tauri-apps/api/dialog'; import folder from '../../../assets/folder.png'; -import alpha from '../../../assets/image-solid.svg' +import alpha from '../../../assets/image-solid.svg'; import arrowleft from '../../../assets/arrowleft.png' import './file_system.css'; @@ -90,10 +90,16 @@ function file_system(open_file: (file: string) => Promise) : AppInterface{ const NewFile = () =>{ const [editing, set_editing] = useState('inherit'); const [text, set_text] = useState(''); + let icon = file_type == FileType.Directory ? folder : alpha; const done_editing = async (e: any) => { e.preventDefault(); set_editing('none'); if (text == ''){return;} + if (await invoke('file_exists', {fileName: text})){ + let sure = await dialog.confirm('a file with this name already exists, are you sure you want to delete it?'); + if (sure){await invoke('rm', {file: text});} + else {return;} + } let name: string = await invoke('system_get', {key: 'name'}); let password: string = await invoke('system_get', {key: 'password'}); await make_file(name, password, text, file_type); @@ -101,7 +107,7 @@ function file_system(open_file: (file: string) => Promise) : AppInterface{ } return
-
+
set_text(e.target.value)} onBlur={done_editing} onKeyDownCapture={e => {if (e.key == 'Enter'){set_editing('none');}}} autoFocus>
@@ -117,7 +123,7 @@ function file_system(open_file: (file: string) => Promise) : AppInterface{ }}> - + {selected != '' ?