46 lines
1.3 KiB
JavaScript

import streamDeck, { SingletonAction } from "@elgato/streamdeck";
import { spawn } from "node:child_process";
import { existsSync, readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const pluginDir = dirname(dirname(fileURLToPath(import.meta.url)));
const launcherConfig = join(pluginDir, "launcher.json");
const fallbackLauncher = "F:\\AI\\TopSecretProjects\\ffmpeg-projects\\rimpac_gif_creator\\rimpac_gif_creator.vbs";
function getAppLauncher() {
if (!existsSync(launcherConfig)) {
return fallbackLauncher;
}
try {
const config = JSON.parse(readFileSync(launcherConfig, "utf8"));
return config.appLauncher || fallbackLauncher;
} catch {
return fallbackLauncher;
}
}
class LaunchGifCreatorAction extends SingletonAction {
manifestId = "com.rimpac.gif-creator.launch";
async onKeyDown(ev) {
const appLauncher = getAppLauncher();
if (!existsSync(appLauncher)) {
streamDeck.logger.error(`Launcher not found: ${appLauncher}`);
await ev.action.showAlert();
return;
}
const child = spawn("wscript.exe", [appLauncher], {
detached: true,
stdio: "ignore",
windowsHide: true,
});
child.unref();
await ev.action.showOk();
}
}
streamDeck.actions.registerAction(new LaunchGifCreatorAction());
streamDeck.connect();