Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: ask to create backup before logout in all cases

Abdullah Attac4e15b8f90b0
diff --git a/apps/web/src/dialogs/confirm.tsx b/apps/web/src/dialogs/confirm.tsx
index e9601539d..9343194a7 100644
--- a/apps/web/src/dialogs/confirm.tsx
+++ b/apps/web/src/dialogs/confirm.tsx
@@ -23,7 +23,7 @@ import { mdToHtml } from "../utils/md";
import Dialog from "../components/dialog";
import { BaseDialogProps, DialogManager } from "../common/dialog-manager";
import { db } from "../common/db";
-import { AppVersion, getChangelog } from "../utils/version";
+import { getChangelog } from "../utils/version";
import { downloadUpdate } from "../utils/updater";
type Check = { text: string; default?: boolean };
@@ -101,12 +101,17 @@ export const ConfirmDialog = DialogManager.register(function ConfirmDialog<
key={id}
id={id}
variant="text.body"
- sx={{ alignItems: "center" }}
+ sx={{ fontWeight: "bold", mt: 1 }}
>
<Checkbox
name={id}
defaultChecked={check.default}
- sx={{ mr: "small", width: 18, height: 18 }}
+ sx={{
+ mr: "small",
+ width: 18,
+ height: 18,
+ color: "accent"
+ }}
onChange={(e) =>
(checkedItems.current[id as TCheckId] =
e.currentTarget.checked)
@@ -147,9 +152,15 @@ export function showLogoutConfirmation() {
return ConfirmDialog.show({
title: `Logout?`,
message:
- "Logging out will clear all data stored on THIS DEVICE. Make sure you have synced all your changes before logging out.",
+ "Logging out will clear all data stored on THIS DEVICE. Are you sure you want to log out?",
positiveButtonText: "Yes",
- negativeButtonText: "No"
+ negativeButtonText: "No",
+ checks: {
+ backup: {
+ text: "Take a backup before logging out to prevent data loss?",
+ default: true
+ }
+ }
});
}
diff --git a/apps/web/src/dialogs/settings/profile-settings.ts b/apps/web/src/dialogs/settings/profile-settings.ts
index 4c5881e87..2bf2ff176 100644
--- a/apps/web/src/dialogs/settings/profile-settings.ts
+++ b/apps/web/src/dialogs/settings/profile-settings.ts
@@ -33,6 +33,7 @@ import {
import { TaskManager } from "../../common/task-manager";
import { AttachmentsDialog } from "../attachments-dialog";
import { RecoveryKeyDialog } from "../recovery-key-dialog";
+import { logger } from "../../utils/logger";
export const ProfileSettings: SettingsGroup[] = [
{
@@ -142,26 +143,34 @@ export const ProfileSettings: SettingsGroup[] = [
variant: "errorSecondary",
title: "Logout",
action: async () => {
- if (await db.hasUnsyncedChanges()) {
- const backup = await ConfirmDialog.show({
- title: "You have unsynced changes",
- message:
- "Do you want to take a backup before logging out to prevent data loss?",
- negativeButtonText: "No",
- positiveButtonText: "Yes"
- });
- if (backup) await createBackup({ mode: "partial" });
- }
+ const result = await showLogoutConfirmation();
+ if (!result) return;
- if (await showLogoutConfirmation()) {
- await TaskManager.startTask({
- type: "modal",
- title: "You are being logged out",
- subtitle: "Please wait...",
- action: () => db.user.logout(true)
- });
- showToast("success", "You have been logged out.");
+ if (result.backup) {
+ try {
+ await createBackup({ mode: "partial" });
+ } catch (e) {
+ logger.error(e, "Failed to take backup before logout");
+ if (
+ !(await ConfirmDialog.show({
+ title: "Failed to take backup",
+ message:
+ "Failed to take backup of your data. Do you want to continue logging out?",
+ negativeButtonText: "No",
+ positiveButtonText: "Yes"
+ }))
+ )
+ return;
+ }
}
+
+ await TaskManager.startTask({
+ type: "modal",
+ title: "You are being logged out",
+ subtitle: "Please wait...",
+ action: () => db.user.logout(true)
+ });
+ showToast("success", "You have been logged out.");
}
}
]