@prozilla-os/core 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +1 -0
- package/package.json +43 -0
- package/src/components/_utils/button/Button.module.css +25 -0
- package/src/components/_utils/button/Button.tsx +48 -0
- package/src/components/_utils/directory-list/DirectoryList.module.css +70 -0
- package/src/components/_utils/directory-list/DirectoryList.tsx +203 -0
- package/src/components/_utils/directory-list/ImagePreview.module.css +19 -0
- package/src/components/_utils/directory-list/ImagePreview.tsx +33 -0
- package/src/components/_utils/dropdown-button/DropdownButton.module.css +60 -0
- package/src/components/_utils/dropdown-button/DropdownButton.tsx +40 -0
- package/src/components/_utils/header-menu/HeaderMenu.module.css +8 -0
- package/src/components/_utils/header-menu/HeaderMenu.tsx +15 -0
- package/src/components/_utils/index.ts +10 -0
- package/src/components/_utils/interactable/Interactable.tsx +42 -0
- package/src/components/_utils/progress-bar/ProgressBar.module.css +20 -0
- package/src/components/_utils/progress-bar/ProgressBar.tsx +22 -0
- package/src/components/_utils/web-view/WebView.module.css +15 -0
- package/src/components/_utils/web-view/WebView.tsx +47 -0
- package/src/components/actions/Actions.module.css +281 -0
- package/src/components/actions/Actions.tsx +108 -0
- package/src/components/actions/actions/ClickAction.tsx +30 -0
- package/src/components/actions/actions/Divider.tsx +5 -0
- package/src/components/actions/actions/DropdownAction.tsx +50 -0
- package/src/components/actions/actions/RadioAction.tsx +50 -0
- package/src/components/actions/actions/TextDisplay.tsx +12 -0
- package/src/components/actions/actions/ToggleAction.tsx +31 -0
- package/src/components/actions/index.ts +7 -0
- package/src/components/desktop/Desktop.module.css +49 -0
- package/src/components/desktop/Desktop.tsx +199 -0
- package/src/components/index.ts +10 -0
- package/src/components/modals/ModalView.module.css +14 -0
- package/src/components/modals/ModalView.tsx +54 -0
- package/src/components/modals/ModalsView.module.css +4 -0
- package/src/components/modals/ModalsView.tsx +32 -0
- package/src/components/modals/_utils/WindowedModal.module.css +92 -0
- package/src/components/modals/_utils/WindowedModal.tsx +71 -0
- package/src/components/modals/dialog-box/DialogBox.module.css +27 -0
- package/src/components/modals/dialog-box/DialogBox.tsx +26 -0
- package/src/components/modals/file-selector/FileSelector.module.css +25 -0
- package/src/components/modals/file-selector/FileSelector.tsx +77 -0
- package/src/components/modals/index.ts +7 -0
- package/src/components/modals/share/Option.tsx +23 -0
- package/src/components/modals/share/Share.module.css +153 -0
- package/src/components/modals/share/Share.tsx +197 -0
- package/src/components/prozilla-os/ProzillaOS.module.css +14 -0
- package/src/components/prozilla-os/ProzillaOS.tsx +76 -0
- package/src/components/taskbar/Taskbar.module.css +218 -0
- package/src/components/taskbar/Taskbar.tsx +193 -0
- package/src/components/taskbar/app-icon/AppIcon.module.css +62 -0
- package/src/components/taskbar/app-icon/AppIcon.tsx +76 -0
- package/src/components/taskbar/indicators/Battery.module.css +32 -0
- package/src/components/taskbar/indicators/Battery.tsx +114 -0
- package/src/components/taskbar/indicators/Calendar.module.css +24 -0
- package/src/components/taskbar/indicators/Calendar.tsx +67 -0
- package/src/components/taskbar/indicators/Network.module.css +17 -0
- package/src/components/taskbar/indicators/Network.tsx +38 -0
- package/src/components/taskbar/indicators/Volume.module.css +17 -0
- package/src/components/taskbar/indicators/Volume.tsx +38 -0
- package/src/components/taskbar/indicators/index.ts +4 -0
- package/src/components/taskbar/menus/AppList.module.css +33 -0
- package/src/components/taskbar/menus/HomeMenu.module.css +47 -0
- package/src/components/taskbar/menus/HomeMenu.tsx +118 -0
- package/src/components/taskbar/menus/SearchMenu.module.css +68 -0
- package/src/components/taskbar/menus/SearchMenu.tsx +100 -0
- package/src/components/taskbar/menus/UtilMenu.module.css +41 -0
- package/src/components/taskbar/menus/UtilMenu.tsx +23 -0
- package/src/components/windows/WindowFallbackView.tsx +38 -0
- package/src/components/windows/WindowView.module.css +152 -0
- package/src/components/windows/WindowView.tsx +233 -0
- package/src/components/windows/WindowsView.tsx +89 -0
- package/src/constants/index.ts +3 -0
- package/src/constants/modals.const.ts +3 -0
- package/src/constants/themes.const.ts +8 -0
- package/src/constants/utils.const.ts +19 -0
- package/src/constants/virtualDrive.const.ts +20 -0
- package/src/features/_utils/array.utils.ts +14 -0
- package/src/features/_utils/browser.utils.ts +111 -0
- package/src/features/_utils/date.utils.ts +90 -0
- package/src/features/_utils/event.utils.ts +39 -0
- package/src/features/_utils/index.ts +8 -0
- package/src/features/_utils/math.utils.ts +18 -0
- package/src/features/_utils/number.utils.ts +3 -0
- package/src/features/_utils/string.utils.ts +31 -0
- package/src/features/_utils/time.utils.ts +13 -0
- package/src/features/actions/actionsManager.ts +7 -0
- package/src/features/index.ts +12 -0
- package/src/features/math/vector2.ts +75 -0
- package/src/features/modals/modal.ts +74 -0
- package/src/features/modals/modalsManager.ts +72 -0
- package/src/features/settings/settings.ts +109 -0
- package/src/features/settings/settingsManager.ts +31 -0
- package/src/features/storage/storageManager.ts +35 -0
- package/src/features/system/configs/app.tsx +60 -0
- package/src/features/system/configs/appsConfig.ts +60 -0
- package/src/features/system/configs/desktopConfig.ts +46 -0
- package/src/features/system/configs/index.ts +9 -0
- package/src/features/system/configs/miscConfig.ts +19 -0
- package/src/features/system/configs/modalsConfig.ts +28 -0
- package/src/features/system/configs/taskbarConfig.ts +19 -0
- package/src/features/system/configs/trackingConfig.ts +24 -0
- package/src/features/system/configs/virtualDriveConfig.ts +39 -0
- package/src/features/system/configs/windowsConfig.ts +34 -0
- package/src/features/system/systemManager.ts +68 -0
- package/src/features/tracking/trackingManager.ts +40 -0
- package/src/features/virtual-drive/file/index.ts +2 -0
- package/src/features/virtual-drive/file/virtualFile.ts +197 -0
- package/src/features/virtual-drive/file/virtualFileLink.ts +111 -0
- package/src/features/virtual-drive/folder/index.ts +2 -0
- package/src/features/virtual-drive/folder/virtualFolder.ts +388 -0
- package/src/features/virtual-drive/folder/virtualFolderLink.ts +148 -0
- package/src/features/virtual-drive/index.ts +3 -0
- package/src/features/virtual-drive/root/defaultData.ts +140 -0
- package/src/features/virtual-drive/root/virtualRoot.ts +244 -0
- package/src/features/virtual-drive/virtualBase.ts +191 -0
- package/src/features/windows/windowsManager.ts +244 -0
- package/src/features/z-index/zIndexGroup.ts +40 -0
- package/src/features/z-index/zIndexManager.ts +46 -0
- package/src/hooks/_utils/history.ts +50 -0
- package/src/hooks/_utils/index.ts +6 -0
- package/src/hooks/_utils/keyboard.ts +111 -0
- package/src/hooks/_utils/mouse.ts +32 -0
- package/src/hooks/_utils/outsideClick.tsx +33 -0
- package/src/hooks/_utils/screen.ts +61 -0
- package/src/hooks/_utils/scrollWithShadows.ts +138 -0
- package/src/hooks/apps/appFolder.ts +30 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/modals/alert.tsx +34 -0
- package/src/hooks/modals/contextMenu.tsx +47 -0
- package/src/hooks/modals/index.ts +4 -0
- package/src/hooks/modals/modalsContext.ts +10 -0
- package/src/hooks/modals/modalsManagerContext.ts +10 -0
- package/src/hooks/modals/modalsManagerProvider.tsx +16 -0
- package/src/hooks/modals/modalsProvider.tsx +20 -0
- package/src/hooks/modals/windowedModal.ts +47 -0
- package/src/hooks/settings/settingsManagerContext.ts +10 -0
- package/src/hooks/settings/settingsManagerProvider.tsx +16 -0
- package/src/hooks/system/systemManagerContext.ts +8 -0
- package/src/hooks/system/systemManagerProvider.tsx +26 -0
- package/src/hooks/themes/themes.tsx +22 -0
- package/src/hooks/tracking/trackingManagerContext.ts +10 -0
- package/src/hooks/tracking/trackingManagerProvider.tsx +13 -0
- package/src/hooks/virtual-drive/virtualRootContext.ts +10 -0
- package/src/hooks/virtual-drive/virtualRootProvider.tsx +13 -0
- package/src/hooks/windows/windowsContext.ts +10 -0
- package/src/hooks/windows/windowsManagerContext.ts +10 -0
- package/src/hooks/windows/windowsManagerProvider.tsx +24 -0
- package/src/hooks/windows/windowsProvider.tsx +20 -0
- package/src/hooks/z-index/zIndex.ts +32 -0
- package/src/hooks/z-index/zIndexManagerContext.ts +10 -0
- package/src/hooks/z-index/zIndexManagerProvider.tsx +11 -0
- package/src/index.ts +5 -0
- package/src/styles/global/fonts.css +18 -0
- package/src/styles/global/scrollbar.css +29 -0
- package/src/styles/global/themes.css +67 -0
- package/src/styles/global/variables.css +92 -0
- package/src/styles/global.css +65 -0
- package/src/styles/index.ts +3 -0
- package/src/styles/utils.module.css +22 -0
- package/src/types/util.d.ts +3 -0
- package/src/types/vite-env.d.ts +1 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
2
|
+
import styles from "./WindowView.module.css";
|
|
3
|
+
import { faCircleRight, faExpand, faMinus, faWindowMaximize as fasWindowMaximize, faTimes, faXmark } from "@fortawesome/free-solid-svg-icons";
|
|
4
|
+
import { ReactSVG } from "react-svg";
|
|
5
|
+
import { useWindowsManager } from "../../hooks/windows/windowsManagerContext";
|
|
6
|
+
import Draggable from "react-draggable";
|
|
7
|
+
import { CSSProperties, FC, memo, MouseEventHandler, useEffect, useRef, useState } from "react";
|
|
8
|
+
import { Vector2 } from "../../features/math/vector2";
|
|
9
|
+
import { faWindowMaximize } from "@fortawesome/free-regular-svg-icons";
|
|
10
|
+
import utilStyles from "../../styles/utils.module.css";
|
|
11
|
+
import { useContextMenu } from "../../hooks/modals/contextMenu";
|
|
12
|
+
import { ClickAction } from "../actions/actions/ClickAction";
|
|
13
|
+
import { Actions } from "../actions/Actions";
|
|
14
|
+
import { useScreenDimensions } from "../../hooks/_utils/screen";
|
|
15
|
+
import { generateUrl, openUrl, setViewportIcon, setViewportTitle } from "../../features/_utils/browser.utils";
|
|
16
|
+
import { ZIndexManager } from "../../features/z-index/zIndexManager";
|
|
17
|
+
import { useZIndex } from "../../hooks/z-index/zIndex";
|
|
18
|
+
import { useWindowedModal } from "../../hooks/modals/windowedModal";
|
|
19
|
+
import { Divider } from "../actions/actions/Divider";
|
|
20
|
+
import { ModalsManager } from "../../features/modals/modalsManager";
|
|
21
|
+
import { Share } from "../modals/share/Share";
|
|
22
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
23
|
+
import { WindowFallbackView } from "./WindowFallbackView";
|
|
24
|
+
import { WindowOptions } from "../../features/windows/windowsManager";
|
|
25
|
+
import { ModalProps } from "../modals/ModalView";
|
|
26
|
+
import { useSystemManager } from "../../hooks";
|
|
27
|
+
|
|
28
|
+
export interface WindowProps extends WindowOptions {
|
|
29
|
+
fullscreen?: boolean;
|
|
30
|
+
onInteract?: Function
|
|
31
|
+
setTitle?: React.Dispatch<React.SetStateAction<string>>;
|
|
32
|
+
setIconUrl?: React.Dispatch<React.SetStateAction<string>>;
|
|
33
|
+
close?: (event?: Event) => void;
|
|
34
|
+
focus?: (event: Event, force?: boolean) => void;
|
|
35
|
+
active?: boolean;
|
|
36
|
+
minimized?: boolean;
|
|
37
|
+
toggleMinimized?: Function;
|
|
38
|
+
index?: number;
|
|
39
|
+
standalone?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const WindowView: FC<WindowProps> = memo(({ id, app, size, position, onInteract, options, active, fullscreen, minimized, toggleMinimized, index }) => {
|
|
43
|
+
const { systemName, windowsConfig, appsConfig } = useSystemManager();
|
|
44
|
+
const windowsManager = useWindowsManager();
|
|
45
|
+
const nodeRef = useRef(null);
|
|
46
|
+
const { openWindowedModal } = useWindowedModal();
|
|
47
|
+
|
|
48
|
+
const [startPosition, setStartPosition] = useState(position);
|
|
49
|
+
const [maximized, setMaximized] = useState(fullscreen ?? false);
|
|
50
|
+
const [screenWidth, screenHeight] = useScreenDimensions();
|
|
51
|
+
const [title, setTitle] = useState(app?.name ?? "");
|
|
52
|
+
const [iconUrl, setIconUrl] = useState<string>(app ? appsConfig.getAppById(app?.id)?.iconUrl ?? "" : "");
|
|
53
|
+
const zIndex = useZIndex({ groupIndex: ZIndexManager.GROUPS.WINDOWS, index: index ?? 0 });
|
|
54
|
+
|
|
55
|
+
const { onContextMenu, ShortcutsListener } = useContextMenu({ Actions: (props) =>
|
|
56
|
+
<Actions {...props}>
|
|
57
|
+
<ClickAction label="Minimize" icon={faMinus} onTrigger={() => { toggleMinimized?.(); }}/>
|
|
58
|
+
<ClickAction label="Maximize" icon={faExpand} shortcut={["F11"]} onTrigger={() => {
|
|
59
|
+
setMaximized(!maximized);
|
|
60
|
+
}}/>
|
|
61
|
+
<ClickAction label="Close" icon={faTimes} shortcut={["Control", "q"]} onTrigger={() => {
|
|
62
|
+
close?.();
|
|
63
|
+
}}/>
|
|
64
|
+
<Divider/>
|
|
65
|
+
<ClickAction label="Standalone mode" icon={faCircleRight} onTrigger={() => {
|
|
66
|
+
if (app != null) openUrl(generateUrl({ appId: app.id, standalone: true }), "_self");
|
|
67
|
+
}}/>
|
|
68
|
+
<ClickAction label={"Share"} icon={ModalsManager.getModalIconUrl("share")} shortcut={["Alt", "s"]} onTrigger={() => {
|
|
69
|
+
if (app != null)
|
|
70
|
+
openWindowedModal({
|
|
71
|
+
appId: app.id,
|
|
72
|
+
fullscreen: maximized,
|
|
73
|
+
size: new Vector2(350, 350),
|
|
74
|
+
Modal: (props: ModalProps) => <Share {...props}/>
|
|
75
|
+
});
|
|
76
|
+
}}/>
|
|
77
|
+
</Actions>
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (screenWidth == null || screenHeight == null) return;
|
|
82
|
+
|
|
83
|
+
if (screenWidth < windowsConfig.minScreenSize.x || screenHeight < windowsConfig.minScreenSize.y) {
|
|
84
|
+
setMaximized(true);
|
|
85
|
+
} else if (position != null) {
|
|
86
|
+
if (position.x > screenWidth) position.x = 0;
|
|
87
|
+
if (position.y > screenHeight) position.y = 0;
|
|
88
|
+
|
|
89
|
+
setStartPosition(position);
|
|
90
|
+
} else {
|
|
91
|
+
setStartPosition(new Vector2(0, 0));
|
|
92
|
+
}
|
|
93
|
+
}, [position, size, screenHeight, screenWidth]);
|
|
94
|
+
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
const setViewportTitleAndIcon = () => {
|
|
97
|
+
if (title != null) setViewportTitle(`${title} | ${systemName}`);
|
|
98
|
+
if (iconUrl != null) setViewportIcon(iconUrl);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
if (active && !minimized) setViewportTitleAndIcon();
|
|
102
|
+
|
|
103
|
+
window.addEventListener("focus", setViewportTitleAndIcon);
|
|
104
|
+
|
|
105
|
+
return () => {
|
|
106
|
+
window.removeEventListener("focus", setViewportTitleAndIcon);
|
|
107
|
+
};
|
|
108
|
+
}, [active, minimized, iconUrl, title]);
|
|
109
|
+
|
|
110
|
+
if (app == null)
|
|
111
|
+
return;
|
|
112
|
+
|
|
113
|
+
const close: WindowProps["close"] = (event) => {
|
|
114
|
+
event?.preventDefault();
|
|
115
|
+
if (id != null) windowsManager?.close(id);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const focus: WindowProps["focus"] = (event, force = false) => {
|
|
119
|
+
if (force) {
|
|
120
|
+
onInteract?.();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (event?.defaultPrevented)
|
|
125
|
+
return;
|
|
126
|
+
|
|
127
|
+
const target = event?.target as HTMLElement;
|
|
128
|
+
if (event == null || target?.closest?.(".Handle") == null || target?.closest?.("button") == null)
|
|
129
|
+
onInteract?.();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const classNames = [styles["Window-container"]];
|
|
133
|
+
if (maximized)
|
|
134
|
+
classNames.push(styles.Maximized);
|
|
135
|
+
if (minimized)
|
|
136
|
+
classNames.push(styles.Minimized);
|
|
137
|
+
|
|
138
|
+
return (<div style={{ zIndex, position: !maximized ? "relative" : null } as CSSProperties}>
|
|
139
|
+
<ShortcutsListener/>
|
|
140
|
+
<Draggable
|
|
141
|
+
key={id}
|
|
142
|
+
axis="both"
|
|
143
|
+
handle={".Window-handle"}
|
|
144
|
+
defaultPosition={startPosition?.round()}
|
|
145
|
+
position={undefined}
|
|
146
|
+
scale={1}
|
|
147
|
+
bounds={{
|
|
148
|
+
top: 0,
|
|
149
|
+
bottom: (screenHeight ?? 0) - 55,
|
|
150
|
+
left: size ? -size.x + 85 : 85,
|
|
151
|
+
right: (screenWidth ?? 0) - 5
|
|
152
|
+
}}
|
|
153
|
+
cancel="button"
|
|
154
|
+
nodeRef={nodeRef}
|
|
155
|
+
disabled={maximized}
|
|
156
|
+
onStart={(event) => { focus(event as Event); }}
|
|
157
|
+
grid={[1, 1]}
|
|
158
|
+
>
|
|
159
|
+
<div
|
|
160
|
+
className={classNames.join(" ")}
|
|
161
|
+
ref={nodeRef}
|
|
162
|
+
onClick={focus as unknown as MouseEventHandler}
|
|
163
|
+
>
|
|
164
|
+
<div
|
|
165
|
+
className={styles["Window-inner"]}
|
|
166
|
+
style={{
|
|
167
|
+
width: (maximized || size == null) ? undefined : size.x,
|
|
168
|
+
height: (maximized || size == null) ? undefined : size.y,
|
|
169
|
+
}}
|
|
170
|
+
>
|
|
171
|
+
<div
|
|
172
|
+
className={`${styles.Header} Window-handle`}
|
|
173
|
+
onContextMenu={onContextMenu as unknown as MouseEventHandler}
|
|
174
|
+
onDoubleClick={(event) => {
|
|
175
|
+
setMaximized(!maximized);
|
|
176
|
+
focus(event as unknown as Event, true);
|
|
177
|
+
}}
|
|
178
|
+
>
|
|
179
|
+
<ReactSVG
|
|
180
|
+
className={styles["Window-icon"]}
|
|
181
|
+
src={iconUrl}
|
|
182
|
+
/>
|
|
183
|
+
<p className={utilStyles.TextSemibold}>{title}</p>
|
|
184
|
+
<button aria-label="Minimize" className={styles["Header-button"]} tabIndex={0} id="minimize-window"
|
|
185
|
+
onClick={toggleMinimized as MouseEventHandler}
|
|
186
|
+
>
|
|
187
|
+
<FontAwesomeIcon icon={faMinus}/>
|
|
188
|
+
</button>
|
|
189
|
+
{screenWidth != null && screenHeight != null
|
|
190
|
+
&& screenWidth > windowsConfig.minScreenSize.x && screenHeight > windowsConfig.minScreenSize.y
|
|
191
|
+
? <button aria-label="Maximize" className={styles["Header-button"]} tabIndex={0} id="maximize-window"
|
|
192
|
+
onClick={(event) => {
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
setMaximized(!maximized);
|
|
195
|
+
focus(event as unknown as Event, true);
|
|
196
|
+
}}
|
|
197
|
+
>
|
|
198
|
+
<FontAwesomeIcon icon={maximized ? fasWindowMaximize : faWindowMaximize}/>
|
|
199
|
+
</button>
|
|
200
|
+
: null
|
|
201
|
+
}
|
|
202
|
+
<button aria-label="Close" className={`${styles["Header-button"]} ${styles["Exit-button"]}`} tabIndex={0} id="close-window"
|
|
203
|
+
onClick={close as unknown as MouseEventHandler}>
|
|
204
|
+
<FontAwesomeIcon icon={faXmark}/>
|
|
205
|
+
</button>
|
|
206
|
+
</div>
|
|
207
|
+
<div className={styles["Window-content"]}>
|
|
208
|
+
<ErrorBoundary
|
|
209
|
+
FallbackComponent={(props) => <WindowFallbackView app={app} closeWindow={close} {...props}/>}
|
|
210
|
+
onReset={() => {
|
|
211
|
+
// Reset the state of your app so the error doesn't happen again
|
|
212
|
+
}}
|
|
213
|
+
onError={(error) => {
|
|
214
|
+
console.error(error);
|
|
215
|
+
}}
|
|
216
|
+
>
|
|
217
|
+
<app.WindowContent
|
|
218
|
+
{...options}
|
|
219
|
+
app={app}
|
|
220
|
+
setTitle={setTitle}
|
|
221
|
+
setIconUrl={setIconUrl}
|
|
222
|
+
close={close}
|
|
223
|
+
focus={focus}
|
|
224
|
+
active={active}
|
|
225
|
+
standalone={false}
|
|
226
|
+
/>
|
|
227
|
+
</ErrorBoundary>
|
|
228
|
+
</div>
|
|
229
|
+
</div>
|
|
230
|
+
</div>
|
|
231
|
+
</Draggable>
|
|
232
|
+
</div>);
|
|
233
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { FC, memo, useEffect, useState } from "react";
|
|
2
|
+
import { WindowProps, WindowView } from "./WindowView";
|
|
3
|
+
import { setViewportTitle, setViewportIcon, getViewportParams, SettingsManager, removeDuplicatesFromArray } from "../../features";
|
|
4
|
+
import { WindowOptions } from "../../features/windows/windowsManager";
|
|
5
|
+
import { useSettingsManager, useSystemManager, useWindowsManager } from "../../hooks";
|
|
6
|
+
import { useWindows } from "../../hooks/windows/windowsContext";
|
|
7
|
+
|
|
8
|
+
export const WindowsView: FC = memo(() => {
|
|
9
|
+
const { systemName, tagLine } = useSystemManager();
|
|
10
|
+
const settingsManager = useSettingsManager();
|
|
11
|
+
const windows = useWindows();
|
|
12
|
+
const windowsManager = useWindowsManager();
|
|
13
|
+
const [sortedWindows, setSortedWindows] = useState<WindowProps[]>([]);
|
|
14
|
+
|
|
15
|
+
// Sort windows
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (windows != null)
|
|
18
|
+
setSortedWindows([...windows].sort((windowA: WindowOptions, windowB: WindowOptions) =>
|
|
19
|
+
(windowA.lastInteraction ?? 0) - (windowB.lastInteraction ?? 0)
|
|
20
|
+
));
|
|
21
|
+
}, [windows]);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const resetViewportTitleAndIcon = () => {
|
|
25
|
+
setViewportTitle(`${systemName} | ${tagLine}`);
|
|
26
|
+
setViewportIcon("/favicon.ico?v=6");
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if (sortedWindows.length === 0 || sortedWindows[sortedWindows.length - 1].minimized)
|
|
30
|
+
resetViewportTitleAndIcon();
|
|
31
|
+
|
|
32
|
+
window.addEventListener("blur", resetViewportTitleAndIcon);
|
|
33
|
+
|
|
34
|
+
return () => {
|
|
35
|
+
window.removeEventListener("blur", resetViewportTitleAndIcon);
|
|
36
|
+
};
|
|
37
|
+
}, [sortedWindows]);
|
|
38
|
+
|
|
39
|
+
// Launch startup apps
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (windowsManager?.startupComplete)
|
|
42
|
+
return;
|
|
43
|
+
|
|
44
|
+
let startupAppNames: string[] = [];
|
|
45
|
+
|
|
46
|
+
// Get app name and params from URL query
|
|
47
|
+
const params = getViewportParams();
|
|
48
|
+
const appName = params.app;
|
|
49
|
+
if (appName)
|
|
50
|
+
startupAppNames.push(appName);
|
|
51
|
+
delete params.app;
|
|
52
|
+
|
|
53
|
+
// Get list of app names from settings file
|
|
54
|
+
const settings = settingsManager?.getSettings(SettingsManager.VIRTUAL_PATHS.apps);
|
|
55
|
+
void settings?.get("startup", (value) => {
|
|
56
|
+
if (value !== "") {
|
|
57
|
+
startupAppNames = value?.split(",").concat(startupAppNames);
|
|
58
|
+
startupAppNames = removeDuplicatesFromArray(startupAppNames);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
windowsManager?.startup(startupAppNames, params);
|
|
62
|
+
});
|
|
63
|
+
}, [settingsManager, windowsManager]);
|
|
64
|
+
|
|
65
|
+
return (<div>
|
|
66
|
+
{windows?.map((window: WindowProps) => {
|
|
67
|
+
const { id, app, size, position, options, minimized, fullscreen } = window;
|
|
68
|
+
const index = sortedWindows.indexOf(window);
|
|
69
|
+
return <WindowView
|
|
70
|
+
key={id}
|
|
71
|
+
onInteract={() => { windowsManager?.focus(id as string); }}
|
|
72
|
+
active={index === sortedWindows.length - 1}
|
|
73
|
+
id={id}
|
|
74
|
+
app={app}
|
|
75
|
+
size={size}
|
|
76
|
+
index={index}
|
|
77
|
+
position={position}
|
|
78
|
+
options={options}
|
|
79
|
+
minimized={minimized}
|
|
80
|
+
toggleMinimized={(event: Event) => {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
event.stopPropagation();
|
|
83
|
+
windowsManager?.setMinimized(id as string, !minimized);
|
|
84
|
+
}}
|
|
85
|
+
fullscreen={fullscreen}
|
|
86
|
+
/>;
|
|
87
|
+
})}
|
|
88
|
+
</div>);
|
|
89
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const ANSI = {
|
|
2
|
+
fg: {
|
|
3
|
+
black: "\u001b[30m",
|
|
4
|
+
red: "\u001b[31m",
|
|
5
|
+
green: "\u001b[32m",
|
|
6
|
+
yellow: "\u001b[33m",
|
|
7
|
+
blue: "\u001b[34m",
|
|
8
|
+
magenta: "\u001b[35m",
|
|
9
|
+
cyan: "\u001b[36m",
|
|
10
|
+
white: "\u001b[37m",
|
|
11
|
+
},
|
|
12
|
+
bg: {
|
|
13
|
+
|
|
14
|
+
},
|
|
15
|
+
decoration: {
|
|
16
|
+
dim: "\u001b[2m",
|
|
17
|
+
},
|
|
18
|
+
reset: "\u001b[0m",
|
|
19
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function removeFromArray<Type>(item: Type, array: Type[]) {
|
|
2
|
+
const index = array.indexOf(item);
|
|
3
|
+
if (index !== -1) {
|
|
4
|
+
array.splice(index, 1);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function randomFromArray<Type>(array: Type[]): Type {
|
|
9
|
+
return array[Math.floor(Math.random() * array.length)];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function removeDuplicatesFromArray<Type>(array: Type[]): Type[] {
|
|
13
|
+
return array.filter((item, index) => array.indexOf(item) === index);
|
|
14
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { HTMLAttributeAnchorTarget } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Simulates closing the viewport by opening a blank page
|
|
5
|
+
* @param name - Name of the app
|
|
6
|
+
*/
|
|
7
|
+
export function closeViewport(requireConfirmation: boolean = false, name: string) {
|
|
8
|
+
if (requireConfirmation && window.confirm(`Are you sure you want to shut down ${name}?`)) {
|
|
9
|
+
console.info("Closing viewport");
|
|
10
|
+
window.open("about:blank", "_self");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Reloads the viewport
|
|
16
|
+
*/
|
|
17
|
+
export function reloadViewport() {
|
|
18
|
+
console.info("Reloading viewport");
|
|
19
|
+
window.location.reload();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isValidUrl(string: string): boolean {
|
|
23
|
+
try {
|
|
24
|
+
new URL(string);
|
|
25
|
+
return true;
|
|
26
|
+
} catch (err) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function setViewportTitle(title: string) {
|
|
32
|
+
document.title = title;
|
|
33
|
+
|
|
34
|
+
document.querySelectorAll("meta[property='og:title'], meta[name='twitter:title']")?.forEach((element) => {
|
|
35
|
+
element.setAttribute("content", title);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function setViewportIcon(url: string) {
|
|
40
|
+
let link: HTMLLinkElement | null = document.querySelector("link[rel~='icon']");
|
|
41
|
+
if (link == null) {
|
|
42
|
+
link = document.createElement("link");
|
|
43
|
+
link.rel = "icon";
|
|
44
|
+
document.head.appendChild(link);
|
|
45
|
+
}
|
|
46
|
+
link.href = url;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getViewportParams(): Record<string, string> {
|
|
50
|
+
const query = window.location.search.slice(1);
|
|
51
|
+
|
|
52
|
+
const params: Record<string, string> = {};
|
|
53
|
+
query.split("&").forEach((param) => {
|
|
54
|
+
// For some reason, URI components only decode when decoded twice
|
|
55
|
+
// TO DO: Please find a fix, or create a custom function
|
|
56
|
+
const [key, value] = param.split("=").map((item) => decodeURIComponent(decodeURIComponent(item)));
|
|
57
|
+
params[key] = value;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return params;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface generateUrlOptions {
|
|
64
|
+
appId?: string;
|
|
65
|
+
fullscreen?: boolean;
|
|
66
|
+
standalone?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function generateUrl(options: generateUrlOptions) {
|
|
70
|
+
let baseUrl = window.location.origin + "/";
|
|
71
|
+
|
|
72
|
+
if (!options || Object.keys(options).length === 0)
|
|
73
|
+
return baseUrl;
|
|
74
|
+
|
|
75
|
+
const { appId, fullscreen, standalone, ...extraOptions } = options;
|
|
76
|
+
const params: URLSearchParams & { size?: number } = new URLSearchParams();
|
|
77
|
+
|
|
78
|
+
if (standalone && appId) {
|
|
79
|
+
baseUrl += appId;
|
|
80
|
+
} else {
|
|
81
|
+
if (appId)
|
|
82
|
+
params.set("app", appId);
|
|
83
|
+
if (fullscreen)
|
|
84
|
+
params.set("fullscreen", fullscreen.toString());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (extraOptions && Object.keys(extraOptions).length > 0) {
|
|
88
|
+
Object.entries(extraOptions).forEach(([key, value]) => {
|
|
89
|
+
if (key && value)
|
|
90
|
+
params.set(key, encodeURIComponent(value as string));
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (params.size === 0)
|
|
95
|
+
return baseUrl;
|
|
96
|
+
|
|
97
|
+
const url = `${baseUrl}?${params.toString()}`;
|
|
98
|
+
return url;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function openUrl(url: string, target?: HTMLAttributeAnchorTarget) {
|
|
102
|
+
window.open(url, target ?? "_blank");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function removeUrlProtocol(url: string) {
|
|
106
|
+
return url.replace(/^https?:\/\/|\/$/g, "");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function copyToClipboard(string: string, onSuccess?: (value: void) => void, onFail?: (value: void) => void) {
|
|
110
|
+
void navigator.clipboard.writeText(string).then(onSuccess, onFail);
|
|
111
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const TIME_INDICATORS = {
|
|
2
|
+
"s": 1000,
|
|
3
|
+
"m": 1000 * 60,
|
|
4
|
+
"h": 1000 * 60 * 60,
|
|
5
|
+
"d": 1000 * 60 * 60 * 24,
|
|
6
|
+
"w": 1000 * 60 * 60 * 24 * 7,
|
|
7
|
+
"n": 1000 * 60 * 60 * 24 * 31,
|
|
8
|
+
"y": 1000 * 60 * 60 * 24 * 365,
|
|
9
|
+
"c": 1000 * 60 * 60 * 24 * 365 * 100
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Format a time
|
|
14
|
+
* @param time - Time in milliseconds
|
|
15
|
+
* @param maxLength - The maximum amount of units, e.g.: 3 => years, months, days
|
|
16
|
+
*/
|
|
17
|
+
export function formatTime(time: number, maxLength: number = 3, allowAffixes: boolean): string {
|
|
18
|
+
const result: string[] = [];
|
|
19
|
+
|
|
20
|
+
const formatResult = (result: string[], inPast: boolean): string => {
|
|
21
|
+
if (!allowAffixes)
|
|
22
|
+
return result.join(", ");
|
|
23
|
+
|
|
24
|
+
let prefix = "";
|
|
25
|
+
let suffix = "";
|
|
26
|
+
|
|
27
|
+
if (inPast) {
|
|
28
|
+
suffix = "ago";
|
|
29
|
+
} else {
|
|
30
|
+
prefix = "in";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return [prefix, result.join(", "), suffix].join(" ").trim();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
let inPast = false;
|
|
37
|
+
|
|
38
|
+
if (time < 0) {
|
|
39
|
+
time = -time;
|
|
40
|
+
inPast = true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (Math.abs(time) < TIME_INDICATORS.s) {
|
|
44
|
+
return formatResult(["less than a second"], inPast);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const units: { amount: number, label: string }[] = [];
|
|
48
|
+
const unitLabels: Record<string, string> = {
|
|
49
|
+
"s": "seconds",
|
|
50
|
+
"m": "minutes",
|
|
51
|
+
"h": "hours",
|
|
52
|
+
"d": "days",
|
|
53
|
+
"n": "months",
|
|
54
|
+
"y": "years",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
for (const [key, value] of Object.entries(TIME_INDICATORS).reverse()) {
|
|
58
|
+
if (key === "w" || key === "c")
|
|
59
|
+
continue;
|
|
60
|
+
|
|
61
|
+
const amount = Math.floor(time / value);
|
|
62
|
+
time -= amount * value;
|
|
63
|
+
|
|
64
|
+
if (amount > 0)
|
|
65
|
+
units.push({ amount, label: unitLabels[key] });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (let i = 0; i < maxLength; i++) {
|
|
69
|
+
const unit = units[i];
|
|
70
|
+
|
|
71
|
+
if (unit)
|
|
72
|
+
result.push(`${unit.amount} ${unit.label}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (result.length === 0) {
|
|
76
|
+
return formatResult(["less than a second"], inPast);
|
|
77
|
+
} else {
|
|
78
|
+
return formatResult(result, inPast);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Format a time relative to now
|
|
84
|
+
* @param date - The date
|
|
85
|
+
* @param maxLength - The maximum amount of units, e.g.: 3 => years, months, days
|
|
86
|
+
*/
|
|
87
|
+
export function formatRelativeTime(date: Date, maxLength: number = 3, allowAffixes: boolean): string {
|
|
88
|
+
const difference = date.valueOf() - Date.now();
|
|
89
|
+
return formatTime(difference, maxLength, allowAffixes);
|
|
90
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type EventNamesMap = Record<string, string>;
|
|
2
|
+
|
|
3
|
+
export class EventEmitter<EventMap extends EventNamesMap> {
|
|
4
|
+
static EVENT_NAMES: EventNamesMap = {};
|
|
5
|
+
|
|
6
|
+
#events: Record<string, Array<Function>> = {};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Add event listener for an event
|
|
10
|
+
*/
|
|
11
|
+
on<Key extends keyof EventMap>(eventName: Key, callback: (data: unknown) => void) {
|
|
12
|
+
if (!this.#events[eventName as string]) {
|
|
13
|
+
this.#events[eventName as string] = [];
|
|
14
|
+
}
|
|
15
|
+
this.#events[eventName as string].push(callback);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Remove event listener for an event
|
|
20
|
+
*/
|
|
21
|
+
off<Key extends keyof EventMap>(eventName: Key, callback: (data: unknown) => void) {
|
|
22
|
+
if (this.#events[eventName as string]) {
|
|
23
|
+
this.#events[eventName as string] = this.#events[eventName as string].filter(
|
|
24
|
+
(listener) => listener !== callback
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Dispatch event
|
|
31
|
+
*/
|
|
32
|
+
emit<Key extends keyof EventMap>(eventName: Key, data?: unknown) {
|
|
33
|
+
if (this.#events[eventName as string]) {
|
|
34
|
+
this.#events[eventName as string].forEach((listener) => {
|
|
35
|
+
listener(data);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function clamp(value: number, min: number, max: number): number {
|
|
2
|
+
if (value < min) {
|
|
3
|
+
return min;
|
|
4
|
+
} else if (value > max) {
|
|
5
|
+
return max;
|
|
6
|
+
} else {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function randomRange(min: number, max: number): number {
|
|
12
|
+
return Math.random() * (max - min) + min;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function round(value: number, precision: number): number {
|
|
16
|
+
const multiplier = Math.pow(10, precision || 0);
|
|
17
|
+
return Math.round(value * multiplier) / multiplier;
|
|
18
|
+
}
|