Added reset function for virtual drive

This commit is contained in:
Prozilla 2023-08-08 15:24:35 +02:00
parent 47525f1347
commit 57f85d7fa6
No known key found for this signature in database
GPG key ID: 5858DFE71CAF31EE
3 changed files with 18 additions and 4 deletions

View file

@ -54,8 +54,12 @@ export class VirtualBase extends EventEmitter {
delete() {
const parent = this.parent;
if (parent == null)
return;
parent.remove?.(this);
parent.getRoot().saveData();
parent.getRoot()?.saveData();
}
open() {}
@ -72,7 +76,7 @@ export class VirtualBase extends EventEmitter {
* @returns {VirtualRoot}
*/
getRoot() {
const root = this.root ?? this.parent.getRoot();
const root = this.root ?? this.parent?.getRoot();
if (root === null) {
throw new Error("Root not found");

View file

@ -219,7 +219,7 @@ export class VirtualFolder extends VirtualBase {
removeFromArray(child, this.subFolders);
}
this.getRoot().saveData();
this.getRoot()?.saveData();
}
/**
@ -284,7 +284,7 @@ export class VirtualFolder extends VirtualBase {
item.delete();
});
this.getRoot().saveData();
this.getRoot()?.saveData();
}
/**

View file

@ -8,6 +8,9 @@ export const WALLPAPER_COUNT = 6;
* A virtual folder that serves as the root folder
*/
export class VirtualRoot extends VirtualFolder {
/**
* @type {boolean}
*/
initiated = false;
constructor() {
@ -177,6 +180,13 @@ export class VirtualRoot extends VirtualFolder {
return this;
}
reset() {
if (window.confirm("Are you sure you want to reset all your data?")) {
StorageManager.clear();
window.location.reload(false);
}
}
static isValidName(name) {
// TO DO
}