@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,244 @@
|
|
|
1
|
+
import { StorageManager } from "../../storage/storageManager";
|
|
2
|
+
import { VirtualFolderLink, VirtualFolderLinkJson } from "../folder/virtualFolderLink";
|
|
3
|
+
import { loadDefaultData } from "./defaultData";
|
|
4
|
+
import { VirtualFileJson } from "../file/virtualFile";
|
|
5
|
+
import { VirtualFolder } from "../folder";
|
|
6
|
+
import { VirtualFileLinkJson } from "../file/virtualFileLink";
|
|
7
|
+
import { VirtualFolderJson } from "../folder/virtualFolder";
|
|
8
|
+
import { VirtualFile, VirtualFileLink } from "../file";
|
|
9
|
+
import { SystemManager } from "../../system/systemManager";
|
|
10
|
+
|
|
11
|
+
export interface VirtualRootJson extends VirtualFolderJson {
|
|
12
|
+
scs: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A virtual folder that serves as the root folder
|
|
17
|
+
*/
|
|
18
|
+
export class VirtualRoot extends VirtualFolder {
|
|
19
|
+
shortcuts: Record<string, VirtualFile | VirtualFileLink | VirtualFolder | VirtualFolderLink>;
|
|
20
|
+
initiated: boolean = false;
|
|
21
|
+
loadedDefaultData: boolean = false;
|
|
22
|
+
systemManager: SystemManager;
|
|
23
|
+
|
|
24
|
+
static EVENT_NAMES = {
|
|
25
|
+
ERROR: "error"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
constructor(systemManager: SystemManager) {
|
|
29
|
+
super("root");
|
|
30
|
+
this.root = this;
|
|
31
|
+
this.systemManager = systemManager;
|
|
32
|
+
this.isRoot = true;
|
|
33
|
+
this.shortcuts = {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
loadDefaultData() {
|
|
37
|
+
loadDefaultData(this.systemManager, this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
loadData() {
|
|
41
|
+
const data = StorageManager.load("data");
|
|
42
|
+
if (data == null)
|
|
43
|
+
return;
|
|
44
|
+
|
|
45
|
+
let object: VirtualRootJson | null = null;
|
|
46
|
+
try {
|
|
47
|
+
object = JSON.parse(data) as VirtualRootJson;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(error);
|
|
50
|
+
}
|
|
51
|
+
if (object == null)
|
|
52
|
+
return;
|
|
53
|
+
|
|
54
|
+
const shortcuts = { ...object.scs } as Record<string, string>;
|
|
55
|
+
|
|
56
|
+
const addFile = ({
|
|
57
|
+
nam: name,
|
|
58
|
+
ext: extension,
|
|
59
|
+
src: source,
|
|
60
|
+
cnt: content,
|
|
61
|
+
lnk: link,
|
|
62
|
+
ico: iconUrl,
|
|
63
|
+
}: VirtualFileJson & VirtualFileLinkJson, parent: VirtualFolder = this) => {
|
|
64
|
+
if (link) {
|
|
65
|
+
parent.createFileLink(name, (fileLink) => {
|
|
66
|
+
(fileLink as VirtualFileLink).setLinkedPath(link);
|
|
67
|
+
if (iconUrl != null) {
|
|
68
|
+
fileLink.setIconUrl(iconUrl);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
parent.createFile(name, extension, (file: VirtualFile) => {
|
|
75
|
+
if (source != null) {
|
|
76
|
+
file.setSource(source);
|
|
77
|
+
} else if (content != null) {
|
|
78
|
+
file.setContent(content);
|
|
79
|
+
}
|
|
80
|
+
if (iconUrl != null) {
|
|
81
|
+
file.setIconUrl(iconUrl);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const addFolder = ({
|
|
87
|
+
nam: name,
|
|
88
|
+
fds: folders,
|
|
89
|
+
fls: files,
|
|
90
|
+
lnk: link,
|
|
91
|
+
ico: iconUrl,
|
|
92
|
+
}: VirtualFolderJson & VirtualFolderLinkJson, parent: VirtualFolder = this) => {
|
|
93
|
+
if (link) {
|
|
94
|
+
parent.createFolderLink(name, (folderLink) => {
|
|
95
|
+
(folderLink as VirtualFolderLink).setLinkedPath(link);
|
|
96
|
+
if (iconUrl != null) {
|
|
97
|
+
folderLink.setIconUrl(iconUrl);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
parent.createFolder(name, (folder: VirtualFolder) => {
|
|
104
|
+
if (Object.values(shortcuts).includes(folder.displayPath)) {
|
|
105
|
+
let alias: string | null = null;
|
|
106
|
+
for (const [key, value] of Object.entries(shortcuts)) {
|
|
107
|
+
if (value === folder.displayPath)
|
|
108
|
+
alias = key;
|
|
109
|
+
}
|
|
110
|
+
if (alias != null) folder.setAlias(alias);
|
|
111
|
+
}
|
|
112
|
+
if (folders != null) {
|
|
113
|
+
folders.forEach((subFolder) => {
|
|
114
|
+
addFolder(subFolder as VirtualFolderJson & VirtualFolderLinkJson, folder);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (files != null) {
|
|
118
|
+
files.forEach((file) => {
|
|
119
|
+
addFile(file as VirtualFileJson & VirtualFileLinkJson, folder);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (iconUrl != null) {
|
|
123
|
+
folder.setIconUrl(iconUrl);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
if (object.fds != null) {
|
|
129
|
+
object.fds.forEach((subFolder) => {
|
|
130
|
+
addFolder(subFolder as VirtualFolderJson & VirtualFolderLinkJson);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (object.fls != null) {
|
|
134
|
+
object.fls.forEach((file) => {
|
|
135
|
+
addFile(file as VirtualFileJson & VirtualFileLinkJson);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Calls the storage manager's store function with this root's data as a string
|
|
142
|
+
*/
|
|
143
|
+
saveData() {
|
|
144
|
+
if (!this.initiated)
|
|
145
|
+
return;
|
|
146
|
+
|
|
147
|
+
const data = this.toString();
|
|
148
|
+
|
|
149
|
+
if (data == null)
|
|
150
|
+
return;
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
StorageManager.store("data", data);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
this.emit(VirtualRoot.EVENT_NAMES.ERROR, {
|
|
156
|
+
message: "Failed to save data"
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Initiates this root by loading the default data and then the user's data on top
|
|
163
|
+
*/
|
|
164
|
+
init(): VirtualRoot {
|
|
165
|
+
this.initiated = false;
|
|
166
|
+
|
|
167
|
+
// Load default data
|
|
168
|
+
this.loadedDefaultData = false;
|
|
169
|
+
this.setAlias("/");
|
|
170
|
+
this.loadDefaultData();
|
|
171
|
+
this.loadedDefaultData = true;
|
|
172
|
+
|
|
173
|
+
// Load user's data
|
|
174
|
+
this.loadData();
|
|
175
|
+
this.initiated = true;
|
|
176
|
+
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Adds a shortcut to a file or folder
|
|
182
|
+
*/
|
|
183
|
+
addShortcut(name: string, destination: VirtualFile | VirtualFileLink | VirtualFolder | VirtualFolderLink) {
|
|
184
|
+
this.shortcuts[name] = destination;
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Tells the storage manager to clear all data and reloads the window
|
|
190
|
+
*/
|
|
191
|
+
reset() {
|
|
192
|
+
if (window.confirm("Are you sure you want to reset all your data?")) {
|
|
193
|
+
StorageManager.clear();
|
|
194
|
+
window.location.reload();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
static isValidName(_name: string) {
|
|
199
|
+
// TO DO
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
static isValidFileName(_name: string) {
|
|
203
|
+
// TO DO
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static isValidFolderName(_name: string) {
|
|
207
|
+
// TO DO
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
get path() {
|
|
211
|
+
return "";
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
get displayPath() {
|
|
215
|
+
return "/";
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
toJSON(): VirtualRootJson | null {
|
|
219
|
+
const object = super.toJSON() as VirtualRootJson;
|
|
220
|
+
|
|
221
|
+
if (object == null)
|
|
222
|
+
return null;
|
|
223
|
+
|
|
224
|
+
if (Object.entries(this.shortcuts).length > 0) {
|
|
225
|
+
object.scs = {};
|
|
226
|
+
|
|
227
|
+
for (const [key, value] of Object.entries(this.shortcuts)) {
|
|
228
|
+
if (!value.root)
|
|
229
|
+
object.scs[key] = value.absolutePath;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return object;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
toString(): string | null {
|
|
237
|
+
const json = this.toJSON();
|
|
238
|
+
|
|
239
|
+
if (json == null)
|
|
240
|
+
return null;
|
|
241
|
+
|
|
242
|
+
return JSON.stringify(json);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { EventEmitter, EventNamesMap } from "../_utils/event.utils";
|
|
2
|
+
import { VirtualRoot } from "./root/virtualRoot";
|
|
3
|
+
import { VirtualFile } from "./file";
|
|
4
|
+
import { VirtualFolder } from "./folder";
|
|
5
|
+
|
|
6
|
+
export interface VirtualBaseJson {
|
|
7
|
+
nam: string;
|
|
8
|
+
ico?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class VirtualBase extends EventEmitter<EventNamesMap> {
|
|
12
|
+
name: string;
|
|
13
|
+
alias: string | undefined | null;
|
|
14
|
+
parent: VirtualFolder | undefined | null;
|
|
15
|
+
isProtected: boolean | undefined | null;
|
|
16
|
+
iconUrl: string | undefined | null;
|
|
17
|
+
linkedFile: VirtualFile | undefined | null;
|
|
18
|
+
linkedFolder: VirtualFolder | undefined | null;
|
|
19
|
+
editedByUser: boolean | undefined | null;
|
|
20
|
+
isRoot: boolean | undefined | null;
|
|
21
|
+
root: VirtualRoot | undefined | null;
|
|
22
|
+
|
|
23
|
+
constructor(name: string) {
|
|
24
|
+
super();
|
|
25
|
+
this.name = name;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get id() {
|
|
29
|
+
return this.name;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
setName(name: string): this {
|
|
33
|
+
if (this.name === name || !this.canBeEdited)
|
|
34
|
+
return this;
|
|
35
|
+
|
|
36
|
+
this.name = name;
|
|
37
|
+
|
|
38
|
+
this.confirmChanges();
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setAlias(alias: string): this {
|
|
43
|
+
if (this.alias === alias || !this.canBeEdited)
|
|
44
|
+
return this;;
|
|
45
|
+
|
|
46
|
+
this.alias = alias;
|
|
47
|
+
this.getRoot().addShortcut(alias, this as never);
|
|
48
|
+
|
|
49
|
+
this.confirmChanges();
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setParent(parent: VirtualFolder): this {
|
|
54
|
+
if (this.parent === parent || !this.canBeEdited)
|
|
55
|
+
return this;
|
|
56
|
+
|
|
57
|
+
this.parent = parent;
|
|
58
|
+
|
|
59
|
+
this.confirmChanges();
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
setProtected(value: boolean): this {
|
|
64
|
+
if (!this.canBeEdited)
|
|
65
|
+
return this;
|
|
66
|
+
|
|
67
|
+
this.isProtected = value;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setIconUrl(iconUrl: string | null): this {
|
|
72
|
+
if (this.iconUrl === iconUrl || !this.canBeEdited)
|
|
73
|
+
return this;
|
|
74
|
+
|
|
75
|
+
this.iconUrl = iconUrl;
|
|
76
|
+
|
|
77
|
+
this.confirmChanges();
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getIconUrl(): string {
|
|
82
|
+
if (this.iconUrl != null) return this.iconUrl;
|
|
83
|
+
if (this.linkedFile?.iconUrl != null) return this.linkedFile.iconUrl;
|
|
84
|
+
if (this.linkedFolder?.iconUrl != null) return this.linkedFolder.iconUrl;
|
|
85
|
+
|
|
86
|
+
const { virtualDriveConfig } = this.getRoot().systemManager;
|
|
87
|
+
return virtualDriveConfig.fileIcon;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getType(): string {
|
|
91
|
+
return "None";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
delete() {
|
|
95
|
+
if (!this.canBeEdited)
|
|
96
|
+
return;
|
|
97
|
+
|
|
98
|
+
const parent = this.parent;
|
|
99
|
+
|
|
100
|
+
if (parent == null)
|
|
101
|
+
return;
|
|
102
|
+
|
|
103
|
+
parent.remove?.(this as never);
|
|
104
|
+
this.confirmChanges(parent.getRoot());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
confirmChanges(root?: VirtualRoot) {
|
|
108
|
+
if (root == null)
|
|
109
|
+
root = this.getRoot();
|
|
110
|
+
|
|
111
|
+
if (root?.loadedDefaultData)
|
|
112
|
+
this.editedByUser = true;
|
|
113
|
+
|
|
114
|
+
root?.saveData();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
open(..._args: unknown[]): unknown {
|
|
118
|
+
return null;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
get path(): string {
|
|
122
|
+
return this.alias ?? this.displayPath;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Returns path without using alias
|
|
127
|
+
*/
|
|
128
|
+
get displayPath() {
|
|
129
|
+
return this.parent?.path + "/" + this.id;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns path without using any aliases
|
|
134
|
+
*/
|
|
135
|
+
get absolutePath(): string {
|
|
136
|
+
if (this.parent?.isRoot) {
|
|
137
|
+
return "/" + this.id;
|
|
138
|
+
} else {
|
|
139
|
+
return this.parent?.absolutePath + "/" + this.id;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Returns whether this can be edited in its current state
|
|
145
|
+
*/
|
|
146
|
+
get canBeEdited(): boolean {
|
|
147
|
+
const isProtected = this.isProtected && this.getRoot().loadedDefaultData;
|
|
148
|
+
|
|
149
|
+
if (!isProtected && this.parent != null) {
|
|
150
|
+
return this.parent.canBeEdited;
|
|
151
|
+
} else {
|
|
152
|
+
return !isProtected;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
getRoot(): VirtualRoot {
|
|
157
|
+
const root = this.root ?? this.parent?.getRoot();
|
|
158
|
+
|
|
159
|
+
if (root == null) {
|
|
160
|
+
throw new Error("Root not found");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return root;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
isFile(): boolean {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
isFolder(): boolean {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
toJSON(): VirtualBaseJson | null {
|
|
175
|
+
const object = {
|
|
176
|
+
nam: this.name,
|
|
177
|
+
ico: this.iconUrl,
|
|
178
|
+
} as VirtualBaseJson;
|
|
179
|
+
|
|
180
|
+
return object;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
toString(): string | null {
|
|
184
|
+
const json = this.toJSON();
|
|
185
|
+
|
|
186
|
+
if (json == null)
|
|
187
|
+
return null;
|
|
188
|
+
|
|
189
|
+
return JSON.stringify(json);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { randomRange } from "../_utils/math.utils";
|
|
2
|
+
import { App } from "../system/configs/app";
|
|
3
|
+
import { Vector2 } from "../math/vector2";
|
|
4
|
+
import { SystemManager } from "../system/systemManager";
|
|
5
|
+
import { TrackingManager } from "../tracking/trackingManager";
|
|
6
|
+
import { VirtualFile } from "../virtual-drive/file";
|
|
7
|
+
|
|
8
|
+
export interface WindowOptions {
|
|
9
|
+
id?: string;
|
|
10
|
+
app?: App;
|
|
11
|
+
size?: Vector2;
|
|
12
|
+
position?: Vector2;
|
|
13
|
+
fullscreen?: boolean | string;
|
|
14
|
+
options?: object;
|
|
15
|
+
isFocused?: boolean;
|
|
16
|
+
lastInteraction?: number;
|
|
17
|
+
minimized?: boolean;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class WindowsManager {
|
|
22
|
+
windows: { [id: string]: WindowOptions };
|
|
23
|
+
updateWindows: Function;
|
|
24
|
+
startupComplete: boolean;
|
|
25
|
+
|
|
26
|
+
#systemManager: SystemManager;
|
|
27
|
+
#trackingManager: TrackingManager;
|
|
28
|
+
|
|
29
|
+
constructor(systemManager: SystemManager, trackingManager: TrackingManager) {
|
|
30
|
+
this.#systemManager = systemManager;
|
|
31
|
+
this.#trackingManager = trackingManager;
|
|
32
|
+
this.windows = {};
|
|
33
|
+
this.updateWindows = () => {};
|
|
34
|
+
this.startupComplete = false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
open(appId: string, options?: WindowOptions | null): object | null {
|
|
38
|
+
const { appsConfig, windowsConfig, taskbarConfig } = this.#systemManager;
|
|
39
|
+
const app = appsConfig.getAppById(appId);
|
|
40
|
+
|
|
41
|
+
if (app == null) {
|
|
42
|
+
console.warn(`Failed to open app ${appId}: app not found`);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const size = options?.size ?? app.windowOptions?.size ?? new Vector2(700, 400);
|
|
47
|
+
|
|
48
|
+
const availableScreenSpace = new Vector2(
|
|
49
|
+
window.innerWidth - windowsConfig.screenMargin * 2,
|
|
50
|
+
window.innerHeight - windowsConfig.screenMargin * 2 - taskbarConfig.height
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
let fullscreen = false;
|
|
54
|
+
|
|
55
|
+
if (size.x > availableScreenSpace.x) {
|
|
56
|
+
size.x = availableScreenSpace.x;
|
|
57
|
+
fullscreen = true;
|
|
58
|
+
} else if (size.y > availableScreenSpace.y) {
|
|
59
|
+
size.y = availableScreenSpace.y;
|
|
60
|
+
fullscreen = true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const position = new Vector2(
|
|
64
|
+
windowsConfig.screenMargin + randomRange(0, availableScreenSpace.x - size.x),
|
|
65
|
+
windowsConfig.screenMargin + randomRange(0, availableScreenSpace.y - size.y)
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (options?.fullscreen) {
|
|
69
|
+
if (typeof(options.fullscreen) == "string") {
|
|
70
|
+
fullscreen = options.fullscreen.toLowerCase() === "true";
|
|
71
|
+
} else {
|
|
72
|
+
fullscreen = options.fullscreen;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
delete options.fullscreen;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let id: number | string = 0;
|
|
79
|
+
while (this.windowIds.includes(id.toString())) {
|
|
80
|
+
id++;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
id = id.toString();
|
|
84
|
+
|
|
85
|
+
this.#trackingManager.event({
|
|
86
|
+
category: "Actions",
|
|
87
|
+
action: "Opened window",
|
|
88
|
+
label: app.id
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
console.info(`Opening window ${id}:${app.id}`);
|
|
92
|
+
|
|
93
|
+
this.windows[id] = {
|
|
94
|
+
id,
|
|
95
|
+
app,
|
|
96
|
+
size,
|
|
97
|
+
position,
|
|
98
|
+
fullscreen,
|
|
99
|
+
options: options as object | undefined,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
this.focus(id);
|
|
103
|
+
|
|
104
|
+
app.isActive = true;
|
|
105
|
+
|
|
106
|
+
this.updateWindows(this.windows);
|
|
107
|
+
return this.windows[id];
|
|
108
|
+
// console.log(this);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
openFile(file: VirtualFile, options: object = {}): object | null {
|
|
112
|
+
if (file.extension == null) return null;
|
|
113
|
+
|
|
114
|
+
const { appsConfig } = this.#systemManager;
|
|
115
|
+
const app = appsConfig.getAppByFileExtension(file?.extension);
|
|
116
|
+
if (app != null) {
|
|
117
|
+
return this.open(app.id, { file, ...options });
|
|
118
|
+
} else {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
close(windowId: string) {
|
|
124
|
+
windowId = windowId.toString();
|
|
125
|
+
|
|
126
|
+
if (!this.windowIds.includes(windowId)) {
|
|
127
|
+
console.warn(`Failed to close window ${windowId}: window not found`);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const { app } = this.windows[windowId];
|
|
132
|
+
if (app != null) app.isActive = this.isAppActive(app.id);
|
|
133
|
+
|
|
134
|
+
console.info(`Closing window ${windowId}`);
|
|
135
|
+
delete this.windows[windowId];
|
|
136
|
+
|
|
137
|
+
this.updateWindows(this.windows);
|
|
138
|
+
// console.log(this);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
focus(windowId: string) {
|
|
142
|
+
windowId = windowId.toString();
|
|
143
|
+
|
|
144
|
+
if (!this.windowIds.includes(windowId)) {
|
|
145
|
+
console.warn(`Failed to focus window ${windowId}: window not found`);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
Object.values(this.windows).forEach((window) => {
|
|
150
|
+
const isFocused = (window.id === windowId);
|
|
151
|
+
window.isFocused = isFocused;
|
|
152
|
+
|
|
153
|
+
if (isFocused) {
|
|
154
|
+
window.lastInteraction = Date.now().valueOf();
|
|
155
|
+
window.minimized = false;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
this.updateWindows(this.windows);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
isFocused(windowId: string) {
|
|
163
|
+
return this.windows[windowId].isFocused;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
isAnyFocused() {
|
|
167
|
+
let anyFocused = false;
|
|
168
|
+
|
|
169
|
+
Object.values(this.windows).forEach((window) => {
|
|
170
|
+
if (window.isFocused)
|
|
171
|
+
return anyFocused = true;
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return anyFocused;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @param minimized - Leave as undefined to toggle the window's minimization state
|
|
179
|
+
*/
|
|
180
|
+
setMinimized(windowId: string, minimized?: boolean) {
|
|
181
|
+
windowId = windowId.toString();
|
|
182
|
+
|
|
183
|
+
if (!this.windowIds.includes(windowId)) {
|
|
184
|
+
console.warn(`Failed to set minimized on window ${windowId}: window not found`);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const window = this.windows[windowId];
|
|
189
|
+
window.minimized = minimized ?? !window.minimized;
|
|
190
|
+
|
|
191
|
+
this.updateWindows(this.windows);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
minimizeAll() {
|
|
195
|
+
Object.values(this.windows).forEach((window) => {
|
|
196
|
+
window.minimized = true;
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
this.updateWindows(this.windows);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
isAppActive(appId: string): boolean {
|
|
203
|
+
let active = false;
|
|
204
|
+
|
|
205
|
+
Object.values(this.windows).forEach((window) => {
|
|
206
|
+
if (window.app?.id === appId) {
|
|
207
|
+
active = true;
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
return active;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
getAppWindowId(appId: string): string | null {
|
|
216
|
+
let windowId: string | null = null;
|
|
217
|
+
|
|
218
|
+
Object.values(this.windows).forEach((window) => {
|
|
219
|
+
if (window.app?.id == appId)
|
|
220
|
+
windowId = window.id as string;
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
return windowId;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
setUpdateWindows(updateWindows: Function) {
|
|
227
|
+
this.updateWindows = updateWindows;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
startup(appIds: string[], options: {}) {
|
|
231
|
+
if (appIds == null || this.startupComplete)
|
|
232
|
+
return;
|
|
233
|
+
|
|
234
|
+
appIds.forEach((appId) => {
|
|
235
|
+
this.open(appId, options);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
this.startupComplete = true;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
get windowIds(): string[] {
|
|
242
|
+
return Object.keys(this.windows);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ZIndexManager } from "./zIndexManager";
|
|
2
|
+
|
|
3
|
+
export class ZIndexGroup {
|
|
4
|
+
length: number = 0;
|
|
5
|
+
offset: number = 0;
|
|
6
|
+
groupIndex: number = 0;
|
|
7
|
+
zIndexManager: ZIndexManager | null = null;
|
|
8
|
+
|
|
9
|
+
constructor(zIndexManager: ZIndexManager, initialLength?: number) {
|
|
10
|
+
this.setManager(zIndexManager);
|
|
11
|
+
this.setLength(initialLength ?? 0);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
setManager(zIndexManager: ZIndexManager): ZIndexGroup {
|
|
15
|
+
this.zIndexManager = zIndexManager;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setOffset(offset: number): ZIndexGroup {
|
|
20
|
+
this.offset = offset;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
setLength(length: number): ZIndexGroup {
|
|
25
|
+
if (this.length === length)
|
|
26
|
+
return this;
|
|
27
|
+
|
|
28
|
+
this.length = length;
|
|
29
|
+
this.zIndexManager?.update();
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getIndex(index: number): number {
|
|
34
|
+
if (this.length < index + 1) {
|
|
35
|
+
this.setLength(index + 1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return this.offset + index;
|
|
39
|
+
}
|
|
40
|
+
}
|