Implement VencordDesktop, improve tray
This commit is contained in:
parent
f45d6482ac
commit
1c20f35460
6 changed files with 57 additions and 22 deletions
|
@ -1,8 +1,13 @@
|
||||||
import { ipcMain } from "electron";
|
import { app, ipcMain } from "electron";
|
||||||
import { join } from "path";
|
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";
|
import { VENCORD_FILES_DIR } from "./constants";
|
||||||
|
|
||||||
ipcMain.on(GET_PRELOAD_FILE, e => {
|
ipcMain.on(GET_PRELOAD_FILE, e => {
|
||||||
e.returnValue = join(VENCORD_FILES_DIR, "preload.js");
|
e.returnValue = join(VENCORD_FILES_DIR, "preload.js");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle(RELAUNCH, () => {
|
||||||
|
app.relaunch();
|
||||||
|
app.exit();
|
||||||
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { BrowserWindow, Menu, Tray, app } from "electron";
|
import { BrowserWindow, Menu, Tray, app } from "electron";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
import { ICON_PATH } from "../shared/paths";
|
||||||
|
|
||||||
export function createMainWindow() {
|
export function createMainWindow() {
|
||||||
let isQuitting = false;
|
let isQuitting = false;
|
||||||
|
@ -13,9 +14,31 @@ export function createMainWindow() {
|
||||||
devTools: true,
|
devTools: true,
|
||||||
preload: join(__dirname, "preload.js")
|
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", () => {
|
app.on("before-quit", () => {
|
||||||
isQuitting = true;
|
isQuitting = true;
|
||||||
});
|
});
|
||||||
|
@ -29,24 +52,14 @@ export function createMainWindow() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
const tray = new Tray(join(__dirname, "..", "..", "static", "icon.ico"));
|
win.on("show", () => {
|
||||||
tray.setToolTip("Vencord Desktop");
|
trayMenu.items[0].enabled = false;
|
||||||
tray.setContextMenu(Menu.buildFromTemplate([
|
});
|
||||||
{
|
|
||||||
label: "Open",
|
win.on("hide", () => {
|
||||||
click() {
|
trayMenu.items[0].enabled = true;
|
||||||
win.show();
|
});
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Quit",
|
|
||||||
click() {
|
|
||||||
isQuitting = true;
|
|
||||||
app.quit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]));
|
|
||||||
tray.on("click", () => win.show());
|
|
||||||
|
|
||||||
win.loadURL("https://discord.com/app");
|
win.loadURL("https://discord.com/app");
|
||||||
|
|
||||||
|
|
9
src/preload/VencordDesktop.ts
Normal file
9
src/preload/VencordDesktop.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import { ipcRenderer } from "electron";
|
||||||
|
import { RELAUNCH } from "../shared/IpcEvents";
|
||||||
|
|
||||||
|
export const VencordDesktop = {
|
||||||
|
app: {
|
||||||
|
relaunch: () => ipcRenderer.invoke(RELAUNCH)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
import { ipcRenderer } from "electron";
|
import { contextBridge, ipcRenderer } from "electron";
|
||||||
import { GET_PRELOAD_FILE } from "../shared/IpcEvents";
|
import { GET_PRELOAD_FILE } from "../shared/IpcEvents";
|
||||||
|
import { VencordDesktop } from "./VencordDesktop";
|
||||||
|
|
||||||
|
contextBridge.exposeInMainWorld("VencordDesktop", VencordDesktop);
|
||||||
|
|
||||||
require(ipcRenderer.sendSync(GET_PRELOAD_FILE));
|
require(ipcRenderer.sendSync(GET_PRELOAD_FILE));
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
export const GET_PRELOAD_FILE = "VCD_GET_PRELOAD_FILE";
|
export const GET_PRELOAD_FILE = "VCD_GET_PRELOAD_FILE";
|
||||||
|
export const RELAUNCH = "VCD_RELAUNCH";
|
||||||
|
|
4
src/shared/paths.ts
Normal file
4
src/shared/paths.ts
Normal 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");
|
Loading…
Reference in a new issue