Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
I'm going to take back the past I lost!
Browse files Browse the repository at this point in the history
  • Loading branch information
raisfeld-ori committed Apr 21, 2024
1 parent bfc1fe9 commit 8fa7390
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ="*"
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/data/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/src/fs/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();}
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
3 changes: 2 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"dialog": {
"open": true,
"save": true,
"message": true
"message": true,
"confirm": true
}
},
"windows": [
Expand Down
14 changes: 10 additions & 4 deletions src/pages/main_page/internal_apps/apps/file_system/file_system.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -90,18 +90,24 @@ function file_system(open_file: (file: string) => Promise<void>) : 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);
await update();
}

return <div className='file' style={{display: editing}}>
<img src={img} className='file_img2'/><br />
<img src={icon} className='file_img2'/><br />
<input className='editing' onChange={e => set_text(e.target.value)}
onBlur={done_editing} onKeyDownCapture={e => {if (e.key == 'Enter'){set_editing('none');}}} autoFocus></input>
</div>
Expand All @@ -117,7 +123,7 @@ function file_system(open_file: (file: string) => Promise<void>) : AppInterface{
}}>

<button className='buttoncontextmenu' onClick={() => make_files(FileType.Directory)}>Create Folder</button>

<button className='buttoncontextmenu' onClick={() => make_files(FileType.File)}>create file</button>
<button className='buttoncontextmenu' onClick={async () => await upload_file(update, set_files)}>Upload File</button>
{selected != '' ?
<div>
Expand Down

0 comments on commit 8fa7390

Please sign in to comment.