@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,31 @@
|
|
|
1
|
+
export function formatShortcut(shortcut: string[]): string {
|
|
2
|
+
const specialKeys: string[] = [];
|
|
3
|
+
const singleKeys: string[] = [];
|
|
4
|
+
|
|
5
|
+
shortcut.forEach((key) => {
|
|
6
|
+
if (key.length > 1) {
|
|
7
|
+
switch (key) {
|
|
8
|
+
case "Control":
|
|
9
|
+
specialKeys.push("Ctrl");
|
|
10
|
+
break;
|
|
11
|
+
default:
|
|
12
|
+
specialKeys.push(key);
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
switch (key) {
|
|
17
|
+
case "+":
|
|
18
|
+
singleKeys.push("Plus");
|
|
19
|
+
break;
|
|
20
|
+
case "-":
|
|
21
|
+
singleKeys.push("Minus");
|
|
22
|
+
break;
|
|
23
|
+
default:
|
|
24
|
+
singleKeys.push(key.toUpperCase());
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return specialKeys.concat(singleKeys).join("+");
|
|
31
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { formatRelativeTime } from "./date.utils";
|
|
2
|
+
|
|
3
|
+
export class TimeManager {
|
|
4
|
+
static startDate: Date;
|
|
5
|
+
|
|
6
|
+
static reset() {
|
|
7
|
+
TimeManager.startDate = new Date();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static getUptime(precision = 2) {
|
|
11
|
+
return formatRelativeTime(TimeManager.startDate, precision, false);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./system/configs";
|
|
2
|
+
export * from "./virtual-drive";
|
|
3
|
+
export * from "./_utils";
|
|
4
|
+
|
|
5
|
+
export { ModalsManager } from "./modals/modalsManager";
|
|
6
|
+
export { SettingsManager } from "./settings/settingsManager";
|
|
7
|
+
export { StorageManager } from "./storage/storageManager";
|
|
8
|
+
export { TrackingManager } from "./tracking/trackingManager";
|
|
9
|
+
export { WindowsManager } from "./windows/windowsManager";
|
|
10
|
+
export { ZIndexManager } from "./z-index/zIndexManager";
|
|
11
|
+
|
|
12
|
+
export { Vector2 } from "./math/vector2";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export class Vector2 {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
|
|
5
|
+
static get ZERO() {
|
|
6
|
+
return new Vector2(0, 0);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
get clone() {
|
|
10
|
+
return new Vector2(this.x, this.y);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(x: number, y?: number) {
|
|
14
|
+
this.x = x;
|
|
15
|
+
this.y = y ?? x;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
round(): Vector2 {
|
|
19
|
+
this.x = Math.round(this.x);
|
|
20
|
+
this.y = Math.round(this.y);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getDistance(x: number, y?: number): number;
|
|
25
|
+
getDistance(vector2: Vector2): number;
|
|
26
|
+
|
|
27
|
+
getDistance(x: unknown, y?: unknown): number {
|
|
28
|
+
let deltaX = 0, deltaY = 0;
|
|
29
|
+
|
|
30
|
+
if (x instanceof Vector2) {
|
|
31
|
+
const vector2 = x;
|
|
32
|
+
deltaX = this.x - vector2.x;
|
|
33
|
+
deltaY = this.y - vector2.y;
|
|
34
|
+
} else {
|
|
35
|
+
deltaX = this.x - (x as number);
|
|
36
|
+
deltaY = this.y - (y as number);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static add(vector2A: Vector2, vector2B: Vector2) {
|
|
43
|
+
return new Vector2(vector2A.x + vector2B.x, vector2A.y + vector2B.y);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static subtract(vector2A: Vector2, vector2B: Vector2) {
|
|
47
|
+
return new Vector2(vector2A.x - vector2B.x, vector2A.y - vector2B.y);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static scale(vector2: Vector2, scalar: number) {
|
|
51
|
+
return new Vector2(vector2.x * scalar, vector2.y * scalar);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static magnitude(vector2: Vector2) {
|
|
55
|
+
return Math.sqrt(vector2.x * vector2.x + vector2.y * vector2.y);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static normalize(vector2: Vector2) {
|
|
59
|
+
const magnitude = Vector2.magnitude(vector2);
|
|
60
|
+
return magnitude === 0 ? Vector2.ZERO : Vector2.scale(vector2, 1 / magnitude);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static sqrDistance(vector2A: Vector2, vector2B: Vector2) {
|
|
64
|
+
const dx = vector2A.x - vector2B.x;
|
|
65
|
+
const dy = vector2A.y - vector2B.y;
|
|
66
|
+
return dx * dx + dy * dy;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static lerp(vector2A: Vector2, vector2B: Vector2, t: number) {
|
|
70
|
+
return new Vector2(
|
|
71
|
+
vector2A.x + (vector2B.x - vector2A.x) * t,
|
|
72
|
+
vector2A.y + (vector2B.y - vector2A.y) * t
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { Vector2 } from "../math/vector2";
|
|
3
|
+
import { ModalsManager } from "./modalsManager";
|
|
4
|
+
import { ModalProps } from "../../components/modals/ModalView";
|
|
5
|
+
|
|
6
|
+
export class Modal {
|
|
7
|
+
size: Vector2 = new Vector2(400, 200);
|
|
8
|
+
position: Vector2 = new Vector2(300, 300);
|
|
9
|
+
icon: string | null = null;
|
|
10
|
+
title: string | null = null;
|
|
11
|
+
modalsManager: ModalsManager | null = null;
|
|
12
|
+
element: FC<ModalProps> | null = null;
|
|
13
|
+
props: object = {};
|
|
14
|
+
callback: Function | null = null;
|
|
15
|
+
id: number | null = null;
|
|
16
|
+
dismissible: boolean = true;
|
|
17
|
+
lastInteraction?: number;
|
|
18
|
+
|
|
19
|
+
constructor(element: Modal["element"], callback?: Modal["callback"]) {
|
|
20
|
+
this.element = element;
|
|
21
|
+
this.callback = callback as Modal["element"];
|
|
22
|
+
this.focus();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setIcon(icon: string): Modal {
|
|
26
|
+
this.icon = icon;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setTitle(title: string): Modal {
|
|
31
|
+
this.title = title;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
setPosition(position: Vector2): Modal {
|
|
36
|
+
this.position = position;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
setSize(size: Vector2): Modal {
|
|
41
|
+
this.size = size;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setProps(props: object): Modal {
|
|
46
|
+
this.props = props;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {boolean} dismissible
|
|
52
|
+
* @returns {Modal}
|
|
53
|
+
*/
|
|
54
|
+
setDismissible(dismissible: boolean): Modal {
|
|
55
|
+
this.dismissible = dismissible;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
focus() {
|
|
60
|
+
this.lastInteraction = Date.now();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
finish(...args: unknown[]) {
|
|
64
|
+
if (this.modalsManager == null || this.id == null)
|
|
65
|
+
return;
|
|
66
|
+
|
|
67
|
+
this.modalsManager.close(this.id);
|
|
68
|
+
this.callback?.(...args);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
close() {
|
|
72
|
+
this.finish();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { MutableRefObject } from "react";
|
|
2
|
+
import { Modal } from "./modal";
|
|
3
|
+
|
|
4
|
+
export class ModalsManager {
|
|
5
|
+
modals: Record<string, Modal> = {};
|
|
6
|
+
containerRef?: MutableRefObject<HTMLElement>;
|
|
7
|
+
updateModals: Function = () => {};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param single - Set to false to preserve other open modals
|
|
11
|
+
*/
|
|
12
|
+
open(modal: Modal, single: boolean = true) {
|
|
13
|
+
if (single) {
|
|
14
|
+
this.modalIds.forEach((id) => {
|
|
15
|
+
this.close(id, false);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let id = 0;
|
|
20
|
+
while (this.modalIds.includes(id.toString())) {
|
|
21
|
+
id++;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
modal.id = id;
|
|
25
|
+
modal.modalsManager = this;
|
|
26
|
+
|
|
27
|
+
console.info(`Opening modal ${id}`);
|
|
28
|
+
this.modals[id] = modal;
|
|
29
|
+
this.updateModals(this.modals);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
close(modalId: string | number, sendModalsUpdate: boolean = true) {
|
|
33
|
+
modalId = modalId.toString();
|
|
34
|
+
|
|
35
|
+
if (!this.modalIds.includes(modalId)) {
|
|
36
|
+
console.warn(`Failed to close modal ${modalId}: modal not found`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.info(`Closing modal ${modalId}`);
|
|
41
|
+
delete this.modals[modalId];
|
|
42
|
+
|
|
43
|
+
if (sendModalsUpdate)
|
|
44
|
+
this.updateModals(this.modals);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
focus(modalId: string) {
|
|
48
|
+
modalId = modalId.toString();
|
|
49
|
+
|
|
50
|
+
if (!this.modalIds.includes(modalId)) {
|
|
51
|
+
console.warn(`Failed to focus modal ${modalId}: modal not found`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const modal = this.modals[modalId];
|
|
56
|
+
modal.focus();
|
|
57
|
+
|
|
58
|
+
this.updateModals(this.modals);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
setUpdateModals(updateModals: Function) {
|
|
62
|
+
this.updateModals = updateModals;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get modalIds(): string[] {
|
|
66
|
+
return Object.keys(this.modals);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static getModalIconUrl(name: string): string {
|
|
70
|
+
return `/assets/modals/icons/${name}.svg`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { VirtualFile } from "../virtual-drive/file";
|
|
2
|
+
import { VirtualRoot } from "../virtual-drive/root/virtualRoot";
|
|
3
|
+
|
|
4
|
+
const PARENT_NODE = "options";
|
|
5
|
+
|
|
6
|
+
export class Settings {
|
|
7
|
+
path: string;
|
|
8
|
+
file: VirtualFile;
|
|
9
|
+
xmlDoc?: Document;
|
|
10
|
+
#virtualRoot?: VirtualRoot;
|
|
11
|
+
|
|
12
|
+
constructor(virtualRoot: VirtualRoot, path: string) {
|
|
13
|
+
this.#virtualRoot = virtualRoot;
|
|
14
|
+
this.path = path;
|
|
15
|
+
this.file = this.#virtualRoot.navigate(this.path) as VirtualFile;
|
|
16
|
+
|
|
17
|
+
if (this.file == null) {
|
|
18
|
+
console.warn(`Unable to read settings from path: ${this.path}\nNo such file or directory.`);
|
|
19
|
+
return;
|
|
20
|
+
} else if (!(this.file instanceof VirtualFile)) {
|
|
21
|
+
console.warn(`Unable to read settings from path: ${this.path}\nPath does not point to VirtualFile.`);
|
|
22
|
+
return;
|
|
23
|
+
} else if (this.file.extension !== "xml") {
|
|
24
|
+
console.warn(`Unable to read settings from path: ${this.path}\nFile does not have extension "xml".`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Reads the xml doc from the given path and assigns it to itself
|
|
31
|
+
*/
|
|
32
|
+
async read(): Promise<void> {
|
|
33
|
+
if (!this.file)
|
|
34
|
+
return;
|
|
35
|
+
|
|
36
|
+
const text = await this.file.read();
|
|
37
|
+
|
|
38
|
+
if (!text)
|
|
39
|
+
return;
|
|
40
|
+
|
|
41
|
+
const parser = new DOMParser();
|
|
42
|
+
const xmlDoc = parser.parseFromString(text, "text/xml");
|
|
43
|
+
|
|
44
|
+
this.xmlDoc = xmlDoc;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
write() {
|
|
48
|
+
if (this.file == null || this.xmlDoc == null)
|
|
49
|
+
return;
|
|
50
|
+
|
|
51
|
+
const serializer = new XMLSerializer();
|
|
52
|
+
const xmlString = serializer.serializeToString(this.xmlDoc);
|
|
53
|
+
|
|
54
|
+
this.file.setContent(xmlString);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Checks if xml doc is missing
|
|
59
|
+
*/
|
|
60
|
+
async isMissingXmlDoc(): Promise<boolean> {
|
|
61
|
+
if (this.xmlDoc == null)
|
|
62
|
+
await this.read();
|
|
63
|
+
|
|
64
|
+
return (this.xmlDoc == null);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Gets a value by a given key if it exists or calls a callback function whenever the value changes
|
|
69
|
+
*/
|
|
70
|
+
async get(key: string, callback?: (value: string) => void): Promise<string | null> {
|
|
71
|
+
if (await this.isMissingXmlDoc())
|
|
72
|
+
return null;
|
|
73
|
+
|
|
74
|
+
let value = this.xmlDoc?.getElementsByTagName(key)?.[0]?.textContent as string | null;
|
|
75
|
+
|
|
76
|
+
if (callback) {
|
|
77
|
+
if (value != null) callback(value);
|
|
78
|
+
|
|
79
|
+
this.file.on(VirtualFile.EVENT_NAMES.CONTENT_CHANGE, () => {
|
|
80
|
+
void (async () => {
|
|
81
|
+
await this.read();
|
|
82
|
+
const newValue = await this.get(key);
|
|
83
|
+
|
|
84
|
+
if (newValue != null && newValue !== value) {
|
|
85
|
+
callback(newValue);
|
|
86
|
+
value = newValue;
|
|
87
|
+
}
|
|
88
|
+
})();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async set(key: string, value: string) {
|
|
96
|
+
if (await this.isMissingXmlDoc() || this.xmlDoc == null)
|
|
97
|
+
return;
|
|
98
|
+
|
|
99
|
+
if (this.xmlDoc.getElementsByTagName(key).length > 0) {
|
|
100
|
+
this.xmlDoc.getElementsByTagName(key)[0].textContent = value;
|
|
101
|
+
} else if (this.xmlDoc.getElementsByTagName(PARENT_NODE).length > 0) {
|
|
102
|
+
const newOption = this.xmlDoc.createElement(key);
|
|
103
|
+
newOption.textContent = value;
|
|
104
|
+
this.xmlDoc.getElementsByTagName(PARENT_NODE)[0].appendChild(newOption);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.write();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { VirtualRoot } from "../virtual-drive/root/virtualRoot";
|
|
2
|
+
import { Settings } from "./settings";
|
|
3
|
+
|
|
4
|
+
export class SettingsManager {
|
|
5
|
+
static VIRTUAL_PATHS: { [s: string]: string; } = {
|
|
6
|
+
desktop: "~/.config/desktop.xml",
|
|
7
|
+
taskbar: "~/.config/taskbar.xml",
|
|
8
|
+
apps: "~/.config/apps.xml",
|
|
9
|
+
theme: "~/.config/theme.xml"
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
#pathToSettings: { [s: string]: Settings; } = {};
|
|
13
|
+
|
|
14
|
+
#virtualRoot: VirtualRoot | null = null;
|
|
15
|
+
|
|
16
|
+
constructor(virtualRoot: VirtualRoot) {
|
|
17
|
+
this.#virtualRoot = virtualRoot;
|
|
18
|
+
|
|
19
|
+
if (this.#virtualRoot == null) {
|
|
20
|
+
throw new Error("SettingsManager is missing VirtualRoot"); // Why does this sound so sad :'(
|
|
21
|
+
} else {
|
|
22
|
+
Object.values(SettingsManager.VIRTUAL_PATHS).forEach((path) => {
|
|
23
|
+
this.#pathToSettings[path] = new Settings(this.#virtualRoot as VirtualRoot, path);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getSettings(path: string): Settings {
|
|
29
|
+
return this.#pathToSettings[path];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class StorageManager {
|
|
2
|
+
static MAX_BYTES = 5_000_000;
|
|
3
|
+
|
|
4
|
+
static store(key: string, value: string) {
|
|
5
|
+
if (key == null || value == null)
|
|
6
|
+
return;
|
|
7
|
+
|
|
8
|
+
const exceededMaxStorage = this.getByteSize(value) > this.MAX_BYTES;
|
|
9
|
+
|
|
10
|
+
if (exceededMaxStorage)
|
|
11
|
+
throw new Error("Failed to store value: storage capacity exceeded.");
|
|
12
|
+
|
|
13
|
+
localStorage.setItem(key, value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static load(key: string): string | null {
|
|
17
|
+
if (key == null)
|
|
18
|
+
return null;
|
|
19
|
+
|
|
20
|
+
return localStorage.getItem(key);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static clear() {
|
|
24
|
+
localStorage.clear();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static getByteSize(string: string | null): number {
|
|
28
|
+
if (string == null) return 0;
|
|
29
|
+
return new Blob([string]).size;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static byteToKilobyte(bytes: number): number {
|
|
33
|
+
return bytes / 1000;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Vector2 } from "../../math/vector2";
|
|
2
|
+
import { WindowProps } from "../../../components/windows/WindowView";
|
|
3
|
+
import { FC } from "react";
|
|
4
|
+
|
|
5
|
+
const validIdRegex = /^[a-zA-Z0-9-]+$/;
|
|
6
|
+
|
|
7
|
+
export class App<AppProps extends WindowProps = WindowProps> {
|
|
8
|
+
name: string = "App";
|
|
9
|
+
id: string = "app";
|
|
10
|
+
windowContent: FC<AppProps>;
|
|
11
|
+
windowOptions?: {
|
|
12
|
+
size: Vector2;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
description: string | null = null;
|
|
17
|
+
iconUrl: string | null = null;
|
|
18
|
+
|
|
19
|
+
isActive: boolean = false;
|
|
20
|
+
isPinned?: boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param windowOptions - Default window options
|
|
24
|
+
*/
|
|
25
|
+
constructor(name: App["name"], id: App["id"], windowContent: App<AppProps>["windowContent"], windowOptions?: App["windowOptions"]) {
|
|
26
|
+
this.name = name;
|
|
27
|
+
this.id = id;
|
|
28
|
+
this.windowContent = windowContent;
|
|
29
|
+
this.windowOptions = windowOptions;
|
|
30
|
+
|
|
31
|
+
if (this.id.match(validIdRegex) == null)
|
|
32
|
+
throw new Error(`Invalid app ID found: ${this.id}`
|
|
33
|
+
+ "\nApp IDs may only contain letters (a-zA-Z), numbers (0-9) and dashes (-).");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
WindowContent = (props: AppProps) => {
|
|
37
|
+
props = { ...props, ...this.windowOptions };
|
|
38
|
+
|
|
39
|
+
if (this.windowContent == null) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return <this.windowContent {...props}/>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
setDescription(description: App["description"]): this {
|
|
47
|
+
this.description = description;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setIconUrl(iconUrl: App["iconUrl"]): this {
|
|
52
|
+
this.iconUrl = iconUrl;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setName(name: string): this {
|
|
57
|
+
this.name = name;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { App } from ".";
|
|
2
|
+
import { OptionalInterface } from "../../../types/util";
|
|
3
|
+
|
|
4
|
+
export interface AppsConfigOptions {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
apps: App<any>[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class AppsConfig {
|
|
10
|
+
apps: AppsConfigOptions["apps"] = [];
|
|
11
|
+
|
|
12
|
+
constructor(options: OptionalInterface<AppsConfigOptions> = {}) {
|
|
13
|
+
const { apps } = options as AppsConfigOptions;
|
|
14
|
+
|
|
15
|
+
if (apps != null) {
|
|
16
|
+
const appIds: string[] = [];
|
|
17
|
+
apps.forEach((app) => {
|
|
18
|
+
if (appIds.includes(app.id))
|
|
19
|
+
throw new Error(`Duplicate app ID found: ${app.id}`
|
|
20
|
+
+ "\nApp IDs must be unique.");
|
|
21
|
+
|
|
22
|
+
this.apps.push(app);
|
|
23
|
+
appIds.push(app.id);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getAppById(id: string): App | null {
|
|
29
|
+
let resultApp: App | null = null;
|
|
30
|
+
|
|
31
|
+
this.apps.forEach((app) => {
|
|
32
|
+
if (app.id === id) {
|
|
33
|
+
resultApp = app;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return resultApp;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get the app associated with a file extension
|
|
43
|
+
*/
|
|
44
|
+
getAppByFileExtension(fileExtension: string): App | null {
|
|
45
|
+
return null;
|
|
46
|
+
|
|
47
|
+
// let app: App | null = null;
|
|
48
|
+
|
|
49
|
+
// if (IMAGE_FORMATS.includes(fileExtension))
|
|
50
|
+
// return this.getAppById(APPS.MEDIA_VIEWER);
|
|
51
|
+
|
|
52
|
+
// switch (fileExtension) {
|
|
53
|
+
// default:
|
|
54
|
+
// app = this.getAppById(APPS.TEXT_EDITOR);
|
|
55
|
+
// break;
|
|
56
|
+
// }
|
|
57
|
+
|
|
58
|
+
// return app;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { OptionalInterface } from "../../../types/util";
|
|
2
|
+
|
|
3
|
+
export interface DesktopConfigOptions {
|
|
4
|
+
/** Array of URLs of wallpaper images */
|
|
5
|
+
wallpapers: string[];
|
|
6
|
+
|
|
7
|
+
/** URL of default wallpaper image */
|
|
8
|
+
defaultWallpaper: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @default 1
|
|
12
|
+
*/
|
|
13
|
+
defaultIconSize: 0 | 1 | 2;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @description 0: vertical, 1: horizontal
|
|
17
|
+
* @default 0
|
|
18
|
+
* */
|
|
19
|
+
defaultIconDirection: 0 | 1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class DesktopConfig {
|
|
23
|
+
wallpapers: DesktopConfigOptions["wallpapers"];
|
|
24
|
+
defaultWallpaper: DesktopConfigOptions["defaultWallpaper"];
|
|
25
|
+
defaultIconSize: DesktopConfigOptions["defaultIconSize"];
|
|
26
|
+
defaultIconDirection: DesktopConfigOptions["defaultIconDirection"];
|
|
27
|
+
|
|
28
|
+
constructor(options: OptionalInterface<DesktopConfigOptions> = {}) {
|
|
29
|
+
const { wallpapers, defaultWallpaper, defaultIconSize, defaultIconDirection } = options as DesktopConfigOptions;
|
|
30
|
+
|
|
31
|
+
this.wallpapers = wallpapers ?? [
|
|
32
|
+
"https://os.prozilla.dev/assets/wallpapers/vibrant-wallpaper-blue-purple-red.png",
|
|
33
|
+
"https://os.prozilla.dev/assets/wallpapers/abstract-mesh-gradient-orange-red-purple.png",
|
|
34
|
+
"https://os.prozilla.dev/assets/wallpapers/vibrant-wallpaper-purple-yellow.png",
|
|
35
|
+
"https://os.prozilla.dev/assets/wallpapers/abstract-wallpaper-mesh-gradient-cyan.png",
|
|
36
|
+
"https://os.prozilla.dev/assets/wallpapers/colorful-abstract-wallpaper-blue-red-green.png",
|
|
37
|
+
"https://os.prozilla.dev/assets/wallpapers/mesh-gradient-wallpaper-red-purple.png",
|
|
38
|
+
"https://os.prozilla.dev/assets/wallpapers/colorful-mesh-gradient-red-green.png",
|
|
39
|
+
"https://os.prozilla.dev/assets/wallpapers/flame-abstract-wallpaper-orange.png",
|
|
40
|
+
"https://os.prozilla.dev/assets/wallpapers/wave-abstract-wallpaper-teal.png",
|
|
41
|
+
];
|
|
42
|
+
this.defaultWallpaper = defaultWallpaper ?? "https://os.prozilla.dev/assets/wallpapers/vibrant-wallpaper-blue-purple-red.png";
|
|
43
|
+
this.defaultIconSize = defaultIconSize ?? 1;
|
|
44
|
+
this.defaultIconDirection = defaultIconDirection ?? 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { App } from "./app";
|
|
2
|
+
export { AppsConfig } from "./appsConfig";
|
|
3
|
+
export { DesktopConfig } from "./desktopConfig";
|
|
4
|
+
export { MiscConfig } from "./miscConfig";
|
|
5
|
+
export { ModalsConfig } from "./modalsConfig";
|
|
6
|
+
export { TaskbarConfig } from "./taskbarConfig";
|
|
7
|
+
export { TrackingConfig } from "./trackingConfig";
|
|
8
|
+
export { WindowsConfig } from "./windowsConfig";
|
|
9
|
+
export { VirtualDriveConfig } from "./virtualDriveConfig";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OptionalInterface } from "../../../types/util";
|
|
2
|
+
|
|
3
|
+
export interface MiscConfigOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The maximum time between two clicks to register as a double click (in ms)
|
|
6
|
+
* @default 250
|
|
7
|
+
* */
|
|
8
|
+
doubleClickDelay: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class MiscConfig {
|
|
12
|
+
doubleClickDelay: MiscConfigOptions["doubleClickDelay"];
|
|
13
|
+
|
|
14
|
+
constructor(options: OptionalInterface<MiscConfigOptions> = {}) {
|
|
15
|
+
const { doubleClickDelay } = options as MiscConfigOptions;
|
|
16
|
+
|
|
17
|
+
this.doubleClickDelay = doubleClickDelay ?? 250;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { OptionalInterface } from "../../../types/util";
|
|
2
|
+
import { Vector2 } from "../../math/vector2";
|
|
3
|
+
|
|
4
|
+
export interface ModalsConfigOptions {
|
|
5
|
+
/**
|
|
6
|
+
* @description Default size of a dialog box
|
|
7
|
+
* @default new Vector2(400, 200)
|
|
8
|
+
*/
|
|
9
|
+
defaultDialogSize: Vector2;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @description Default size of a file selector
|
|
13
|
+
* @default new Vector2(700, 400)
|
|
14
|
+
*/
|
|
15
|
+
defaultFileSelectorSize: Vector2;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class ModalsConfig {
|
|
19
|
+
defaultDialogSize: ModalsConfigOptions["defaultDialogSize"];
|
|
20
|
+
defaultFileSelectorSize: ModalsConfigOptions["defaultFileSelectorSize"];
|
|
21
|
+
|
|
22
|
+
constructor(options: OptionalInterface<ModalsConfigOptions> = {}) {
|
|
23
|
+
const { defaultDialogSize, defaultFileSelectorSize } = options as ModalsConfigOptions;
|
|
24
|
+
|
|
25
|
+
this.defaultDialogSize = defaultDialogSize ?? new Vector2(400, 200);
|
|
26
|
+
this.defaultFileSelectorSize = defaultFileSelectorSize ?? new Vector2(700, 400);
|
|
27
|
+
}
|
|
28
|
+
}
|