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
|
// 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";
|
if (isDeckGameMode) nativeTheme.themeSource = "dark";
|
||||||
|
|
||||||
app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => {
|
app.on("second-instance", (_event, cmdLine, _cwd, data: any) => {
|
||||||
if (data.IS_DEV) app.quit();
|
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) {
|
else if (mainWin) {
|
||||||
if (mainWin.isMinimized()) mainWin.restore();
|
if (mainWin.isMinimized()) mainWin.restore();
|
||||||
if (!mainWin.isVisible()) mainWin.show();
|
if (!mainWin.isVisible()) mainWin.show();
|
||||||
|
@ -72,6 +76,9 @@ function init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!app.requestSingleInstanceLock({ IS_DEV })) {
|
if (!app.requestSingleInstanceLock({ IS_DEV })) {
|
||||||
|
if (process.argv.includes("--keybind")) {
|
||||||
|
app.quit();
|
||||||
|
} else {
|
||||||
if (IS_DEV) {
|
if (IS_DEV) {
|
||||||
console.log("Vesktop is already running. Quitting previous instance...");
|
console.log("Vesktop is already running. Quitting previous instance...");
|
||||||
init();
|
init();
|
||||||
|
@ -79,8 +86,14 @@ if (!app.requestSingleInstanceLock({ IS_DEV })) {
|
||||||
console.log("Vesktop is already running. Quitting...");
|
console.log("Vesktop is already running. Quitting...");
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (process.argv.includes("--keybind")) {
|
||||||
|
console.error("No instances running! cannot issue a keybind!");
|
||||||
|
app.quit();
|
||||||
|
} else {
|
||||||
init();
|
init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
|
|
|
@ -7,17 +7,7 @@
|
||||||
if (process.platform === "linux") import("./venmic");
|
if (process.platform === "linux") import("./venmic");
|
||||||
|
|
||||||
import { execFile } from "child_process";
|
import { execFile } from "child_process";
|
||||||
import {
|
import { app, BrowserWindow, clipboard, dialog, nativeImage, RelaunchOptions, session, shell } from "electron";
|
||||||
app,
|
|
||||||
BrowserWindow,
|
|
||||||
clipboard,
|
|
||||||
dialog,
|
|
||||||
globalShortcut,
|
|
||||||
nativeImage,
|
|
||||||
RelaunchOptions,
|
|
||||||
session,
|
|
||||||
shell
|
|
||||||
} from "electron";
|
|
||||||
import { mkdirSync, readFileSync, watch } from "fs";
|
import { mkdirSync, readFileSync, watch } from "fs";
|
||||||
import { open, readFile } from "fs/promises";
|
import { open, readFile } from "fs/promises";
|
||||||
import { release } from "os";
|
import { release } from "os";
|
||||||
|
@ -143,15 +133,11 @@ handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string)
|
||||||
const registered_keybinds = {};
|
const registered_keybinds = {};
|
||||||
|
|
||||||
handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => {
|
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;
|
registered_keybinds[id] = shortcut;
|
||||||
|
console.log(registered_keybinds);
|
||||||
});
|
});
|
||||||
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => {
|
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => {
|
||||||
globalShortcut.unregister(registered_keybinds[id]);
|
delete registered_keybinds[id];
|
||||||
});
|
});
|
||||||
|
|
||||||
function readCss() {
|
function readCss() {
|
||||||
|
|
|
@ -79,6 +79,6 @@ export const VesktopNative = {
|
||||||
keybind: {
|
keybind: {
|
||||||
register: (id: number, shortcut: string, options: any) =>
|
register: (id: number, shortcut: string, options: any) =>
|
||||||
invoke<void>(IpcEvents.KEYBIND_REGISTER, id, shortcut),
|
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) {
|
unregisterKeybind: function (id) {
|
||||||
delete keybindCallbacks[id];
|
delete keybindCallbacks[id];
|
||||||
VesktopNative.keybind.uregister(id);
|
VesktopNative.keybind.unregister(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue