cli based toggles
Co-Authored-By: exhq <infidelLOler@gmail.com>
This commit is contained in:
parent
d222d4ffc1
commit
8d3196c96c
4 changed files with 26 additions and 27 deletions
|
@ -47,8 +47,12 @@ function init() {
|
|||
// In the Flatpak on SteamOS the theme is detected as light, but SteamOS only has a dark mode, so we just override it
|
||||
if (isDeckGameMode) nativeTheme.themeSource = "dark";
|
||||
|
||||
app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => {
|
||||
if (data.IS_DEV) app.quit();
|
||||
app.on("second-instance", (_event, cmdLine, _cwd, data: any) => {
|
||||
const keybindIndex = cmdLine.indexOf("--keybind");
|
||||
|
||||
if (keybindIndex !== -1) {
|
||||
mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${cmdLine[keybindIndex + 1]}](false)`);
|
||||
} else if (data.IS_DEV) app.quit();
|
||||
else if (mainWin) {
|
||||
if (mainWin.isMinimized()) mainWin.restore();
|
||||
if (!mainWin.isVisible()) mainWin.show();
|
||||
|
@ -72,15 +76,24 @@ function init() {
|
|||
}
|
||||
|
||||
if (!app.requestSingleInstanceLock({ IS_DEV })) {
|
||||
if (IS_DEV) {
|
||||
console.log("Vesktop is already running. Quitting previous instance...");
|
||||
init();
|
||||
} else {
|
||||
console.log("Vesktop is already running. Quitting...");
|
||||
if (process.argv.includes("--keybind")) {
|
||||
app.quit();
|
||||
} else {
|
||||
if (IS_DEV) {
|
||||
console.log("Vesktop is already running. Quitting previous instance...");
|
||||
init();
|
||||
} else {
|
||||
console.log("Vesktop is already running. Quitting...");
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
init();
|
||||
if (process.argv.includes("--keybind")) {
|
||||
console.error("No instances running! cannot issue a keybind!");
|
||||
app.quit();
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
async function bootstrap() {
|
||||
|
|
|
@ -7,17 +7,7 @@
|
|||
if (process.platform === "linux") import("./venmic");
|
||||
|
||||
import { execFile } from "child_process";
|
||||
import {
|
||||
app,
|
||||
BrowserWindow,
|
||||
clipboard,
|
||||
dialog,
|
||||
globalShortcut,
|
||||
nativeImage,
|
||||
RelaunchOptions,
|
||||
session,
|
||||
shell
|
||||
} from "electron";
|
||||
import { app, BrowserWindow, clipboard, dialog, nativeImage, RelaunchOptions, session, shell } from "electron";
|
||||
import { mkdirSync, readFileSync, watch } from "fs";
|
||||
import { open, readFile } from "fs/promises";
|
||||
import { release } from "os";
|
||||
|
@ -143,15 +133,11 @@ handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string)
|
|||
const registered_keybinds = {};
|
||||
|
||||
handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => {
|
||||
globalShortcut.register(shortcut, () => {
|
||||
// false here implies `keyup`
|
||||
// electron's global shortcut system doesn't really register keyup or down as far as i can tell
|
||||
mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${id}](false)`);
|
||||
});
|
||||
registered_keybinds[id] = shortcut;
|
||||
console.log(registered_keybinds);
|
||||
});
|
||||
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => {
|
||||
globalShortcut.unregister(registered_keybinds[id]);
|
||||
delete registered_keybinds[id];
|
||||
});
|
||||
|
||||
function readCss() {
|
||||
|
|
|
@ -79,6 +79,6 @@ export const VesktopNative = {
|
|||
keybind: {
|
||||
register: (id: number, shortcut: string, options: any) =>
|
||||
invoke<void>(IpcEvents.KEYBIND_REGISTER, id, shortcut),
|
||||
uregister: (id: number) => invoke<void>(IpcEvents.KEYBIND_UNREGISTER, id)
|
||||
unregister: (id: number) => invoke<void>(IpcEvents.KEYBIND_UNREGISTER, id)
|
||||
}
|
||||
};
|
||||
|
|
|
@ -50,6 +50,6 @@ addPatch({
|
|||
},
|
||||
unregisterKeybind: function (id) {
|
||||
delete keybindCallbacks[id];
|
||||
VesktopNative.keybind.uregister(id);
|
||||
VesktopNative.keybind.unregister(id);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue