@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,388 @@
|
|
|
1
|
+
import { removeFromArray } from "../../_utils/array.utils";
|
|
2
|
+
import { WindowsManager } from "../../windows/windowsManager";
|
|
3
|
+
import { VirtualFileJson } from "../file/virtualFile";
|
|
4
|
+
import { VirtualBase, VirtualBaseJson } from "../virtualBase";
|
|
5
|
+
import { VirtualFolderLink } from ".";
|
|
6
|
+
import { VirtualFile, VirtualFileLink } from "../file";
|
|
7
|
+
import { fileExplorer } from "@prozilla-os/file-explorer";
|
|
8
|
+
|
|
9
|
+
export interface VirtualFolderJson extends VirtualBaseJson {
|
|
10
|
+
fls?: VirtualFileJson[];
|
|
11
|
+
fds?: VirtualFolderJson[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A virtual folder that can contains files and sub-folders
|
|
16
|
+
*/
|
|
17
|
+
export class VirtualFolder extends VirtualBase {
|
|
18
|
+
subFolders: (VirtualFolder | VirtualFolderLink)[];
|
|
19
|
+
files: (VirtualFile | VirtualFileLink)[];
|
|
20
|
+
type: number | undefined;
|
|
21
|
+
|
|
22
|
+
static TYPE = {
|
|
23
|
+
GENERAL: 0,
|
|
24
|
+
MEDIA: 1,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
constructor(name: string, type?: number) {
|
|
28
|
+
super(name);
|
|
29
|
+
this.subFolders = [];
|
|
30
|
+
this.files = [];
|
|
31
|
+
this.type = type ?? VirtualFolder.TYPE.GENERAL;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
setAlias(alias: string): this {
|
|
35
|
+
return super.setAlias(alias);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns true if this folder contains a file matching a name and extension
|
|
40
|
+
*/
|
|
41
|
+
hasFile(name: string, extension?: string) {
|
|
42
|
+
return this.findFile(name, extension) !== null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if this folder contains a folder matching a name
|
|
47
|
+
*/
|
|
48
|
+
hasFolder(name: string) {
|
|
49
|
+
return this.findSubFolder(name) !== null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Finds and returns a file inside this folder matching a name and extension
|
|
54
|
+
*/
|
|
55
|
+
findFile(name: string, extension?: string | null): VirtualFile | VirtualFileLink | null {
|
|
56
|
+
let resultFile: VirtualFile | VirtualFileLink | null = null;
|
|
57
|
+
|
|
58
|
+
this.files.forEach((file) => {
|
|
59
|
+
const matchingName = (file.name === name || (file.alias && file.alias === name));
|
|
60
|
+
const matchingExtension = (extension == null || file.extension === extension);
|
|
61
|
+
if (matchingName && matchingExtension) {
|
|
62
|
+
return resultFile = file;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return resultFile;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Finds and returns a folder inside this folder matching a name
|
|
71
|
+
*/
|
|
72
|
+
findSubFolder(name: string): VirtualFolder | VirtualFolderLink | null {
|
|
73
|
+
let resultFolder: VirtualFolder | VirtualFolderLink | null = null;
|
|
74
|
+
|
|
75
|
+
this.subFolders.forEach((folder) => {
|
|
76
|
+
if (folder.name === name || (folder.alias && folder.alias === name)) {
|
|
77
|
+
return resultFolder = folder;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return resultFolder;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Creates a file with a name and extension
|
|
86
|
+
*/
|
|
87
|
+
createFile(name: string, extension?: string, callback?: (newFile: VirtualFile | VirtualFileLink) => void): this {
|
|
88
|
+
if (!this.canBeEdited)
|
|
89
|
+
return this;
|
|
90
|
+
|
|
91
|
+
let newFile = this.findFile(name, extension);
|
|
92
|
+
if (newFile == null) {
|
|
93
|
+
newFile = new VirtualFile(name, extension);
|
|
94
|
+
this.files.push(newFile);
|
|
95
|
+
newFile.parent = this;
|
|
96
|
+
}
|
|
97
|
+
callback?.(newFile);
|
|
98
|
+
|
|
99
|
+
newFile.confirmChanges();
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates files based on an array of objects with file names and extensions
|
|
105
|
+
*/
|
|
106
|
+
createFiles(files: { name: string; extension: string; }[]): this {
|
|
107
|
+
if (!this.canBeEdited)
|
|
108
|
+
return this;
|
|
109
|
+
|
|
110
|
+
files.forEach(({ name, extension }) => {
|
|
111
|
+
this.createFile(name, extension);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
this.confirmChanges();
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Creates a file link with a name
|
|
120
|
+
*/
|
|
121
|
+
createFileLink(name: string, callback?: (newFileLink: VirtualFileLink | VirtualFile) => void): this {
|
|
122
|
+
if (!this.canBeEdited)
|
|
123
|
+
return this;
|
|
124
|
+
|
|
125
|
+
let newFile = this.findFile(name);
|
|
126
|
+
if (newFile == null) {
|
|
127
|
+
newFile = new VirtualFileLink(name);
|
|
128
|
+
this.files.push(newFile);
|
|
129
|
+
newFile.parent = this;
|
|
130
|
+
}
|
|
131
|
+
callback?.(newFile);
|
|
132
|
+
|
|
133
|
+
newFile.confirmChanges();
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Creates files based on an array of objects with file names and extensions
|
|
139
|
+
*/
|
|
140
|
+
createFileLinks(files: { name: string; }[]): this {
|
|
141
|
+
if (!this.canBeEdited)
|
|
142
|
+
return this;
|
|
143
|
+
|
|
144
|
+
files.forEach(({ name }) => {
|
|
145
|
+
this.createFileLink(name);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
this.confirmChanges();
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Creates a folder with a name
|
|
154
|
+
*/
|
|
155
|
+
createFolder(name: string, callback?: (newFolder: VirtualFolder) => void): this {
|
|
156
|
+
if (!this.canBeEdited)
|
|
157
|
+
return this;
|
|
158
|
+
|
|
159
|
+
let newFolder = this.findSubFolder(name);
|
|
160
|
+
if (newFolder == null) {
|
|
161
|
+
newFolder = new VirtualFolder(name);
|
|
162
|
+
this.subFolders.push(newFolder);
|
|
163
|
+
newFolder.parent = this;
|
|
164
|
+
}
|
|
165
|
+
callback?.(newFolder as VirtualFolder);
|
|
166
|
+
|
|
167
|
+
newFolder.confirmChanges();
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Creates folders based on an array of folder names
|
|
173
|
+
*/
|
|
174
|
+
createFolders(names: string[]): this {
|
|
175
|
+
if (!this.canBeEdited)
|
|
176
|
+
return this;
|
|
177
|
+
|
|
178
|
+
names.forEach((name) => {
|
|
179
|
+
this.createFolder(name);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
this.confirmChanges();
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Creates a folder link with a name
|
|
188
|
+
*/
|
|
189
|
+
createFolderLink(name: string, callback?: (newFolderLink: VirtualFolderLink | VirtualFolder) => void): this {
|
|
190
|
+
if (!this.canBeEdited)
|
|
191
|
+
return this;
|
|
192
|
+
|
|
193
|
+
let newFolder = this.findSubFolder(name);
|
|
194
|
+
if (newFolder == null) {
|
|
195
|
+
newFolder = new VirtualFolderLink(name);
|
|
196
|
+
this.subFolders.push(newFolder);
|
|
197
|
+
newFolder.parent = this;
|
|
198
|
+
}
|
|
199
|
+
callback?.(newFolder);
|
|
200
|
+
|
|
201
|
+
newFolder.confirmChanges();
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Creates folder links based on an array of folder names
|
|
207
|
+
*/
|
|
208
|
+
createFolderLinks(names: string[]): this {
|
|
209
|
+
if (!this.canBeEdited)
|
|
210
|
+
return this;
|
|
211
|
+
|
|
212
|
+
names.forEach((name) => {
|
|
213
|
+
this.createFolder(name);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
this.confirmChanges();
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Removes a file or folder from this folder
|
|
222
|
+
*/
|
|
223
|
+
remove(child: VirtualFile | VirtualFileLink | VirtualFolder | VirtualFolderLink): this {
|
|
224
|
+
if (!this.canBeEdited)
|
|
225
|
+
return this;
|
|
226
|
+
|
|
227
|
+
child.parent = undefined;
|
|
228
|
+
|
|
229
|
+
if (child.isFile()) {
|
|
230
|
+
removeFromArray(child, this.files);
|
|
231
|
+
} else if (child.isFolder()) {
|
|
232
|
+
removeFromArray(child, this.subFolders);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
child.confirmChanges();
|
|
236
|
+
return this;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Returns the file or folder at a relative path or null if it doesn't exist
|
|
241
|
+
*/
|
|
242
|
+
navigate(relativePath: string): VirtualFile | VirtualFolder | null {
|
|
243
|
+
const segments = relativePath.split("/");
|
|
244
|
+
let currentDirectory: VirtualFile | VirtualFolder = this as VirtualFolder;
|
|
245
|
+
|
|
246
|
+
const getDirectory = (path: string, isStart: boolean) => {
|
|
247
|
+
if (isStart && path === "") {
|
|
248
|
+
return this.getRoot();
|
|
249
|
+
} else if (isStart && Object.keys(this.getRoot().shortcuts).includes(path)) {
|
|
250
|
+
return this.getRoot().shortcuts[path];
|
|
251
|
+
} else if (path === ".") {
|
|
252
|
+
return this;
|
|
253
|
+
} else if (path === "..") {
|
|
254
|
+
return currentDirectory?.parent;
|
|
255
|
+
} else {
|
|
256
|
+
return (currentDirectory as VirtualFolder)?.findSubFolder(path);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
if (segments.length === 1) {
|
|
261
|
+
const directory = getDirectory(segments[0], true) as VirtualFile | VirtualFolder;
|
|
262
|
+
if (directory != null)
|
|
263
|
+
return directory;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
267
|
+
const segment = segments[i];
|
|
268
|
+
currentDirectory = getDirectory(segment, i === 0) as VirtualFile | VirtualFolder;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const lastSegment = segments[segments.length - 1];
|
|
272
|
+
|
|
273
|
+
if (lastSegment === "") {
|
|
274
|
+
return currentDirectory;
|
|
275
|
+
} else if (currentDirectory != null) {
|
|
276
|
+
const folder = (currentDirectory as VirtualFolder).findSubFolder(lastSegment) as VirtualFolder;
|
|
277
|
+
|
|
278
|
+
if (folder != null) return folder;
|
|
279
|
+
|
|
280
|
+
const { name, extension } = VirtualFile.splitId(lastSegment);
|
|
281
|
+
return (currentDirectory as VirtualFolder).findFile(name, extension) as VirtualFile | VirtualFolder;
|
|
282
|
+
} else {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Opens this folder in file explorer
|
|
289
|
+
*/
|
|
290
|
+
open(windowsManager: WindowsManager) {
|
|
291
|
+
return windowsManager.open(fileExplorer.id, { path: this.path });
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Deletes this folder and all its files and sub-folders recursively
|
|
296
|
+
*/
|
|
297
|
+
delete() {
|
|
298
|
+
if (!this.canBeEdited)
|
|
299
|
+
return;
|
|
300
|
+
|
|
301
|
+
super.delete();
|
|
302
|
+
|
|
303
|
+
const items = [
|
|
304
|
+
...this.files,
|
|
305
|
+
...this.subFolders
|
|
306
|
+
];
|
|
307
|
+
|
|
308
|
+
items.forEach((item) => {
|
|
309
|
+
item.delete();
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
this.confirmChanges();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Returns all files inside this folder
|
|
317
|
+
*/
|
|
318
|
+
getFiles(showHidden = false): VirtualFile[] {
|
|
319
|
+
if (showHidden) return this.files as VirtualFile[];
|
|
320
|
+
|
|
321
|
+
return this.files.filter(({ name }) =>
|
|
322
|
+
!name.startsWith(".")
|
|
323
|
+
) as VirtualFile[];
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Returns all sub-folders inside this folder
|
|
328
|
+
*/
|
|
329
|
+
getSubFolders(showHidden = false): VirtualFolder[] {
|
|
330
|
+
if (showHidden) return this.subFolders as VirtualFolder[];
|
|
331
|
+
|
|
332
|
+
return this.subFolders.filter(({ name }) =>
|
|
333
|
+
!name.startsWith(".")
|
|
334
|
+
) as VirtualFolder[];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Returns the amount of files and sub-folders inside this folder
|
|
339
|
+
*/
|
|
340
|
+
getItemCount(showHidden = false): number {
|
|
341
|
+
const filesCount = this.getFiles(showHidden)?.length ?? 0;
|
|
342
|
+
const foldersCount = this.getSubFolders(showHidden)?.length ?? 0;
|
|
343
|
+
|
|
344
|
+
return filesCount + foldersCount;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
isFolder(): boolean {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
getIconUrl(): string {
|
|
352
|
+
if (this.iconUrl != null)
|
|
353
|
+
return this.iconUrl;
|
|
354
|
+
|
|
355
|
+
const { virtualDriveConfig } = this.getRoot().systemManager;
|
|
356
|
+
return virtualDriveConfig.folderIcon;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
toJSON(): VirtualFolderJson | null {
|
|
360
|
+
const object = super.toJSON() as VirtualFolderJson;
|
|
361
|
+
|
|
362
|
+
if (object == null)
|
|
363
|
+
return null;
|
|
364
|
+
|
|
365
|
+
if (this.files.length > 0) {
|
|
366
|
+
const files = this.files
|
|
367
|
+
.map((file) => file.toJSON())
|
|
368
|
+
.filter((file) => file != null) as VirtualFileJson[];
|
|
369
|
+
|
|
370
|
+
if (files.length > 0)
|
|
371
|
+
object.fls = files;
|
|
372
|
+
}
|
|
373
|
+
if (this.subFolders.length > 0) {
|
|
374
|
+
const folders = this.subFolders
|
|
375
|
+
.map((folder) => folder.toJSON())
|
|
376
|
+
.filter((folder) => folder != null) as VirtualFolderJson[];
|
|
377
|
+
|
|
378
|
+
if (folders.length > 0)
|
|
379
|
+
object.fds = folders;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Don't store folder if it's empty and untouched
|
|
383
|
+
if (!this.editedByUser && (!object.fls || object.fls.length === 0) && (!object.fds || object.fds.length === 0))
|
|
384
|
+
return null;
|
|
385
|
+
|
|
386
|
+
return object;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { VirtualFolder } from ".";
|
|
2
|
+
import { VirtualFolderJson } from "./virtualFolder";
|
|
3
|
+
|
|
4
|
+
export interface VirtualFolderLinkJson extends VirtualFolderJson {
|
|
5
|
+
lnk: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A link that points to a virtual folder
|
|
10
|
+
*/
|
|
11
|
+
export class VirtualFolderLink extends VirtualFolder {
|
|
12
|
+
linkedPath?: string;
|
|
13
|
+
|
|
14
|
+
constructor(name: string, linkedFolder?: VirtualFolder) {
|
|
15
|
+
super(name);
|
|
16
|
+
this.linkedFolder = linkedFolder;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setLinkedFolder(folder: VirtualFolder): VirtualFolderLink {
|
|
20
|
+
this.linkedFolder = folder;
|
|
21
|
+
|
|
22
|
+
if (folder) {
|
|
23
|
+
this.linkedPath = folder.path;
|
|
24
|
+
this.type = folder.type;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setLinkedPath(path: string): VirtualFolderLink {
|
|
31
|
+
if (this.linkedFolder && this.linkedFolder.path === path)
|
|
32
|
+
return this;
|
|
33
|
+
|
|
34
|
+
const target = this.navigate(path);
|
|
35
|
+
|
|
36
|
+
if (target instanceof VirtualFolder) {
|
|
37
|
+
this.setLinkedFolder(target);
|
|
38
|
+
} else {
|
|
39
|
+
this.linkedFolder = null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
isValid(): boolean {
|
|
46
|
+
if (!this.linkedPath)
|
|
47
|
+
return false;
|
|
48
|
+
|
|
49
|
+
this.setLinkedPath(this.linkedPath);
|
|
50
|
+
|
|
51
|
+
return (this.linkedFolder != null);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getIconUrl(): string {
|
|
55
|
+
if (this.iconUrl != null)
|
|
56
|
+
return this.iconUrl;
|
|
57
|
+
|
|
58
|
+
if (this.isValid() && this.linkedFolder?.iconUrl)
|
|
59
|
+
return this.linkedFolder.iconUrl;
|
|
60
|
+
|
|
61
|
+
const { virtualDriveConfig } = this.getRoot().systemManager;
|
|
62
|
+
return virtualDriveConfig.folderLinkIcon;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
toJSON(): VirtualFolderLinkJson | null {
|
|
66
|
+
if (this.linkedPath == null)
|
|
67
|
+
return null;
|
|
68
|
+
|
|
69
|
+
const object = {
|
|
70
|
+
nam: this.name,
|
|
71
|
+
lnk: this.linkedPath
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return object;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Point certain methods to linked folder
|
|
78
|
+
|
|
79
|
+
setAlias(...args: Parameters<VirtualFolder["setAlias"]>) {
|
|
80
|
+
if (this.isValid())
|
|
81
|
+
this.linkedFolder?.setAlias(...args);
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
createFile(...args: Parameters<VirtualFolder["createFile"]>) {
|
|
86
|
+
if (this.isValid())
|
|
87
|
+
this.linkedFolder?.createFile(...args);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
createFiles(...args: Parameters<VirtualFolder["createFiles"]>) {
|
|
92
|
+
if (this.isValid())
|
|
93
|
+
this.linkedFolder?.createFiles(...args);
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
createFolder(...args: Parameters<VirtualFolder["createFolder"]>) {
|
|
98
|
+
if (this.isValid())
|
|
99
|
+
this.linkedFolder?.createFolder(...args);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
createFolders(...args: Parameters<VirtualFolder["createFolders"]>) {
|
|
104
|
+
if (this.isValid())
|
|
105
|
+
this.linkedFolder?.createFolders(...args);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
hasFile(...args: Parameters<VirtualFolder["hasFile"]>): ReturnType<VirtualFolder["hasFile"]> {
|
|
110
|
+
if (this.isValid()) return this.linkedFolder?.hasFile(...args) ?? false;
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
hasFolder(...args: Parameters<VirtualFolder["hasFolder"]>): ReturnType<VirtualFolder["hasFolder"]> {
|
|
115
|
+
if (this.isValid()) return this.linkedFolder?.hasFolder(...args) ?? false;
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
findFile(...args: Parameters<VirtualFolder["findFile"]>): ReturnType<VirtualFolder["findFile"]> {
|
|
120
|
+
if (this.isValid()) return this.linkedFolder?.findFile(...args) as ReturnType<VirtualFolder["findFile"]>;
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
findSubFolder(...args: Parameters<VirtualFolder["findSubFolder"]>): ReturnType<VirtualFolder["findSubFolder"]> {
|
|
125
|
+
if (this.isValid()) return this.linkedFolder?.findSubFolder(...args) as ReturnType<VirtualFolder["findSubFolder"]>;
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
getFiles(...args: Parameters<VirtualFolder["getFiles"]>): ReturnType<VirtualFolder["getFiles"]> {
|
|
130
|
+
if (this.isValid()) return this.linkedFolder?.getFiles(...args) ?? [];
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
getSubFolders(...args: Parameters<VirtualFolder["getSubFolders"]>): ReturnType<VirtualFolder["getSubFolders"]> {
|
|
135
|
+
if (this.isValid()) return this.linkedFolder?.getSubFolders(...args) ?? [];
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
open(...args: Parameters<VirtualFolder["open"]>): ReturnType<VirtualFolder["open"]> {
|
|
140
|
+
if (this.isValid()) return this.linkedFolder?.open(...args) as ReturnType<VirtualFolder["open"]>;
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
getItemCount(...args: Parameters<VirtualFolder["getItemCount"]>): ReturnType<VirtualFolder["getItemCount"]> {
|
|
145
|
+
if (this.isValid()) return this.linkedFolder?.getItemCount(...args) ?? 0;
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { SystemManager } from "../../system/systemManager";
|
|
2
|
+
import { VirtualFile, VirtualFileLink } from "../file";
|
|
3
|
+
import { VirtualFolder, VirtualFolderLink } from "../folder";
|
|
4
|
+
import { VirtualRoot } from "./virtualRoot";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Loads default data on the virtual root
|
|
8
|
+
*/
|
|
9
|
+
export function loadDefaultData(systemManager: SystemManager, virtualRoot: VirtualRoot) {
|
|
10
|
+
const { desktopConfig, virtualDriveConfig } = systemManager;
|
|
11
|
+
const linkedPaths: Record<string, string> = {};
|
|
12
|
+
|
|
13
|
+
virtualRoot.createFolder("home", (folder) => {
|
|
14
|
+
folder.createFolder("prozilla-os", (folder) => {
|
|
15
|
+
folder.setAlias("~")
|
|
16
|
+
.createFolder(".config", (folder) => {
|
|
17
|
+
folder.createFile("desktop", "xml", (file) => {
|
|
18
|
+
file.setSource("/config/desktop.xml");
|
|
19
|
+
}).createFile("taskbar", "xml", (file) => {
|
|
20
|
+
file.setSource("/config/taskbar.xml");
|
|
21
|
+
}).createFile("apps", "xml", (file) => {
|
|
22
|
+
file.setSource("/config/apps.xml");
|
|
23
|
+
}).createFile("theme", "xml", (file) => {
|
|
24
|
+
file.setSource("/config/theme.xml");
|
|
25
|
+
});
|
|
26
|
+
})
|
|
27
|
+
.createFolder("Pictures", (folder) => {
|
|
28
|
+
folder.setIconUrl(virtualDriveConfig.imagesFolderIcon);
|
|
29
|
+
folder.createFolder("Wallpapers", (folder) => {
|
|
30
|
+
folder.setProtected(true);
|
|
31
|
+
for (let i = 0; i < desktopConfig.wallpapers.length; i++) {
|
|
32
|
+
const source = desktopConfig.wallpapers[i];
|
|
33
|
+
folder.createFile(`Wallpaper${i + 1}`, "png", (file) => {
|
|
34
|
+
file.setSource(source);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}).createFile("ProzillaOS", "png", (file) => {
|
|
38
|
+
file.setSource("/assets/banner-logo-title.png");
|
|
39
|
+
}).createFile("Icon", "svg", (file) => {
|
|
40
|
+
file.setSource("/icon.svg");
|
|
41
|
+
}).createFolder("Crumbling City", (folder) => {
|
|
42
|
+
folder.createFile("Japan", "png", (file) => {
|
|
43
|
+
file.setSource("https://daisygames.org/media/Games/Crumbling%20City/CrumblingCityRelease.png");
|
|
44
|
+
}).createFile("City Center", "png", (file) => {
|
|
45
|
+
file.setSource("https://daisygames.org/media/Games/Crumbling%20City/Screenshot_City_Firegun.png");
|
|
46
|
+
}).createFile("Farms", "png", (file) => {
|
|
47
|
+
file.setSource("https://daisygames.org/media/Games/Crumbling%20City/Screenshot_Farms_Hammer.png");
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
linkedPaths.images = folder.path;
|
|
51
|
+
})
|
|
52
|
+
.createFolder("Documents", (folder) => {
|
|
53
|
+
folder.setIconUrl(virtualDriveConfig.textFolderIcon);
|
|
54
|
+
folder.createFile("text", "txt", (file) => {
|
|
55
|
+
file.setContent("Hello world!");
|
|
56
|
+
}).createFile("Info", "md", (file) => {
|
|
57
|
+
file.setProtected(true)
|
|
58
|
+
.setSource("/documents/Info.md")
|
|
59
|
+
.setIconUrl(virtualDriveConfig.infoFileIcon);
|
|
60
|
+
linkedPaths.info = file.path;
|
|
61
|
+
}).createFile("Prozilla", "md", (file) => {
|
|
62
|
+
file.setProtected(true)
|
|
63
|
+
.setSource("/documents/Prozilla.md");
|
|
64
|
+
linkedPaths.links = file.path;
|
|
65
|
+
});
|
|
66
|
+
linkedPaths.documents = folder.path;
|
|
67
|
+
})
|
|
68
|
+
.createFolder("Desktop", (folder) => {
|
|
69
|
+
folder.createFileLink("Info.md", (fileLink) => {
|
|
70
|
+
(fileLink as VirtualFileLink).setLinkedPath(linkedPaths.info);
|
|
71
|
+
}).createFileLink("Prozilla.md", (fileLink) => {
|
|
72
|
+
(fileLink as VirtualFileLink).setLinkedPath(linkedPaths.links);
|
|
73
|
+
}).createFolderLink("Pictures", (folderLink) => {
|
|
74
|
+
(folderLink as VirtualFolderLink).setLinkedPath(linkedPaths.images);
|
|
75
|
+
}).createFolderLink("Documents", (folderLink) => {
|
|
76
|
+
(folderLink as VirtualFolderLink).setLinkedPath(linkedPaths.documents);
|
|
77
|
+
});
|
|
78
|
+
})
|
|
79
|
+
.createFolder("Apps");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
loadTree(virtualRoot);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Create files and folders based on repository tree
|
|
87
|
+
function loadTree(virtualRoot: VirtualRoot) {
|
|
88
|
+
const excludedFiles = [
|
|
89
|
+
"/public/config/tree.json"
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
void fetch("/config/tree.json").then((response) =>
|
|
93
|
+
response.json()
|
|
94
|
+
).then(({ files, folders }: { files: string[], folders: string[] }) => {
|
|
95
|
+
folders.forEach((folderPath) => {
|
|
96
|
+
const lastSlashIndex = folderPath.lastIndexOf("/");
|
|
97
|
+
|
|
98
|
+
if (lastSlashIndex === -1) {
|
|
99
|
+
virtualRoot.createFolder(folderPath);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const parentPath = folderPath.substring(0, lastSlashIndex);
|
|
104
|
+
const folderName = folderPath.substring(lastSlashIndex + 1);
|
|
105
|
+
|
|
106
|
+
const parentFolder = virtualRoot.navigate(parentPath) as VirtualFolder;
|
|
107
|
+
parentFolder.createFolder(folderName);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
files.forEach((filePath) => {
|
|
111
|
+
if (excludedFiles.includes(filePath))
|
|
112
|
+
return;
|
|
113
|
+
|
|
114
|
+
const lastSlashIndex = filePath.lastIndexOf("/");
|
|
115
|
+
|
|
116
|
+
const callback = (virtualFile: VirtualFile) => {
|
|
117
|
+
const virtualPath = virtualFile.absolutePath;
|
|
118
|
+
if (virtualPath.startsWith("/public/")) {
|
|
119
|
+
virtualFile.setSource(virtualPath.replace(/^\/public\//, "/"));
|
|
120
|
+
} else {
|
|
121
|
+
virtualFile.setSource(`https://raw.githubusercontent.com/Prozilla/ProzillaOS/main${virtualPath}`);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
if (lastSlashIndex === -1) {
|
|
126
|
+
const { name, extension } = VirtualFile.splitId(filePath);
|
|
127
|
+
virtualRoot.createFile(name, extension as string | undefined, callback);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const parentPath = filePath.substring(0, lastSlashIndex);
|
|
132
|
+
const { name, extension } = VirtualFile.splitId(filePath.substring(lastSlashIndex + 1));
|
|
133
|
+
|
|
134
|
+
const parentFolder = virtualRoot.navigate(parentPath) as VirtualFolder;
|
|
135
|
+
parentFolder.createFile(name, extension as string | undefined, callback);
|
|
136
|
+
});
|
|
137
|
+
}).catch(() => {
|
|
138
|
+
console.warn("Failed to load repository tree. Make sure the tree data is valid and up-to-date using 'npm run fetch'.");
|
|
139
|
+
});
|
|
140
|
+
}
|