Implement VencordDesktop, improve tray

This commit is contained in:
Vendicated 2023-04-04 01:35:37 +02:00
parent f45d6482ac
commit 1c20f35460
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
6 changed files with 57 additions and 22 deletions

View file

@ -1,8 +1,13 @@
import { ipcMain } from "electron";
import { app, ipcMain } from "electron";
import { join } from "path";
import { GET_PRELOAD_FILE } from "../shared/IpcEvents";
import { GET_PRELOAD_FILE, RELAUNCH } from "../shared/IpcEvents";
import { VENCORD_FILES_DIR } from "./constants";
ipcMain.on(GET_PRELOAD_FILE, e => {
e.returnValue = join(VENCORD_FILES_DIR, "preload.js");
});
ipcMain.handle(RELAUNCH, () => {
app.relaunch();
app.exit();
});

View file

@ -1,5 +1,6 @@
import { BrowserWindow, Menu, Tray, app } from "electron";
import { join } from "path";
import { ICON_PATH } from "../shared/paths";
export function createMainWindow() {
let isQuitting = false;
@ -13,9 +14,31 @@ export function createMainWindow() {
devTools: true,
preload: join(__dirname, "preload.js")
},
icon: join(__dirname, "..", "..", "static", "icon.ico")
icon: ICON_PATH
});
const trayMenu = Menu.buildFromTemplate([
{
label: "Open",
click() {
win.show();
},
enabled: false
},
{
label: "Quit Vencord Desktop",
click() {
isQuitting = true;
app.quit();
}
}
]);
const tray = new Tray(ICON_PATH);
tray.setToolTip("Vencord Desktop");
tray.setContextMenu(trayMenu);
tray.on("click", () => win.show());
app.on("before-quit", () => {
isQuitting = true;
});
@ -29,24 +52,14 @@ export function createMainWindow() {
return false;
});
const tray = new Tray(join(__dirname, "..", "..", "static", "icon.ico"));
tray.setToolTip("Vencord Desktop");
tray.setContextMenu(Menu.buildFromTemplate([
{
label: "Open",
click() {
win.show();
}
},
{
label: "Quit",
click() {
isQuitting = true;
app.quit();
}
}
]));
tray.on("click", () => win.show());
win.on("show", () => {
trayMenu.items[0].enabled = false;
});
win.on("hide", () => {
trayMenu.items[0].enabled = true;
});
win.loadURL("https://discord.com/app");

View file

@ -0,0 +1,9 @@
import { ipcRenderer } from "electron";
import { RELAUNCH } from "../shared/IpcEvents";
export const VencordDesktop = {
app: {
relaunch: () => ipcRenderer.invoke(RELAUNCH)
}
}

View file

@ -1,4 +1,7 @@
import { ipcRenderer } from "electron";
import { contextBridge, ipcRenderer } from "electron";
import { GET_PRELOAD_FILE } from "../shared/IpcEvents";
import { VencordDesktop } from "./VencordDesktop";
contextBridge.exposeInMainWorld("VencordDesktop", VencordDesktop);
require(ipcRenderer.sendSync(GET_PRELOAD_FILE));

View file

@ -1 +1,2 @@
export const GET_PRELOAD_FILE = "VCD_GET_PRELOAD_FILE";
export const RELAUNCH = "VCD_RELAUNCH";

4
src/shared/paths.ts Normal file
View file

@ -0,0 +1,4 @@
import { join } from "path";
export const STATIC_DIR = join(__dirname, "..", "..", "static");
export const ICON_PATH = join(STATIC_DIR, "icon.ico");