From 5933ceab63de0a7a46e85d0b841acbf893d8fcec Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 24 Sep 2024 20:31:48 +0800 Subject: [PATCH] fix(invitation): reset app data then logout Signed-off-by: Innei --- apps/main/src/lib/cleaner.ts | 13 ++++++++++--- apps/main/src/menu.ts | 4 ++-- .../renderer/src/modules/auth/LoginModalContent.tsx | 2 +- apps/renderer/src/pages/(external)/invitation.tsx | 10 ++++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/apps/main/src/lib/cleaner.ts b/apps/main/src/lib/cleaner.ts index 18832311c..bd7d4883b 100644 --- a/apps/main/src/lib/cleaner.ts +++ b/apps/main/src/lib/cleaner.ts @@ -5,10 +5,9 @@ import { getMainWindow } from "~/window" import { t } from "./i18n" -export const clearAllData = async () => { +export const clearAllDataAndConfirm = async () => { const win = getMainWindow() if (!win) return - const ses = win.webContents.session // Dialog to confirm const result = await dialog.showMessageBox({ @@ -17,11 +16,19 @@ export const clearAllData = async () => { message: t("dialog.clearAllData"), buttons: [t("dialog.yes"), t("dialog.no")], }) - const caller = callWindowExpose(win) if (result.response === 1) { return } + return clearAllData() +} + +export const clearAllData = async () => { + const win = getMainWindow() + if (!win) return + const ses = win.webContents.session + const caller = callWindowExpose(win) + try { await ses.clearCache() diff --git a/apps/main/src/menu.ts b/apps/main/src/menu.ts index 5217438a1..e985df608 100644 --- a/apps/main/src/menu.ts +++ b/apps/main/src/menu.ts @@ -4,7 +4,7 @@ import type { BrowserWindow, MenuItem, MenuItemConstructorOptions } from "electr import { Menu } from "electron" import { isDev, isMacOS } from "./env" -import { clearAllData } from "./lib/cleaner" +import { clearAllDataAndConfirm } from "./lib/cleaner" import { t } from "./lib/i18n" import { revealLogFile } from "./logger" import { checkForUpdates, quitAndInstall } from "./updater" @@ -38,7 +38,7 @@ export const registerAppMenu = () => { { type: "separator" }, { label: t("menu.clearAllData"), - click: clearAllData, + click: clearAllDataAndConfirm, }, { role: "quit", label: t("menu.quit", { name }) }, ], diff --git a/apps/renderer/src/modules/auth/LoginModalContent.tsx b/apps/renderer/src/modules/auth/LoginModalContent.tsx index ed31594c2..1d699381f 100644 --- a/apps/renderer/src/modules/auth/LoginModalContent.tsx +++ b/apps/renderer/src/modules/auth/LoginModalContent.tsx @@ -105,7 +105,7 @@ const LoginButtonContent = (props: { children: React.ReactNode; isLoading: boole ) : ( { - signOut() - window.location.href = "/" + if (window.electron) { + tipcClient?.clearAllData().then(() => { + window.location.href = "/" + }) + } else { + signOut() + } }} >