Skip to content

Commit

Permalink
cli based toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxinal committed Mar 8, 2024
1 parent d222d4f commit 02803f0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
29 changes: 21 additions & 8 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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() {
Expand Down
20 changes: 3 additions & 17 deletions src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/preload/VesktopNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
};
2 changes: 1 addition & 1 deletion src/renderer/patches/keybinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ addPatch({
},
unregisterKeybind: function (id) {
delete keybindCallbacks[id];
VesktopNative.keybind.uregister(id);
VesktopNative.keybind.unregister(id);
}
});

0 comments on commit 02803f0

Please sign in to comment.