From 53c188566906e57110d3373d3aa3454acf8896eb Mon Sep 17 00:00:00 2001 From: Dwynr Date: Thu, 28 Nov 2024 20:17:35 +0100 Subject: [PATCH] feat: requireConfirmationOnLargeDeletion --- package.json | 2 +- src/index.ts | 4 ++-- src/lib/sync.ts | 14 +++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index b7f527b..d680967 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@filen/sync", - "version": "0.1.85", + "version": "0.1.86", "description": "Filen Sync", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 81be8c0..de5f8ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -327,10 +327,10 @@ export class SyncWorker { } } - public confirmDeletion(uuid: string): void { + public confirmDeletion(uuid: string, result: "delete" | "restart"): void { for (const syncUUID in this.syncs) { if (syncUUID === uuid) { - this.syncs[syncUUID]!.needsDeletionConfirmation = false + this.syncs[syncUUID]!.deletionConfirmationResult = result break } diff --git a/src/lib/sync.ts b/src/lib/sync.ts index 6d9342b..80349a1 100644 --- a/src/lib/sync.ts +++ b/src/lib/sync.ts @@ -59,7 +59,7 @@ export class Sync { public cleaningLocalTrash: boolean = false public isPreviousSavedTreeStateEmpty: boolean = true public requireConfirmationOnLargeDeletion: boolean - public needsDeletionConfirmation: boolean = false + public deletionConfirmationResult: "delete" | "restart" | "waiting" = "waiting" /** * Creates an instance of Sync. @@ -427,14 +427,14 @@ export class Sync { ((confirmLocalDeletion && (this.mode === "twoWay" || this.mode === "localToCloud")) || (confirmRemoteDeletion && (this.mode === "twoWay" || this.mode === "cloudToLocal"))) ) { - this.needsDeletionConfirmation = true + this.deletionConfirmationResult = "waiting" - await new Promise(resolve => { + const result = await new Promise<"delete" | "restart">(resolve => { const interval = setInterval(() => { - if (!this.needsDeletionConfirmation) { + if (this.deletionConfirmationResult !== "waiting") { clearInterval(interval) - resolve() + resolve(this.deletionConfirmationResult) } else { postMessageToMain({ type: "confirmDeletion", @@ -463,6 +463,10 @@ export class Sync { } }, 1000) }) + + if (result === "restart") { + return + } } postMessageToMain({