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

Commit

Permalink
added the option to upload files
Browse files Browse the repository at this point in the history
  • Loading branch information
raisfeld-ori committed Mar 24, 2024
1 parent 1e80df7 commit 40ed743
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 64 deletions.
101 changes: 101 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 = [ "window-close", "window-set-fullscreen"] }
tauri = { version = "1", features = [ "dialog-open", "dialog-save", "window-close", "window-set-fullscreen"] }
serde = { version = "1", features = ["derive"] }
base64 = "*"
rust-crypto ="*"
Expand Down
4 changes: 4 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"shell": {
"all": false,
"open": false
},
"dialog": {
"open": true,
"save": true
}
},
"windows": [
Expand Down
51 changes: 40 additions & 11 deletions src/pages/main_page/internal_apps/apps/file_system.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@ import App from '../App';
import { invoke } from '@tauri-apps/api';
import { useState, useEffect } from 'react';
import img from '../../assets/terminal.png';
import { open } from '@tauri-apps/api/dialog';

async function upload_file(update_fs: () => Promise<void>, set_files: React.Dispatch<React.SetStateAction<React.JSX.Element[]>>){
let file_selected = await open({});
if (Array.isArray(file_selected)){
for (let i = 0; i < file_selected.length;i++){
//@ts-expect-error
set_files(files => [...files, <File name={file_selected[i]} key={files.length + 1}/>])
}
await update_fs();
}
else if (file_selected == null){return;}
else{
console.log('test');
//@ts-expect-error
set_files(files => [...files, <File name={file_selected} key={files.length + 1}/>]);
await update_fs();
}
}


function File(props: {name: string}){


return <div className='file'>
<img src={img} className='file_img'/><br />
<p className='file_name'>{props.name}</p>
</div>;
}

enum FileType{
File, Directory,
}
Expand All @@ -13,7 +43,7 @@ async function make_file(name: string, password: string, file: string, type: Fil
}
}

function file_system() : [JSX.Element, React.Dispatch<React.SetStateAction<string>>, JSX.Element]{
function file_system() : [JSX.Element, React.Dispatch<React.SetStateAction<string>>, JSX.Element, update_fs: () => Promise<void>]{
const [location, set_location] = useState("Home");
const [files, set_files] = useState<React.JSX.Element[]>([]);
const [{dx, dy}, set_positions] = useState({dx: 0, dy: 0});
Expand All @@ -23,15 +53,11 @@ function file_system() : [JSX.Element, React.Dispatch<React.SetStateAction<strin
let pwd: string = await invoke('pwd', {});
let files_divs = [];
for (let i = 0;i < files.length;i++){
files_divs.push(<div className='file' key={i}>
<img src={img} className='file_img'/><br />
<p className='file_name'>{files[i]}</p>
</div>);
files_divs.push(<File name={files[i]} key={'f' + i}/>);
}
set_files(files_divs);
set_location(pwd);
}
useEffect(() => {update_fs().catch(e => console.log(e))}, []);
useEffect(() => {
document.addEventListener("click", () => set_ctx_display('none'));
return () => document.removeEventListener("click", () => set_ctx_display('none'));
Expand Down Expand Up @@ -63,14 +89,17 @@ function file_system() : [JSX.Element, React.Dispatch<React.SetStateAction<strin
}
set_files([...files, <NewFile key={files.length + 1}/>]);
}
let context_menu = <div className='ContextMenu'
let context_menu =
<div className='ContextMenu'
style={{
top: dy + 2 + 'px',
left: dx + 2 + 'px',
display: `${ctx_display}`,
}}
><button onClick={() => make_files(FileType.Directory)}>
create dir</button></div>;
}}>
<button onClick={() => make_files(FileType.Directory)}>create dir</button>
<br />
<button onClick={async () => await upload_file(update_fs, set_files)}>upload file</button>
</div>;
let Application = <div className='ApplicationDirectory'>
<h1 className='filesystemtxt2'>/{location}/</h1>
</div>
Expand All @@ -80,7 +109,7 @@ function file_system() : [JSX.Element, React.Dispatch<React.SetStateAction<strin
</div>;
const [display, set_display] = useState('none');
let app = <App element={app_html} display={display} set_display={set_display} name='File System'/>;
return [app, set_display, context_menu];
return [app, set_display, context_menu, update_fs];
};


Expand Down
61 changes: 9 additions & 52 deletions src/pages/main_page/main_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ import { desktop_app } from './Grid';
import leaveicon from './assets/leave.png';
import { useNavigate } from 'react-router-dom';
import exit from './assets/exit.png';
import daddy from './assets/daddyishome.png';
import { invoke } from '@tauri-apps/api';

async function save_user(){
let username = await invoke('system_get', {key: 'name'});
let password = await invoke('system_get', {key: 'password'});
await invoke('save_user', {username, password});
}

export default function MainPage() {
const navigate = useNavigate();
const [app, fs_display, ctx_menu] = file_system();
const example_app = desktop_app("Files", folder, () => {fs_display('inherit')});
const [app, fs_display, ctx_menu, update_fs] = file_system();
const example_app = desktop_app("Files", folder, async () => {await update_fs();fs_display('inherit');});
const not_example_app = desktop_app("Search", search, async () => { console.log(await invoke('system_get', {key: 'name'})); });
const terminal = desktop_app("Terminal", terminald, () => {});
const [menu, set_menu] = useState(false);
Expand All @@ -38,11 +42,11 @@ export default function MainPage() {
<h1 className='menutext'>Applications</h1>

</div>
<button className='leave'onClick={() => navigate("/")} >
<button className='leave'onClick={async () => {await save_user();navigate("/");}} >
<img src={leaveicon} alt="leaveicon" />
</button>
<p className='hiddentxt'>Logout​</p>
<button className='exit' onClick={async () => await invoke('close_app', {})}>
<button className='exit' onClick={async () => {await save_user();await invoke('close_app', {});}}>
<img src={exit} alt="exiticon" />
</button>
<p className='hiddenclose'>Exit 😭​</p>
Expand All @@ -55,53 +59,6 @@ export default function MainPage() {
</button>
<p className='filestxt'>Files</p>
</div>

<div className='appsmenu'onClick={() => {fs_display('inherit')}}>
<p><i className="line right"></i></p>
<button className='folderappmenu'>
<img className='folderappmenu' src={daddy} alt="filesystem" />
</button>
<p className='filestxt'>Undefined</p>
</div>


<div className='appsmenu'onClick={() => {fs_display('inherit')}}>
<p><i className="line right"></i></p>
<button className='folderappmenu'>
<img className='folderappmenu' src={daddy} alt="filesystem" />
</button>
<p className='filestxt'>Undefined</p>
</div>


<div className='appsmenu'onClick={() => {fs_display('inherit')}}>
<p><i className="line right"></i></p>
<button className='folderappmenu'>
<img className='folderappmenu' src={daddy} alt="filesystem" />
</button>
<p className='filestxt'>Undefined</p>
</div>

<div className='appsmenu'onClick={() => {fs_display('inherit')}}>
<p><i className="line right"></i></p>
<button className='folderappmenu'>
<img className='folderappmenu' src={daddy} alt="filesystem" />
</button>
<p className='filestxt'>Undefined</p>
</div>


<div className='appsmenu'onClick={() => {fs_display('inherit')}}>
<p><i className="line right"></i></p>
<button className='folderappmenu'>
<img className='folderappmenu' src={daddy} alt="filesystem" />
</button>
<p className='filestxt'>Undefined</p>
</div>





</div>
<video className='hakari' src={ibetonhakari} width="100%" height="100%" autoPlay muted loop>
Expand Down

0 comments on commit 40ed743

Please sign in to comment.