mirror of
https://github.com/Vencord/Vesktop.git
synced 2025-02-23 13:45:09 +00:00
Make clicking notifications focus VC Desktop
This commit is contained in:
parent
2efed86b71
commit
cf23b6d028
7 changed files with 36 additions and 7 deletions
5
src/globals.d.ts
vendored
Normal file
5
src/globals.d.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
declare global {
|
||||||
|
export var VencordDesktop: typeof import("./preload/VencordDesktop").VencordDesktop;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { };
|
|
@ -1,8 +1,9 @@
|
||||||
import { app, ipcMain, shell } from "electron";
|
import { app, ipcMain, shell } from "electron";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { GET_RENDERER_SCRIPT, GET_SETTINGS, GET_VENCORD_PRELOAD_FILE, RELAUNCH, SET_SETTINGS, SHOW_IN_FOLDER } from "../shared/IpcEvents";
|
import { FOCUS, GET_RENDERER_SCRIPT, GET_SETTINGS, GET_VENCORD_PRELOAD_FILE, RELAUNCH, SET_SETTINGS, SHOW_ITEM_IN_FOLDER } from "../shared/IpcEvents";
|
||||||
import { VENCORD_FILES_DIR } from "./constants";
|
import { VENCORD_FILES_DIR } from "./constants";
|
||||||
|
import { mainWin } from "./mainWindow";
|
||||||
import { PlainSettings, setSettings } from "./settings";
|
import { PlainSettings, setSettings } from "./settings";
|
||||||
|
|
||||||
ipcMain.on(GET_VENCORD_PRELOAD_FILE, e => {
|
ipcMain.on(GET_VENCORD_PRELOAD_FILE, e => {
|
||||||
|
@ -26,6 +27,10 @@ ipcMain.handle(RELAUNCH, () => {
|
||||||
app.exit();
|
app.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle(SHOW_IN_FOLDER, (_, path) => {
|
ipcMain.handle(SHOW_ITEM_IN_FOLDER, (_, path) => {
|
||||||
shell.showItemInFolder(path);
|
shell.showItemInFolder(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle(FOCUS, () => {
|
||||||
|
mainWin?.focus();
|
||||||
|
});
|
||||||
|
|
|
@ -9,6 +9,8 @@ app.on("before-quit", () => {
|
||||||
isQuitting = true;
|
isQuitting = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export let mainWin: BrowserWindow;
|
||||||
|
|
||||||
function initWindowOpenHandler(win: BrowserWindow) {
|
function initWindowOpenHandler(win: BrowserWindow) {
|
||||||
win.webContents.setWindowOpenHandler(({ url }) => {
|
win.webContents.setWindowOpenHandler(({ url }) => {
|
||||||
switch (url) {
|
switch (url) {
|
||||||
|
@ -115,7 +117,7 @@ function initWindowBoundsListeners(win: BrowserWindow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createMainWindow() {
|
export function createMainWindow() {
|
||||||
const win = new BrowserWindow({
|
const win = mainWin = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer } from "electron";
|
||||||
import type { Settings } from "../main/settings";
|
import type { Settings } from "../main/settings";
|
||||||
import { GET_SETTINGS, RELAUNCH, SET_SETTINGS, SHOW_IN_FOLDER } from "../shared/IpcEvents";
|
import { FOCUS, GET_SETTINGS, RELAUNCH, SET_SETTINGS, SHOW_ITEM_IN_FOLDER } from "../shared/IpcEvents";
|
||||||
|
|
||||||
export const VencordDesktop = {
|
export const VencordDesktop = {
|
||||||
app: {
|
app: {
|
||||||
relaunch: () => ipcRenderer.invoke(RELAUNCH)
|
relaunch: () => ipcRenderer.invoke(RELAUNCH)
|
||||||
},
|
},
|
||||||
files: {
|
fileManager: {
|
||||||
showInFolder: (path: string) => ipcRenderer.invoke(SHOW_IN_FOLDER, path)
|
showItemInFolder: (path: string) => ipcRenderer.invoke(SHOW_ITEM_IN_FOLDER, path)
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
get: () => ipcRenderer.sendSync(GET_SETTINGS),
|
get: () => ipcRenderer.sendSync(GET_SETTINGS),
|
||||||
set: (settings: typeof Settings) => ipcRenderer.invoke(SET_SETTINGS, settings)
|
set: (settings: typeof Settings) => ipcRenderer.invoke(SET_SETTINGS, settings)
|
||||||
|
},
|
||||||
|
win: {
|
||||||
|
focus: () => ipcRenderer.invoke(FOCUS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
src/renderer/fixes.ts
Normal file
11
src/renderer/fixes.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// Make clicking Notifications focus the window
|
||||||
|
const originalSetOnClick = Object.getOwnPropertyDescriptor(Notification.prototype, "onclick")!.set!;
|
||||||
|
Object.defineProperty(Notification.prototype, "onclick", {
|
||||||
|
set(onClick) {
|
||||||
|
originalSetOnClick.call(this, function () {
|
||||||
|
onClick.apply(this, arguments);
|
||||||
|
VencordDesktop.win.focus();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
configurable: true
|
||||||
|
});
|
|
@ -1 +1,3 @@
|
||||||
|
import "./fixes";
|
||||||
|
|
||||||
console.log("read if cute :3");
|
console.log("read if cute :3");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
export const GET_VENCORD_PRELOAD_FILE = "VCD_GET_VC_PRELOAD_FILE";
|
export const GET_VENCORD_PRELOAD_FILE = "VCD_GET_VC_PRELOAD_FILE";
|
||||||
export const GET_RENDERER_SCRIPT = "VCD_GET_RENDERER_SCRIPT";
|
export const GET_RENDERER_SCRIPT = "VCD_GET_RENDERER_SCRIPT";
|
||||||
export const RELAUNCH = "VCD_RELAUNCH";
|
export const RELAUNCH = "VCD_RELAUNCH";
|
||||||
export const SHOW_IN_FOLDER = "VCD_SHOW_IN_FOLDER";
|
export const SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER";
|
||||||
export const GET_SETTINGS = "VCD_GET_SETTINGS";
|
export const GET_SETTINGS = "VCD_GET_SETTINGS";
|
||||||
export const SET_SETTINGS = "VCD_SET_SETTINGS";
|
export const SET_SETTINGS = "VCD_SET_SETTINGS";
|
||||||
|
export const FOCUS = "VC_FOCUS";
|
||||||
|
|
Loading…
Add table
Reference in a new issue