From 2e921311074f95e49976070bba2d337d6f56f73a Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sun, 9 Jul 2023 17:28:12 +0800 Subject: [PATCH 1/7] feat: add menu bar item to clear data --- src/main/mainWindow.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 65f2c469..3c6aa2a8 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -123,6 +123,17 @@ function initMenuBar(win: BrowserWindow) { }, toolTip: "Vencord Desktop will automatically restart after this operation" }, + { + label: "Clear data", + async click() { + await win.webContents.session.clearStorageData(); + await win.webContents.session.clearCache(); + await win.webContents.session.clearCodeCaches({}); + app.relaunch(); + app.quit(); + }, + toolTip: "Vencord Desktop will automatically restart after this operation" + }, { label: "Relaunch", accelerator: "CmdOrCtrl+Shift+R", From 9b9c7eb6dab20ef0282b8b8f12baa2351573c0f5 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sun, 9 Jul 2023 17:37:34 +0800 Subject: [PATCH 2/7] add dialog box --- src/main/mainWindow.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 3c6aa2a8..0cddc18f 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -4,7 +4,15 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ -import { app, BrowserWindow, BrowserWindowConstructorOptions, Menu, MenuItemConstructorOptions, Tray } from "electron"; +import { + app, + BrowserWindow, + BrowserWindowConstructorOptions, + dialog, + Menu, + MenuItemConstructorOptions, + Tray +} from "electron"; import { join } from "path"; import { IpcEvents } from "shared/IpcEvents"; import { isTruthy } from "shared/utils/guards"; @@ -126,9 +134,21 @@ function initMenuBar(win: BrowserWindow) { { label: "Clear data", async click() { + const { response } = await dialog.showMessageBox(win, { + message: "Are you sure you want to clear all web storage?", + detail: "Vencord Desktop will automatically restart after this operation", + buttons: ["Yes", "No"], + cancelId: 1, + defaultId: 0, + type: "warning" + }); + + if (response === 1) return; + await win.webContents.session.clearStorageData(); await win.webContents.session.clearCache(); await win.webContents.session.clearCodeCaches({}); + app.relaunch(); app.quit(); }, From e240342c209741c439b807a3bde09074e1f2cdaa Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Mon, 10 Jul 2023 11:56:05 +0800 Subject: [PATCH 3/7] reset app --- src/main/mainWindow.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 0cddc18f..8afa3132 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -13,6 +13,7 @@ import { MenuItemConstructorOptions, Tray } from "electron"; +import { rmdir } from "fs/promises"; import { join } from "path"; import { IpcEvents } from "shared/IpcEvents"; import { isTruthy } from "shared/utils/guards"; @@ -22,7 +23,7 @@ import type { SettingsStore } from "shared/utils/SettingsStore"; import { ICON_PATH } from "../shared/paths"; import { createAboutWindow } from "./about"; import { initArRPC } from "./arrpc"; -import { DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH, VENCORD_FILES_DIR } from "./constants"; +import { DATA_DIR, DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH, VENCORD_FILES_DIR } from "./constants"; import { Settings, VencordSettings } from "./settings"; import { createSplashWindow } from "./splash"; import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally"; @@ -135,8 +136,8 @@ function initMenuBar(win: BrowserWindow) { label: "Clear data", async click() { const { response } = await dialog.showMessageBox(win, { - message: "Are you sure you want to clear all web storage?", - detail: "Vencord Desktop will automatically restart after this operation", + message: "Are you sure you want to reset Vencord Desktop?", + detail: "Vencord Desktop will automatically restart after this operation.", buttons: ["Yes", "No"], cancelId: 1, defaultId: 0, @@ -145,9 +146,12 @@ function initMenuBar(win: BrowserWindow) { if (response === 1) return; + win.close(); + await win.webContents.session.clearStorageData(); await win.webContents.session.clearCache(); await win.webContents.session.clearCodeCaches({}); + await rmdir(DATA_DIR); app.relaunch(); app.quit(); From aa9e7cad9e73bd5025cd13d269bb5908d0703465 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Wed, 12 Jul 2023 12:36:14 +0800 Subject: [PATCH 4/7] add to tray --- src/main/mainWindow.ts | 52 +++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 8afa3132..24e3289e 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -80,6 +80,12 @@ function initTray(win: BrowserWindow) { app.quit(); } }, + { + label: "Reset app", + async click() { + await clearData(win); + } + }, { type: "separator" }, @@ -113,6 +119,29 @@ function initTray(win: BrowserWindow) { }); } +async function clearData(win: BrowserWindow) { + const { response } = await dialog.showMessageBox(win, { + message: "Are you sure you want to reset Vencord Desktop?", + detail: "Vencord Desktop will automatically restart after this operation.", + buttons: ["Yes", "No"], + cancelId: 1, + defaultId: 0, + type: "warning" + }); + + if (response === 1) return; + + win.close(); + + await win.webContents.session.clearStorageData(); + await win.webContents.session.clearCache(); + await win.webContents.session.clearCodeCaches({}); + await rmdir(DATA_DIR); + + app.relaunch(); + app.quit(); +} + function initMenuBar(win: BrowserWindow) { const isWindows = process.platform === "win32"; const isDarwin = process.platform === "darwin"; @@ -133,28 +162,9 @@ function initMenuBar(win: BrowserWindow) { toolTip: "Vencord Desktop will automatically restart after this operation" }, { - label: "Clear data", + label: "Reset app", async click() { - const { response } = await dialog.showMessageBox(win, { - message: "Are you sure you want to reset Vencord Desktop?", - detail: "Vencord Desktop will automatically restart after this operation.", - buttons: ["Yes", "No"], - cancelId: 1, - defaultId: 0, - type: "warning" - }); - - if (response === 1) return; - - win.close(); - - await win.webContents.session.clearStorageData(); - await win.webContents.session.clearCache(); - await win.webContents.session.clearCodeCaches({}); - await rmdir(DATA_DIR); - - app.relaunch(); - app.quit(); + await clearData(win); }, toolTip: "Vencord Desktop will automatically restart after this operation" }, From f1ee4a8e99154ea098ec3c103954a799d0f1ca49 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 14 Jul 2023 02:11:17 +0200 Subject: [PATCH 5/7] Address issues --- src/main/mainWindow.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index b6b5806a..f77d273a 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -13,7 +13,7 @@ import { MenuItemConstructorOptions, Tray } from "electron"; -import { rmdir } from "fs/promises"; +import { rm } from "fs/promises"; import { join } from "path"; import { IpcEvents } from "shared/IpcEvents"; import { isTruthy } from "shared/utils/guards"; @@ -119,24 +119,30 @@ function initTray(win: BrowserWindow) { }); } +const enum MessageBoxChoice { + Default, + Cancel +} + async function clearData(win: BrowserWindow) { const { response } = await dialog.showMessageBox(win, { - message: "Are you sure you want to reset Vencord Desktop?", - detail: "Vencord Desktop will automatically restart after this operation.", + message: + "Are you sure you want to reset Vesktop? This will log you out, clear caches and reset all your settings", + detail: "Vesktop will automatically restart after this operation.", buttons: ["Yes", "No"], - cancelId: 1, - defaultId: 0, + cancelId: MessageBoxChoice.Cancel, + defaultId: MessageBoxChoice.Default, type: "warning" }); - if (response === 1) return; + if (response === MessageBoxChoice.Cancel) return; win.close(); await win.webContents.session.clearStorageData(); await win.webContents.session.clearCache(); await win.webContents.session.clearCodeCaches({}); - await rmdir(DATA_DIR); + await rm(DATA_DIR, { force: true, recursive: true }); app.relaunch(); app.quit(); @@ -162,11 +168,11 @@ function initMenuBar(win: BrowserWindow) { toolTip: "Vesktop will automatically restart after this operation" }, { - label: "Reset app", + label: "Reset Vesktop", async click() { await clearData(win); }, - toolTip: "Vencord Desktop will automatically restart after this operation" + toolTip: "Vesktop will automatically restart after this operation" }, { label: "Relaunch", From f012e677a602927bb0d1d7ce92594c4464fef093 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 14 Jul 2023 02:11:48 +0200 Subject: [PATCH 6/7] Consistency --- src/main/mainWindow.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index f77d273a..d9d84afb 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -81,7 +81,7 @@ function initTray(win: BrowserWindow) { } }, { - label: "Reset app", + label: "Reset Vesktop", async click() { await clearData(win); } From 79fb798471138e380a80829a2d0e705de18a2911 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 14 Jul 2023 02:14:00 +0200 Subject: [PATCH 7/7] Move text to detail --- src/main/mainWindow.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index d9d84afb..ab62066b 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -126,9 +126,8 @@ const enum MessageBoxChoice { async function clearData(win: BrowserWindow) { const { response } = await dialog.showMessageBox(win, { - message: - "Are you sure you want to reset Vesktop? This will log you out, clear caches and reset all your settings", - detail: "Vesktop will automatically restart after this operation.", + message: "Are you sure you want to reset Vesktop?", + detail: "This will log you out, clear caches and reset all your settings!\n\nVesktop will automatically restart after this operation.", buttons: ["Yes", "No"], cancelId: MessageBoxChoice.Cancel, defaultId: MessageBoxChoice.Default,