This commit is contained in:
Oleh Polisan 2024-10-26 12:56:31 +01:00 committed by GitHub
commit 82a338a942
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 104 additions and 4 deletions

View file

@ -74,3 +74,6 @@ export const enum MessageBoxChoice {
Default,
Cancel
}
export const isWayland =
process.platform === "linux" && (process.env.XDG_SESSION_TYPE === "wayland" || !!process.env.WAYLAND_DISPLAY);

80
src/main/keybinds.ts Normal file
View file

@ -0,0 +1,80 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { spawnSync } from "node:child_process";
import { constants, existsSync, open, unlinkSync } from "node:fs";
import { join } from "node:path";
import { Socket } from "net";
import { IpcEvents } from "shared/IpcEvents";
import { mainWin } from "./mainWindow";
const xdgRuntimeDir = process.env.XDG_RUNTIME_DIR || process.env.TMP || "/tmp";
const socketFile = join(xdgRuntimeDir, "vesktop-ipc");
const Actions = new Set([IpcEvents.TOGGLE_SELF_DEAF, IpcEvents.TOGGLE_SELF_MUTE]);
function createFIFO() {
if (existsSync(socketFile)) {
try {
unlinkSync(socketFile);
} catch (err) {
console.error("Failed to remove existing mkfifo file:", err);
return false;
}
}
try {
spawnSync("mkfifo", [socketFile]);
} catch (err) {
console.error("Failed to create mkfifo while initializing keybinds:", err);
return false;
}
return true;
}
function openFIFO() {
try {
open(socketFile, constants.O_RDONLY | constants.O_NONBLOCK, (err, fd) => {
if (err) {
console.error("Error opening pipe while initializing keybinds:", err);
return;
}
const pipe = new Socket({ fd });
pipe.on("data", data => {
const action = data.toString().trim();
if (Actions.has(action as IpcEvents)) {
mainWin.webContents.send(action);
}
});
pipe.on("end", () => {
pipe.destroy();
openFIFO();
});
});
} catch (err) {
console.error("Can't open socket file.", err);
}
}
function cleanup() {
try {
unlinkSync(socketFile);
} catch (err) {
console.error("Failed to remove mkfifo file:", err);
}
}
process.on("exit", cleanup);
export function initKeybinds() {
if (createFIFO()) {
openFIFO();
}
}

View file

@ -31,11 +31,13 @@ import {
DATA_DIR,
DEFAULT_HEIGHT,
DEFAULT_WIDTH,
isWayland,
MessageBoxChoice,
MIN_HEIGHT,
MIN_WIDTH,
VENCORD_FILES_DIR
} from "./constants";
import { initKeybinds } from "./keybinds";
import { Settings, State, VencordSettings } from "./settings";
import { createSplashWindow } from "./splash";
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
@ -512,4 +514,5 @@ export async function createWindows() {
});
initArRPC();
if (isWayland) initKeybinds();
}

View file

@ -8,11 +8,9 @@ import { desktopCapturer, session, Streams } from "electron";
import type { StreamPick } from "renderer/components/ScreenSharePicker";
import { IpcEvents } from "shared/IpcEvents";
import { isWayland } from "./constants";
import { handle } from "./utils/ipcWrappers";
const isWayland =
process.platform === "linux" && (process.env.XDG_SESSION_TYPE === "wayland" || !!process.env.WAYLAND_DISPLAY);
export function registerScreenShareHandler() {
handle(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, async (_, id: string) => {
const sources = await desktopCapturer.getSources({

View file

@ -78,5 +78,13 @@ export const VesktopNative = {
clipboard: {
copyImage: (imageBuffer: Uint8Array, imageSrc: string) =>
invoke<void>(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc)
},
voice: {
onToggleSelfMute: (listener: (...args: any[]) => void) => {
ipcRenderer.on(IpcEvents.TOGGLE_SELF_MUTE, listener);
},
onToggleSelfDeaf: (listener: (...args: any[]) => void) => {
ipcRenderer.on(IpcEvents.TOGGLE_SELF_DEAF, listener);
}
}
};

View file

@ -60,6 +60,12 @@ VesktopNative.arrpc.onActivity(async data => {
arRPC.handleEvent(new MessageEvent("message", { data }));
});
const VoiceActions = findByPropsLazy("toggleSelfMute");
VesktopNative.voice.onToggleSelfMute(() => VoiceActions.toggleSelfMute());
VesktopNative.voice.onToggleSelfDeaf(() => VoiceActions.toggleSelfDeaf());
// TODO: remove soon
const vencordDir = "vencordDir" as keyof typeof Settings.store;
if (Settings.store[vencordDir]) {

View file

@ -50,5 +50,7 @@ export const enum IpcEvents {
ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY",
CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE"
CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE",
TOGGLE_SELF_MUTE = "VCD_TOGGLE_SELF_MUTE",
TOGGLE_SELF_DEAF = "VCD_TOGGLE_SELF_DEAF"
}