Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of global shortcuts for mute and deafen #370

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sources/code/common/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { getRecommendedGPUFlags, getRedommendedOSFlags } from "../main/modules/o
import { styles } from "../main/modules/extensions";
import { parseArgs, ParseArgsConfig, stripVTControlCharacters, debug } from "util";
import { parseArgs as parseArgsPolyfill } from "@pkgjs/parseargs";
import { registerShortcuts } from "../main/modules/shortcuts";

const argvConfig = Object.freeze(({
options: Object.freeze({
Expand Down Expand Up @@ -368,7 +369,7 @@ function main(): void {
}, 30/*min*/*60000);
checkVersion(updateInterval).catch(commonCatches.print);
const mainWindow = createMainWindow({startHidden, screenShareAudio});

registerShortcuts(mainWindow);
// WebSocket server
import("../main/modules/socket")
.then(socket => socket.default())
Expand Down Expand Up @@ -529,4 +530,4 @@ app.on("child-process-gone", (_event, details) => {
console.error(kolor.bold("[%s:%d]")+" %s", name, details.exitCode, reason);
if(tip !== null) setImmediate(() => console.error(kolor.bold("[%s:TIP]")+" %s", name, tip));
}
});
});
16 changes: 16 additions & 0 deletions sources/code/main/modules/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { BrowserWindow, globalShortcut } from "electron/main";
import { commonCatches } from "./error";

export function registerShortcuts(window: BrowserWindow) {
globalShortcut.register("Insert", () => {
window.webContents.executeJavaScript(
"document.querySelector('button[aria-label=\"Mute\"').click()"
).catch(commonCatches.print);
});

globalShortcut.register("F1", () => {
window.webContents.executeJavaScript(
"document.querySelector('button[aria-label=\"Deafen\"').click()"
).catch(commonCatches.print);
});
}