Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "Reset Vesktop" option to menu & tray #53

Merged
merged 8 commits into from
Jul 14, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 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 { rmdir } 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 app",
async click() {
await clearData(win);
}
},
{
type: "separator"
},
Expand Down Expand Up @@ -104,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?",
Vendicated marked this conversation as resolved.
Show resolved Hide resolved
detail: "Vencord Desktop will automatically restart after this operation.",
buttons: ["Yes", "No"],
cancelId: 1,
defaultId: 0,
Vendicated marked this conversation as resolved.
Show resolved Hide resolved
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";
Expand All @@ -123,6 +161,13 @@ function initMenuBar(win: BrowserWindow) {
},
toolTip: "Vencord Desktop will automatically restart after this operation"
},
{
label: "Reset app",
async click() {
await clearData(win);
},
toolTip: "Vencord Desktop will automatically restart after this operation"
},
{
label: "Relaunch",
accelerator: "CmdOrCtrl+Shift+R",
Expand Down