From f6e8fefc25a9c693a560d7b61afd69698a7db3ac Mon Sep 17 00:00:00 2001 From: Franklin Waller Date: Thu, 31 Oct 2019 16:53:56 +0100 Subject: [PATCH] feat(terminal): Add support for running applications inside the filesystem --- src/js/apps/Explorer/Explorer.scss | 4 +++ src/js/apps/Explorer/Explorer.tsx | 32 +++++++++++++++++-- .../apps/Explorer/components/File/File.scss | 7 +++- src/js/apps/Explorer/components/File/File.tsx | 17 +++++++++- .../molecules/AppHeader/AppHeader.scss | 4 +++ .../molecules/AppHeader/AppHeader.tsx | 6 +++- .../organims/AppWindow/AppTitleBar.tsx | 5 +-- src/js/pages/HomePage/HomePage.tsx | 4 +-- src/js/services/BootService.ts | 4 +-- src/js/services/FileSystemService.ts | 23 +++++++++++-- src/js/services/TerminalService.ts | 8 +++++ 11 files changed, 99 insertions(+), 15 deletions(-) diff --git a/src/js/apps/Explorer/Explorer.scss b/src/js/apps/Explorer/Explorer.scss index c23964d..87fc904 100644 --- a/src/js/apps/Explorer/Explorer.scss +++ b/src/js/apps/Explorer/Explorer.scss @@ -3,3 +3,7 @@ // justify-content: space-evenly; flex-flow: wrap; } + +.toolbarButton { + color: white; +} diff --git a/src/js/apps/Explorer/Explorer.tsx b/src/js/apps/Explorer/Explorer.tsx index 80e9cfc..7f812a7 100644 --- a/src/js/apps/Explorer/Explorer.tsx +++ b/src/js/apps/Explorer/Explorer.tsx @@ -2,8 +2,11 @@ import * as React from 'react'; import AppHeader from '../../components/molecules/AppHeader'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; +import IconButton from '@material-ui/core/IconButton'; import ListItemIcon from '@material-ui/core/ListItemIcon'; import FolderIcon from '@material-ui/icons/Folder'; +import CreateNewFolderOutlinedIcon from '@material-ui/icons/CreateNewFolderOutlined'; +import ArrowUpwardIcon from '@material-ui/icons/ArrowUpward'; import ListItemText from '@material-ui/core/ListItemText'; import Collapse from '@material-ui/core/Collapse'; import ExpandLess from '@material-ui/icons/ExpandLess'; @@ -18,11 +21,12 @@ const styles = require('./Explorer.scss'); export default function Explorer() { const [isLocationsOpen, setLocationsOpen] = React.useState(true); const [files, setFiles] = React.useState([]); - const [path, setPath] = React.useState('/'); + const [path, setPath] = React.useState(''); React.useEffect(() => { const wasmFs = InstanceBag.get('fs'); - const filesAndDirectories: any = wasmFs.fs.readdirSync(path, { + const newPath = path === '' ? '/' : path; + const filesAndDirectories: any = wasmFs.fs.readdirSync(newPath, { encoding: "utf8", withFileTypes: true, }); @@ -37,9 +41,31 @@ export default function Explorer() { } } + function handleFolderUpButtonClick() { + const splittedPath = path.split('/'); + splittedPath.pop(); + + const newPath = splittedPath.join('/'); + setPath(newPath); + } + + const currentPathFolder = path.split('/').pop(); + const appHeaderTitle = currentPathFolder === '' ? 'Files' : currentPathFolder; + return ( <> - + + + + + + + + } + + menu={ setLocationsOpen(!isLocationsOpen)}> diff --git a/src/js/apps/Explorer/components/File/File.scss b/src/js/apps/Explorer/components/File/File.scss index b59aea4..7fa15c3 100644 --- a/src/js/apps/Explorer/components/File/File.scss +++ b/src/js/apps/Explorer/components/File/File.scss @@ -5,9 +5,14 @@ width: 25%; } -.icon { +.iconWrapper { width: 100%; height: 60%; +} + +.icon { + width: 100%; + height: 100%; color: #94a9b3; cursor: pointer; diff --git a/src/js/apps/Explorer/components/File/File.tsx b/src/js/apps/Explorer/components/File/File.tsx index 37e1281..4c302fc 100644 --- a/src/js/apps/Explorer/components/File/File.tsx +++ b/src/js/apps/Explorer/components/File/File.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import Dirent from 'memfs/lib/Dirent'; import InsertDriveFileOutlinedIcon from '@material-ui/icons/InsertDriveFileOutlined'; +import WebIcon from '@material-ui/icons/Web'; const styles = require('./File.scss'); interface Props { @@ -8,10 +9,24 @@ interface Props { onClick?: (folder: Dirent) => void; } +function getFileIcon(file: Dirent): any { + const fileNameSplitted = file.name.toString().split('.'); + const fileExtension = fileNameSplitted.pop(); + + switch(fileExtension) { + case 'wasm': + return + default: + return + } +} + export default function File(props: Props) { return (
- props.onClick(props.file)} /> +
props.onClick(props.file)}> + {getFileIcon(props.file)} +
{props.file.name}
); diff --git a/src/js/components/molecules/AppHeader/AppHeader.scss b/src/js/components/molecules/AppHeader/AppHeader.scss index 0d447c1..60f1583 100644 --- a/src/js/components/molecules/AppHeader/AppHeader.scss +++ b/src/js/components/molecules/AppHeader/AppHeader.scss @@ -6,6 +6,10 @@ $drawer-width: 240px; height: 100%; } +.title { + flex-grow: 1; +} + .menuButton { color: white !important; } diff --git a/src/js/components/molecules/AppHeader/AppHeader.tsx b/src/js/components/molecules/AppHeader/AppHeader.tsx index 3c4b73e..c2d326a 100644 --- a/src/js/components/molecules/AppHeader/AppHeader.tsx +++ b/src/js/components/molecules/AppHeader/AppHeader.tsx @@ -11,6 +11,7 @@ const styles = require('./AppHeader.scss'); interface Props { title: string; menu: React.ReactElement; + toolbar?: React.ReactNode; children: React.ReactNode; headerBackground?: string; headerTextColor?: string; @@ -27,9 +28,12 @@ function AppHeader(props: Props) { {/* */} - + {props.title} +
+ {props.toolbar} +
diff --git a/src/js/components/organims/AppWindow/AppTitleBar.tsx b/src/js/components/organims/AppWindow/AppTitleBar.tsx index 8c25863..dbd7155 100644 --- a/src/js/components/organims/AppWindow/AppTitleBar.tsx +++ b/src/js/components/organims/AppWindow/AppTitleBar.tsx @@ -25,9 +25,10 @@ function AppTitleBar(props: Props) { return (
- +
+ {/* - +
*/} {isDesktop && {props.process.app.short_name}} {!isDesktop &&