From 9fb21b651faee1804f518bf03b8b3b28c5ca7f16 Mon Sep 17 00:00:00 2001 From: Richard Herman Date: Tue, 19 Aug 2025 13:47:34 +0100 Subject: [PATCH] refactor: reduce strictness of Stream Deck path checking --- src/stream-deck.ts | 54 ++++------------------------------------------ 1 file changed, 4 insertions(+), 50 deletions(-) diff --git a/src/stream-deck.ts b/src/stream-deck.ts index 2b02a1a..caf1fb8 100644 --- a/src/stream-deck.ts +++ b/src/stream-deck.ts @@ -1,8 +1,7 @@ import find from "find-process"; -import { Dirent, existsSync, readdirSync, readlinkSync } from "node:fs"; +import { Dirent, readdirSync, readlinkSync } from "node:fs"; import os from "node:os"; import { basename, join, resolve } from "node:path"; -import { Registry } from "rage-edit"; const PLUGIN_SUFFIX = ".sdPlugin"; @@ -55,60 +54,15 @@ export function isPluginInstalled(uuid: string): boolean { return getPlugins().some((pi) => pi.uuid === uuid); } -/** - * Gets the path to the Stream Deck application. - * @returns The path. - */ -export const getStreamDeckPath = ((): (() => Promise) => { - let appPath: string | undefined = undefined; - return async () => (appPath ??= await __getStreamDeckPath()); - - /** - * Gets the path to the Stream Deck application. - * @returns The path. - */ - async function __getStreamDeckPath(): Promise { - if (os.platform() === "darwin") { - return "/Applications/Elgato Stream Deck.app/Contents/MacOS/Stream Deck"; - } else { - // Before checking the registry, check if the default path exists. - const defaultWinPath = "C:\\Program Files\\Elgato\\StreamDeck\\StreamDeck.exe"; - if (existsSync(defaultWinPath)) { - return defaultWinPath; - } - - // Otherwise, attempt to get the installation directory from the registry. - const registryValue = await Registry.get( - "HKEY_CURRENT_USER\\Software\\Elgato Systems GmbH\\StreamDeck", - "InstallDir", - ); - - if (registryValue && typeof registryValue === "string") { - const winPath = join(registryValue, "StreamDeck.exe"); - if (existsSync(winPath)) { - return winPath; - } - } - - throw new Error("StreamDeck.exe could not be found"); - } - } -})(); - /** * Determines if the Stream Deck application is currently running. * @returns `true` when the application is running; otherwise `false`. */ export async function isStreamDeckRunning(): Promise { - const appPath = await getStreamDeckPath(); + const name = os.platform() === "darwin" ? "Elgato Stream Deck" : "StreamDeck.exe"; + const processes = await find("name", name); - if (os.platform() === "darwin") { - const processes = await find("name", "Elgato Stream Deck"); - return processes.some((p) => p.cmd.startsWith(appPath)); - } else { - const processes = await find("name", "StreamDeck.exe"); - return processes.some((p) => p.cmd.startsWith(`"${appPath}"`)); - } + return processes.length > 0; } /**