Skip to content

Commit

Permalink
feat: add "Reset Vesktop" option to menu & tray (#53)
Browse files Browse the repository at this point in the history
Co-authored-by: V <[email protected]>
  • Loading branch information
ryanccn and Vendicated authored Jul 14, 2023
1 parent 6d35be7 commit d884b7d
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions src/main/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
* 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 { rm } from "fs/promises";
import { join } from "path";
import { IpcEvents } from "shared/IpcEvents";
import { isTruthy } from "shared/utils/guards";
Expand All @@ -14,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";
Expand Down Expand Up @@ -71,6 +80,12 @@ function initTray(win: BrowserWindow) {
app.quit();
}
},
{
label: "Reset Vesktop",
async click() {
await clearData(win);
}
},
{
type: "separator"
},
Expand Down Expand Up @@ -104,6 +119,34 @@ 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 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,
type: "warning"
});

if (response === MessageBoxChoice.Cancel) return;

win.close();

await win.webContents.session.clearStorageData();
await win.webContents.session.clearCache();
await win.webContents.session.clearCodeCaches({});
await rm(DATA_DIR, { force: true, recursive: true });

app.relaunch();
app.quit();
}

function initMenuBar(win: BrowserWindow) {
const isWindows = process.platform === "win32";
const isDarwin = process.platform === "darwin";
Expand All @@ -123,6 +166,13 @@ function initMenuBar(win: BrowserWindow) {
},
toolTip: "Vesktop will automatically restart after this operation"
},
{
label: "Reset Vesktop",
async click() {
await clearData(win);
},
toolTip: "Vesktop will automatically restart after this operation"
},
{
label: "Relaunch",
accelerator: "CmdOrCtrl+Shift+R",
Expand Down

0 comments on commit d884b7d

Please sign in to comment.