diff --git a/src/features/virtual-drive/virtual-base.js b/src/features/virtual-drive/virtual-base.js index 3344ae0..6bc5f9a 100644 --- a/src/features/virtual-drive/virtual-base.js +++ b/src/features/virtual-drive/virtual-base.js @@ -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"); diff --git a/src/features/virtual-drive/virtual-folder.js b/src/features/virtual-drive/virtual-folder.js index 80c9fd8..b4a57f8 100644 --- a/src/features/virtual-drive/virtual-folder.js +++ b/src/features/virtual-drive/virtual-folder.js @@ -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(); } /** diff --git a/src/features/virtual-drive/virtual-root.js b/src/features/virtual-drive/virtual-root.js index 3515510..0dbacf0 100644 --- a/src/features/virtual-drive/virtual-root.js +++ b/src/features/virtual-drive/virtual-root.js @@ -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 }