Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

refactor: extract Hyprland detection into helper with guard

Gabriel Steinefb0fc4d81ea
diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.js
index 1022c0711..d09278d2b 100644
--- a/src/helpers/clipboard.js
+++ b/src/helpers/clipboard.js
@@ -40,8 +40,9 @@ const getLinuxSessionInfo = () => {
const isGnome = isWayland && isGnomeDesktop(desktopEnv);
const isKde = isWayland && isKdeDesktop(desktopEnv);
const isWlroots = isWayland && isWlrootsCompositor(desktopEnv);
+ const isHyprland = isWayland && !!process.env.HYPRLAND_INSTANCE_SIGNATURE;
- return { isWayland, xwaylandAvailable, desktopEnv, isGnome, isKde, isWlroots };
+ return { isWayland, xwaylandAvailable, desktopEnv, isGnome, isKde, isWlroots, isHyprland };
};
const PASTE_DELAYS = {
@@ -505,6 +506,18 @@ class ClipboardManager {
return null;
}
+ _detectHyprlandWindowClass() {
+ try {
+ const result = spawnSync("hyprctl", ["activewindow", "-j"], { timeout: 1000 });
+ if (result.status !== 0) return null;
+ const win = JSON.parse(result.stdout.toString());
+ return win.class?.toLowerCase() || null;
+ } catch (err) {
+ debugLogger.warn("hyprctl window detection failed", { error: err?.message }, "clipboard");
+ return null;
+ }
+ }
+
safeLog(...args) {
if (process.env.NODE_ENV === "development") {
try {
@@ -997,7 +1010,8 @@ class ClipboardManager {
}
async pasteLinux(originalClipboard, options = {}) {
- const { isWayland, xwaylandAvailable, isGnome, isKde, isWlroots } = getLinuxSessionInfo();
+ const { isWayland, xwaylandAvailable, isGnome, isKde, isWlroots, isHyprland } =
+ getLinuxSessionInfo();
const webContents = options.webContents;
const xdotoolExists = this.commandExists("xdotool");
const wtypeExists = this.commandExists("wtype");
@@ -1099,17 +1113,11 @@ class ClipboardManager {
}
}
- if (!detectedWindowClass) {
- try {
- const hyprResult = spawnSync("hyprctl", ["activewindow", "-j"]);
- if (hyprResult.status === 0) {
- const win = JSON.parse(hyprResult.stdout.toString());
- detectedWindowClass = win.class?.toLowerCase() || null;
- if (detectedWindowClass) {
- debugLogger.debug("Hyprland window class detected", { detectedWindowClass }, "clipboard");
- }
- }
- } catch {}
+ if (!detectedWindowClass && isHyprland) {
+ detectedWindowClass = this._detectHyprlandWindowClass();
+ if (detectedWindowClass) {
+ debugLogger.debug("Hyprland window class detected", { detectedWindowClass }, "clipboard");
+ }
}
if (linuxFastPaste) {