Initial Version
This commit is contained in:
commit
bdf4330738
5 changed files with 383 additions and 0 deletions
67
obs_hudfx.py
Normal file
67
obs_hudfx.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import obspython as obs
|
||||
import subprocess
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
OVERLAY_SCRIPT = "/home/bashy/projects/HudFX_LNX/hudfx.py"
|
||||
PYTHON_BIN = "/usr/bin/python3"
|
||||
FLATPAK_SPAWN = "/usr/bin/flatpak-spawn"
|
||||
LOG_FILE = "/home/bashy/projects/HudFX_LNX/hudfx.log"
|
||||
|
||||
process = None
|
||||
|
||||
|
||||
def ts():
|
||||
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
def is_flatpak():
|
||||
return bool(os.environ.get("FLATPAK_ID")) or os.path.exists("/run/host/etc")
|
||||
|
||||
|
||||
def build_cmd():
|
||||
if is_flatpak():
|
||||
return [FLATPAK_SPAWN, "--host", PYTHON_BIN, OVERLAY_SCRIPT]
|
||||
return [PYTHON_BIN, OVERLAY_SCRIPT]
|
||||
|
||||
|
||||
def script_description():
|
||||
return "Starts HudFX overlay when OBS loads and stops it when OBS closes."
|
||||
|
||||
|
||||
def script_load(settings):
|
||||
obs.obs_frontend_add_event_callback(on_event)
|
||||
mode = "Flatpak" if is_flatpak() else "native"
|
||||
print(f"[HudFX] {ts()} Script loaded (OBS mode: {mode})")
|
||||
|
||||
|
||||
def on_event(event):
|
||||
if event == obs.OBS_FRONTEND_EVENT_FINISHED_LOADING:
|
||||
_start()
|
||||
elif event == obs.OBS_FRONTEND_EVENT_EXIT:
|
||||
_stop()
|
||||
|
||||
|
||||
def script_unload():
|
||||
_stop()
|
||||
|
||||
|
||||
def _start():
|
||||
global process
|
||||
if process is None or process.poll() is not None:
|
||||
try:
|
||||
log = open(LOG_FILE, "a")
|
||||
cmd = build_cmd()
|
||||
process = subprocess.Popen(cmd, env=os.environ.copy(), stdout=log, stderr=log)
|
||||
print(f"[HudFX] {ts()} Overlay started (pid {process.pid})")
|
||||
print(f"[HudFX] {ts()} Log: {LOG_FILE}")
|
||||
except Exception as e:
|
||||
print(f"[HudFX] {ts()} Failed to start overlay: {e}")
|
||||
|
||||
|
||||
def _stop():
|
||||
global process
|
||||
if process and process.poll() is None:
|
||||
process.terminate()
|
||||
print(f"[HudFX] {ts()} Overlay stopped")
|
||||
process = None
|
||||
Loading…
Add table
Add a link
Reference in a new issue