Skip to content

Commit

Permalink
feat: requireConfirmationOnLargeDeletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Nov 28, 2024
1 parent dea2783 commit 53c1885
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 9 additions & 5 deletions src/lib/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<void>(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",
Expand Down Expand Up @@ -463,6 +463,10 @@ export class Sync {
}
}, 1000)
})

if (result === "restart") {
return
}
}

postMessageToMain({
Expand Down

0 comments on commit 53c1885

Please sign in to comment.