Skip to content

Commit 5eb4a6a

Browse files
committed
Merge branch 'master' of https://github.com/devklick/react-resktop-sim into dev
2 parents 68dda27 + e372560 commit 5eb4a6a

10 files changed

Lines changed: 115 additions & 35 deletions

File tree

README.md

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,79 @@
1-
# React + TypeScript + Vite
1+
# React Desktop Simulator
22

3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3+
A simple simulation of a desktop environment, built using React.
44

5-
Currently, two official plugins are available:
5+
[Try it out!](https://devklick.github.io/react-desktop-sim/)
66

7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
7+
## Status
98

10-
## Expanding the ESLint configuration
9+
⚠️ WIP
1110

12-
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
11+
While it's somewhat functional, it's still a work in progress. Expect things to
12+
change fairly often, sometimes for better, sometimes for worse.
1313

14-
- Configure the top-level `parserOptions` property like this:
1514

16-
```js
17-
parserOptions: {
18-
ecmaVersion: 'latest',
19-
sourceType: 'module',
20-
project: ['./tsconfig.json', './tsconfig.node.json'],
21-
tsconfigRootDir: __dirname,
22-
},
23-
```
15+
## Scope And Purpose
2416

25-
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
26-
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
27-
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
17+
The purpose of this app, as with most of my apps, is for fun and practice.
18+
It doesn't really serve any useful purpose. It's fun to work on, hopefully it's
19+
interesting to others too, either to work on (feel free to get involved) or just
20+
play around with.
21+
22+
There's no defined scope, really. It's something that will likely slowly be built
23+
up more and more over time. With that being said, there are at least a few things
24+
that are definitely out of scope:
25+
26+
- Installing applications
27+
<br>You will never be able to install applications into this desktop simulator.
28+
You can build your own applications using React and add them to the repo, but
29+
you will never be able to install any genuine applications.
30+
31+
## Features
32+
33+
### File System
34+
35+
There's a basic file system built into the desktop environment, and it's persisted
36+
in your browsers local storage. It's not a full file system, so it doesn't contain
37+
the typical system files and folders you'd expect to see in a Windows, Linux or Mac OS
38+
system, but it's enough for you to create files and folders as required.
39+
40+
### Moveable/Resizable Applications
41+
42+
You can position your applications anywhere on the desktop, resizing them to fit
43+
your requirements. You can even maximize and minimize them when necessary.
44+
45+
### File Browser Application
46+
47+
There's no point having a file system built int the environment if there's no GUI
48+
to use it! There's a basic file browser application that allows you to navigate
49+
throughout the file system, view and create files and folders, pin favorites, and more.
50+
51+
### Calculator Application
52+
53+
Of course, there's a simple calculator app that allows you to perform basic
54+
calculations. Don't expect anything fancy though; you wont be able to complete
55+
you're algebra homework using it!
56+
57+
### Notes Application
58+
59+
A very bog-standard notes app that allows you to... well, write notes!
60+
It doesn't currently support saving files, but that should be added in the near
61+
future (the file system supports it, there's just no option in the UI to actually
62+
save the file). The same goes for loading saved files.
63+
64+
### Settings Application
65+
66+
The settings application will be for controlling the various settings of the
67+
desktop environment. At present, this is limited to:
68+
69+
#### Appearance
70+
71+
You can control the appearance of your simulated desktop environment, changing
72+
things like:
73+
74+
- Background image
75+
- UI color
76+
- Font color
77+
78+
Hopefully the list of configurable appearance settings will continue to grow
79+
over time.

src/components/BorderedApp/BorderedApp.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
grid-template-areas:
88
"title-bar"
99
"content";
10-
border-radius: 10px 10px 0 0;
10+
// border-radius: 10px 10px 0 0;
11+
border-radius: 10px;
1112
box-shadow: 0px -2px 10px 1px rgb(0, 0, 0, 0.5);
1213
position: fixed;
1314

src/components/BottomBar/Launcher/Launcher.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
transform: scale(1);
2121
transition: all 0.2s ease;
2222
&:hover {
23+
box-shadow: 0px 0px 10px 5px rgb(0, 0, 0, 0.5);
2324
transform: scale(1.3);
2425
transition: all 0.2s ease;
2526
}

src/hooks/useDragToMove.ts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import React, {
66
useRef,
77
useState,
88
} from "react";
9-
import { Rect } from "./useDragToResize";
9+
import { Position, Rect } from "./useDragToResize";
1010

1111
// https://stackoverflow.com/a/39192992/6236042
1212

@@ -19,12 +19,20 @@ interface UseDraggableProps {
1919
moveRef?: React.RefObject<HTMLElement> | null;
2020

2121
elementRect: MutableRefObject<Partial<Rect>>;
22+
23+
threshold?: number;
2224
}
2325

2426
// complex logic should be a hook, not a component
25-
const useDragToMove = ({ moveRef = null, elementRect }: UseDraggableProps) => {
27+
const useDragToMove = ({
28+
moveRef = null,
29+
elementRect,
30+
threshold = 7,
31+
}: UseDraggableProps) => {
2632
const [pressed, setPressed] = useState(false);
2733
const ref = useRef<HTMLElement | null>(null);
34+
const tempRect = useRef<Position>({ x: 0, y: 0 });
35+
const moving = useRef(false);
2836

2937
const unsubscribe = useRef<VoidFunction>();
3038
const moveHandle: RefCallback<HTMLElement> = useCallback((elem) => {
@@ -52,23 +60,37 @@ const useDragToMove = ({ moveRef = null, elementRect }: UseDraggableProps) => {
5260

5361
const handleMouseMove = throttle(
5462
(event: { movementX: number; movementY: number }) => {
55-
if (!ref.current || !elementRect.current) {
56-
return;
57-
}
63+
const element = moveRef?.current ?? ref.current;
64+
65+
if (!element) return;
5866

59-
elementRect.current.left =
60-
(elementRect.current.left ?? 0) + event.movementX;
67+
tempRect.current.x += event.movementX;
68+
tempRect.current.y += event.movementY;
6169

62-
elementRect.current.top =
63-
(elementRect.current.top ?? 0) + event.movementY;
70+
if (
71+
Math.abs(tempRect.current.x) >= threshold ||
72+
Math.abs(tempRect.current.y) >= threshold ||
73+
moving.current
74+
) {
75+
elementRect.current.left =
76+
(elementRect.current.left ?? 0) + tempRect.current.x;
6477

65-
const elem = moveRef?.current ?? ref.current;
78+
elementRect.current.top =
79+
(elementRect.current.top ?? 0) + tempRect.current.y;
80+
81+
tempRect.current.x = 0;
82+
tempRect.current.y = 0;
83+
moving.current = true;
84+
}
6685

67-
elem.style.left = `${elementRect.current.left}px`;
68-
elem.style.top = `${elementRect.current.top}px`;
86+
element.style.left = `${elementRect.current.left}px`;
87+
element.style.top = `${elementRect.current.top}px`;
6988
}
7089
);
7190
const handleMouseUp = () => {
91+
tempRect.current.x = 0;
92+
tempRect.current.y = 0;
93+
moving.current = false;
7294
setPressed(false);
7395
};
7496
// subscribe to mousemove and mouseup on document, otherwise you
@@ -84,7 +106,7 @@ const useDragToMove = ({ moveRef = null, elementRect }: UseDraggableProps) => {
84106
// if `onDrag` wasn't defined with `useCallback`, we'd have to
85107
// resubscribe to 2 DOM events here, not to say it would mess
86108
// with `throttle` and reset its internal timer
87-
}, [pressed, moveRef, elementRect]);
109+
}, [pressed, moveRef, elementRect, threshold]);
88110

89111
// actually it makes sense to return an array only when
90112
// you expect that on the caller side all of the fields

src/hooks/useDragToResize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface Rect extends Dimensions {
1212
left: number;
1313
}
1414

15-
interface Position {
15+
export interface Position {
1616
x: number;
1717
y: number;
1818
}

src/hooks/useWindowMinMax.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function useWindowMinMax({
4949

5050
window.style.transition = "all 0.2s linear";
5151
window.style.opacity = "0";
52-
window.style.transform = "scale(0.5) translate(0, 500%)";
52+
window.style.transform = "scale(0.2) translate(0, 500%)";
5353

5454
window.addEventListener("transitionend", handleTransitionEnd);
5555
}

src/programs/Calculator/Calculator.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"buttons";
1010
box-shadow: 0px 0px 4px rgb(0, 0, 0, 0.5) inset;
1111
padding: 10px;
12+
border-radius: 10px;
1213
box-sizing: border-box;
1314
gap: 10px;
1415

src/programs/FileBrowser/FileBrowser.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"side-bar bottom-bar";
1111

1212
box-shadow: 0px 0px 4px rgb(0, 0, 0, 0.5) inset;
13+
border-radius: 10px;
1314

1415
&__top-bar {
1516
grid-area: top-bar;

src/programs/Settings/Settings.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
width: 100%;
66
height: 100%;
77
box-shadow: 0px 0px 4px rgb(0, 0, 0, 0.5) inset;
8+
border-radius: 10px;
89

910
&__page {
1011
overflow: auto;

src/programs/TextEditor/TextEditor.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
background-color: transparent;
1313
color: white;
1414
box-shadow: 0px 0px 4px rgb(0, 0, 0, 0.5) inset;
15+
border-radius: 10px;
1516
padding: 10px;
1617
box-sizing: border-box;
1718

0 commit comments

Comments
 (0)