11const { app, BrowserWindow, ipcMain, Menu, nativeImage, nativeTheme, shell, Tray } = require ( "electron" ) ;
2+ const fs = require ( "node:fs" ) ;
23const path = require ( "node:path" ) ;
34const http = require ( "node:http" ) ;
45const { execFile } = require ( "node:child_process" ) ;
@@ -14,9 +15,11 @@ const {
1415 writeSourceAllocation,
1516} = require ( "./source-allocation.cjs" ) ;
1617const { assignStableTaskSlots, readTaskSlotIds, writeTaskSlotIds } = require ( "./task-slots.cjs" ) ;
18+ const { installBundledStreamDeckPlugin } = require ( "./stream-deck-plugin-install.cjs" ) ;
1719
1820const execFileAsync = promisify ( execFile ) ;
1921const BRIDGE_HOST = "127.0.0.1" ;
22+ const STREAM_DECK_PLUGIN_BUNDLE = "com.roie.deck-threads.sdPlugin" ;
2023const requestedBridgePort = Number ( process . env . DECK_THREADS_BRIDGE_PORT ) ;
2124const BRIDGE_PORT = Number . isInteger ( requestedBridgePort ) && requestedBridgePort > 0 && requestedBridgePort <= 65535
2225 ? requestedBridgePort
@@ -59,6 +62,27 @@ function getResourcePath(filename) {
5962 : path . join ( __dirname , ".." , "build" , filename ) ;
6063}
6164
65+ async function ensureBundledStreamDeckPlugin ( ) {
66+ if ( process . platform !== "darwin" || ! app . isPackaged ) {
67+ return { status : "development" } ;
68+ }
69+
70+ const source = path . join ( process . resourcesPath , "stream-deck-plugin" , STREAM_DECK_PLUGIN_BUNDLE ) ;
71+ const pluginsRoot = process . env . DECK_THREADS_STREAM_DECK_PLUGINS_DIR
72+ || path . join ( app . getPath ( "home" ) , "Library" , "Application Support" , "com.elgato.StreamDeck" , "Plugins" ) ;
73+ const destination = path . join ( pluginsRoot , STREAM_DECK_PLUGIN_BUNDLE ) ;
74+ const result = await installBundledStreamDeckPlugin ( source , destination ) ;
75+
76+ if ( result . status === "installed"
77+ && process . env . DECK_THREADS_SKIP_STREAM_DECK_RESTART !== "1"
78+ && fs . existsSync ( "/Applications/Elgato Stream Deck.app" ) ) {
79+ await execFileAsync ( "/usr/bin/pkill" , [ "-x" , "Stream Deck" ] ) . catch ( ( ) => undefined ) ;
80+ await execFileAsync ( "/usr/bin/open" , [ "-a" , "/Applications/Elgato Stream Deck.app" ] ) . catch ( ( ) => undefined ) ;
81+ }
82+
83+ return result ;
84+ }
85+
6286function getLaunchAtLoginStatus ( ) {
6387 if ( process . platform !== "darwin" || ! app . isPackaged ) {
6488 return { openAtLogin : false , status : "development" } ;
@@ -481,6 +505,15 @@ app.whenReady().then(() => {
481505 const openedAtLogin = app . isPackaged && app . getLoginItemSettings ( ) . wasOpenedAtLogin ;
482506 if ( openedAtLogin ) app . dock ?. hide ( ) ;
483507 else showMainWindow ( ) ;
508+ ensureBundledStreamDeckPlugin ( )
509+ . then ( ( result ) => {
510+ if ( result . status === "installed" ) {
511+ emitEvent ( "system" , "success" , "Stream Deck plugin installed" , `Version ${ result . version || "current" } is ready.` ) ;
512+ }
513+ } )
514+ . catch ( ( error ) => {
515+ emitEvent ( "system" , "warning" , "Could not install the Stream Deck plugin" , error . message ) ;
516+ } ) ;
484517 if ( process . env . CODEX_BRIDGE_API_DISABLED !== "1" ) startBridgeServer ( ) ;
485518 app . on ( "activate" , showMainWindow ) ;
486519} ) ;
0 commit comments