diff --git a/package-lock.json b/package-lock.json
index 288b22a..954fabb 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -25,6 +25,7 @@
"web-vitals": "^2.1.4"
},
"devDependencies": {
+ "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"gh-pages": "^5.0.0"
}
},
@@ -638,9 +639,16 @@
}
},
"node_modules/@babel/plugin-proposal-private-property-in-object": {
- "version": "7.21.0-placeholder-for-preset-env.2",
- "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz",
- "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==",
+ "version": "7.21.11",
+ "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.11.tgz",
+ "integrity": "sha512-0QZ8qP/3RLDVBwBFoWAwCtgcDZJVwA5LUJRZU8x2YFfKNuFq161wK3cuGrALu5yiPu+vzwTAg/sMWVNeWeNyaw==",
+ "dev": true,
+ "dependencies": {
+ "@babel/helper-annotate-as-pure": "^7.18.6",
+ "@babel/helper-create-class-features-plugin": "^7.21.0",
+ "@babel/helper-plugin-utils": "^7.20.2",
+ "@babel/plugin-syntax-private-property-in-object": "^7.14.5"
+ },
"engines": {
"node": ">=6.9.0"
},
@@ -1898,6 +1906,17 @@
"@babel/core": "^7.0.0-0"
}
},
+ "node_modules/@babel/preset-env/node_modules/@babel/plugin-proposal-private-property-in-object": {
+ "version": "7.21.0-placeholder-for-preset-env.2",
+ "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz",
+ "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==",
+ "engines": {
+ "node": ">=6.9.0"
+ },
+ "peerDependencies": {
+ "@babel/core": "^7.0.0-0"
+ }
+ },
"node_modules/@babel/preset-env/node_modules/semver": {
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
diff --git a/package.json b/package.json
index 7fe3edb..e6c2594 100644
--- a/package.json
+++ b/package.json
@@ -49,6 +49,7 @@
]
},
"devDependencies": {
+ "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"gh-pages": "^5.0.0"
}
}
diff --git a/src/components/applications/file-explorer/FileExplorer.jsx b/src/components/applications/file-explorer/FileExplorer.jsx
index 180ffb5..8a2ef8e 100644
--- a/src/components/applications/file-explorer/FileExplorer.jsx
+++ b/src/components/applications/file-explorer/FileExplorer.jsx
@@ -3,11 +3,16 @@ import { useVirtualRoot } from "../../../hooks/virtual-drive/VirtualRootContext.
import styles from "./FileExplorer.module.css";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faArrowUp, faCaretLeft, faCaretRight, faCog, faDesktop, faFile, faFileLines, faFolder, faHouse, faImage, faSearch } from "@fortawesome/free-solid-svg-icons";
+// eslint-disable-next-line no-unused-vars
+import { VirtualFile } from "../../../features/virtual-drive/virtual-file.js";
+import { useWindowsManager } from "../../../hooks/windows/WindowsManagerContext.js";
+/**
+ * @param {Object} props
+ * @param {VirtualFile} props.file
+ */
function FilePreview({ file }) {
- let preview;
-
- console.log(file);
+ let preview = null;
switch (file.extension) {
case "png":
@@ -25,6 +30,7 @@ export function FileExplorer() {
const virtualRoot = useVirtualRoot();
const [currentDirectory, setCurrentDirectory] = useState(virtualRoot.navigate("~"));
const [path, setPath] = useState(currentDirectory.path);
+ const windowsManager = useWindowsManager();
const changeDirectory = (path, absolute = false) => {
const directory = absolute ? virtualRoot.navigate(path) : currentDirectory.navigate(path);
@@ -96,13 +102,18 @@ export function FileExplorer() {
{currentDirectory.files.map((file, index) =>
-
diff --git a/src/components/windows/WindowsView.jsx b/src/components/windows/WindowsView.jsx
index c14c8e1..377d027 100644
--- a/src/components/windows/WindowsView.jsx
+++ b/src/components/windows/WindowsView.jsx
@@ -11,7 +11,7 @@ export function WindowsView() {
return (
{windows.sort((windowA, windowB) =>
windowA.lastInteraction - windowB.lastInteraction
- ).map(({ id, app, size, position }, index) =>
+ ).map(({ id, app, size, position, options }, index) =>
{ windowsManager.focus(windows[index]); }}
id={id}
@@ -19,6 +19,7 @@ export function WindowsView() {
app={app}
size={size}
position={position}
+ options={options}
/>
)}
);
diff --git a/src/features/applications/application.js b/src/features/applications/application.js
index 39e023e..4af341a 100644
--- a/src/features/applications/application.js
+++ b/src/features/applications/application.js
@@ -4,7 +4,18 @@ export default class Application {
* @param {String} id
* @param {React.ReactElement} windowContent
*/
- constructor(name, id, windowContent) {
- Object.assign(this, { name, id, windowContent });
+ constructor(name, id, windowContent, windowOptions) {
+ Object.assign(this, { name, id, windowContent, windowOptions });
+ }
+
+ WindowContent = (props) => {
+ props = {...props, ...this.windowOptions};
+
+ if (this.windowContent == null) {
+ console.warn(`App (${this.id}) is missing the windowContent property.`);
+ return null;
+ }
+
+ return ;
}
}
\ No newline at end of file
diff --git a/src/features/applications/applications.js b/src/features/applications/applications.js
index 95fcd86..0d38b1d 100644
--- a/src/features/applications/applications.js
+++ b/src/features/applications/applications.js
@@ -1,21 +1,26 @@
/* eslint-disable eqeqeq */
import { FileExplorer } from "../../components/applications/file-explorer/FileExplorer.jsx";
+import { MediaViewer } from "../../components/applications/media-viewer/MediaViewer.jsx";
import { WebView } from "../../components/applications/templates/WebView.jsx";
import { Terminal } from "../../components/applications/terminal/Terminal.jsx";
import Application from "./application.js";
export default class ApplicationsManager {
static APPLICATIONS = [
- new Application("Terminal", "terminal", ),
+ new Application("Terminal", "terminal", Terminal),
// new Application("Browser", "browser"),
new Application("Code Editor", "code-editor"),
- new Application("File Explorer", "file-explorer", ),
- new Application("Media Viewer", "media-viewer"),
- new Application("Wordle", "wordle", ),
- new Application("Balls", "balls", ),
- new Application("Minesweeper", "minesweeper", ),
+ new Application("File Explorer", "file-explorer", FileExplorer),
+ new Application("Media Viewer", "media-viewer", MediaViewer),
+ new Application("Wordle", "wordle", WebView, { source: "https://prozilla.dev/wordle" }),
+ new Application("Balls", "balls", WebView, { source: "https://prozilla.dev/ball-maze" }),
+ new Application("Minesweeper", "minesweeper", WebView, { source: "https://prozilla.dev/minesweeper" }),
]
+ /**
+ * @param {String} id
+ * @returns {Application}
+ */
static getApplication(id) {
let application = null;
@@ -28,4 +33,21 @@ export default class ApplicationsManager {
return application;
}
+
+ /**
+ * @param {String} fileExtension
+ * @returns {Application}
+ */
+ static getFileApplication(fileExtension) {
+ let app = null;
+
+ // eslint-disable-next-line default-case
+ switch (fileExtension) {
+ case "png":
+ app = this.getApplication("media-viewer");
+ break;
+ }
+
+ return app;
+ }
}
\ No newline at end of file
diff --git a/src/features/windows/windows.js b/src/features/windows/windows.js
index 4929c45..09341ba 100644
--- a/src/features/windows/windows.js
+++ b/src/features/windows/windows.js
@@ -1,15 +1,16 @@
import ApplicationsManager from "../applications/applications.js";
import { randomRange } from "../math/random.js";
import Vector2 from "../math/vector2.js";
+// eslint-disable-next-line no-unused-vars
+import { VirtualFile } from "../virtual-drive/virtual-file.js";
export default class WindowsManager {
constructor() {
this.windows = {};
this.updateWindows = () => {};
- console.log("Windows manager init");
}
- open(appId) {
+ open(appId, options) {
const app = ApplicationsManager.getApplication(appId);
const size = new Vector2(700, 400);
const position = new Vector2(randomRange(50, 600), randomRange(50, 450));
@@ -19,13 +20,16 @@ export default class WindowsManager {
id++;
}
+ id = id.toString();
+
console.log(`Opening window ${id}:${app.id}`);
- this.windows[id.toString()] = {
+ this.windows[id] = {
id,
app,
size,
position,
+ options,
lastInteraction: new Date().valueOf()
};
@@ -33,6 +37,14 @@ export default class WindowsManager {
// console.log(this);
}
+ /**
+ * @param {VirtualFile} file
+ */
+ openFile(file) {
+ const app = ApplicationsManager.getFileApplication(file.extension);
+ this.open(app.id, { file });
+ }
+
close(windowId) {
windowId = windowId.toString();
diff --git a/src/hooks/virtual-drive/VirtualRootContext.js b/src/hooks/virtual-drive/VirtualRootContext.js
index 49a8371..fbfa972 100644
--- a/src/hooks/virtual-drive/VirtualRootContext.js
+++ b/src/hooks/virtual-drive/VirtualRootContext.js
@@ -38,13 +38,13 @@ function initVirtualRoot(virtualRoot) {
folder.setAlias("~")
.createFolder("Images", (folder) => {
folder.createFile("Wallpaper_1", "png", (file) => {
- file.setSource("/public/media/wallpapers/wallpaper-1.png")
+ file.setSource("/media/wallpapers/wallpaper1.png")
}).createFile("Wallpaper_2", "png", (file) => {
- file.setSource("/public/media/wallpapers/wallpaper-2.png")
+ file.setSource("/media/wallpapers/wallpaper2.png")
}).createFile("Wallpaper_3", "png", (file) => {
- file.setSource("/public/media/wallpapers/wallpaper-3.png")
+ file.setSource("/media/wallpapers/wallpaper3.png")
}).createFile("Wallpaper_4", "png", (file) => {
- file.setSource("/public/media/wallpapers/wallpaper-4.png")
+ file.setSource("/media/wallpapers/wallpaper4.png")
})
})
.createFolder("Documents")