mirror of
https://github.com/onyx-and-iris/duckypad-twitch.git
synced 2024-11-15 22:40:50 +00:00
sl_fullpath implemented as cached_property
This commit is contained in:
parent
10eea42cf7
commit
768720e797
@ -21,7 +21,13 @@ class DuckyPad:
|
|||||||
self.audio = Audio(self, vm=self.vm, mixer=self.mixer)
|
self.audio = Audio(self, vm=self.vm, mixer=self.mixer)
|
||||||
self.scene = Scene(self, vm=self.vm)
|
self.scene = Scene(self, vm=self.vm)
|
||||||
self.obsws = OBSWS(self)
|
self.obsws = OBSWS(self)
|
||||||
self.streamlabs_controller = StreamlabsController(self, conn=self.sl)
|
self.streamlabs_controller = StreamlabsController(self)
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_value, exc_type, traceback):
|
||||||
|
self.streamlabs_controller.conn.disconnect()
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
'''
|
'''
|
||||||
|
@ -3,9 +3,11 @@ import subprocess as sp
|
|||||||
import time
|
import time
|
||||||
import winreg
|
import winreg
|
||||||
from asyncio.subprocess import DEVNULL
|
from asyncio.subprocess import DEVNULL
|
||||||
|
from functools import cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import slobs_websocket
|
import slobs_websocket
|
||||||
|
from slobs_websocket import StreamlabsOBS
|
||||||
|
|
||||||
from . import configuration
|
from . import configuration
|
||||||
from .util import ensure_sl
|
from .util import ensure_sl
|
||||||
@ -14,14 +16,13 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class StreamlabsController:
|
class StreamlabsController:
|
||||||
SL_FULLPATH = ""
|
|
||||||
|
|
||||||
def __init__(self, duckypad, **kwargs):
|
def __init__(self, duckypad, **kwargs):
|
||||||
self.logger = logger.getChild(__class__.__name__)
|
self.logger = logger.getChild(__class__.__name__)
|
||||||
self._duckypad = duckypad
|
self._duckypad = duckypad
|
||||||
for attr, val in kwargs.items():
|
for attr, val in kwargs.items():
|
||||||
setattr(self, attr, val)
|
setattr(self, attr, val)
|
||||||
|
|
||||||
|
self.conn = StreamlabsOBS()
|
||||||
self.proc = None
|
self.proc = None
|
||||||
|
|
||||||
####################################################################################
|
####################################################################################
|
||||||
@ -98,24 +99,24 @@ class StreamlabsController:
|
|||||||
# LAUNCH/SHUTDOWN the streamlabs process
|
# LAUNCH/SHUTDOWN the streamlabs process
|
||||||
####################################################################################
|
####################################################################################
|
||||||
|
|
||||||
def launch(self, delay=5):
|
@cached_property
|
||||||
def get_slpath():
|
def sl_fullpath(self) -> Path:
|
||||||
|
try:
|
||||||
|
self.logger.debug("fetching sl_fullpath from the registry")
|
||||||
SL_KEY = "029c4619-0385-5543-9426-46f9987161d9"
|
SL_KEY = "029c4619-0385-5543-9426-46f9987161d9"
|
||||||
|
|
||||||
with winreg.OpenKey(
|
with winreg.OpenKey(
|
||||||
winreg.HKEY_LOCAL_MACHINE, r"{}".format("SOFTWARE" + "\\" + SL_KEY)
|
winreg.HKEY_LOCAL_MACHINE, r"{}".format("SOFTWARE" + "\\" + SL_KEY)
|
||||||
) as regpath:
|
) as regpath:
|
||||||
return winreg.QueryValueEx(regpath, r"InstallLocation")[0]
|
slpath = winreg.QueryValueEx(regpath, r"InstallLocation")[0]
|
||||||
|
return Path(slpath) / "Streamlabs OBS.exe"
|
||||||
try:
|
|
||||||
if not self.SL_FULLPATH: # so we only read from registry once.
|
|
||||||
self.SL_FULLPATH = Path(get_slpath()) / "Streamlabs OBS.exe"
|
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
self.logger.exception(f"{type(e).__name__}: {e}")
|
self.logger.exception(f"{type(e).__name__}: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def launch(self, delay=5):
|
||||||
if self.proc is None:
|
if self.proc is None:
|
||||||
self.proc = sp.Popen(self.SL_FULLPATH, shell=False, stdout=DEVNULL)
|
self.proc = sp.Popen(str(self.sl_fullpath), shell=False, stdout=DEVNULL)
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user