Merge branch 'overlay' into develop

This commit is contained in:
misyaguziya
2024-04-27 05:50:27 +09:00
3 changed files with 31 additions and 12 deletions

View File

@@ -161,7 +161,7 @@ def receiveSpeakerMessage(message):
xsoverlay_message = messageFormatter("RECEIVED", translation, message) xsoverlay_message = messageFormatter("RECEIVED", translation, message)
model.notificationXSOverlay(xsoverlay_message) model.notificationXSOverlay(xsoverlay_message)
if model.th_overlay is None: if model.overlay.initialized is False:
model.startOverlay() model.startOverlay()
if config.ENABLE_OVERLAY_SMALL_LOG is True: if config.ENABLE_OVERLAY_SMALL_LOG is True:

View File

@@ -608,17 +608,14 @@ class Model:
def startOverlay(self): def startOverlay(self):
if self.overlay.initialized is False: if self.overlay.initialized is False:
print("self.overlay.init()")
self.overlay.init() self.overlay.init()
if self.overlay.initialized is True: if self.overlay.initialized is True:
self.th_overlay = threadFnc(self.overlay.startOverlay) self.th_overlay = Thread(target=self.overlay.startOverlay)
self.th_overlay.daemon = True self.th_overlay.daemon = True
self.th_overlay.start() self.th_overlay.start()
def stopOverlay(self):
if isinstance(self.th_overlay, threadFnc):
self.th_overlay.stop()
self.th_overlay = None
def updateOverlayPosition(self): def updateOverlayPosition(self):
if self.overlay.initialized is True: if self.overlay.initialized is True:
pos = (config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"], config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"]) pos = (config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"], config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"])

View File

@@ -7,7 +7,7 @@ from PIL import Image
def checkSteamvrRunning(): def checkSteamvrRunning():
for proc in psutil.process_iter(): for proc in psutil.process_iter():
if "vrserver" in proc.name().lower() or "vrcompositor" in proc.name().lower(): if "vrserver.exe" == proc.name().lower():
return True return True
return False return False
@@ -156,17 +156,19 @@ class Overlay:
"Ui_scaling": ui_scaling, "Ui_scaling": ui_scaling,
} }
self.settings = settings self.settings = settings
self.system = None
def init(self): def init(self):
try: try:
if checkSteamvrRunning() is True: if checkSteamvrRunning() is True:
openvr.init(openvr.VRApplication_Overlay) self.system = openvr.init(openvr.VRApplication_Background)
self.initialized = True self.initialized = True
except Exception as e: except Exception as e:
print("Could not initialise OpenVR") print("Could not initialise OpenVR")
print(e)
async def mainLoop(self): async def mainLoop(self):
while True: while self.checkActive() is True:
startTime = time.monotonic() startTime = time.monotonic()
self.uiManager.update() self.uiManager.update()
@@ -175,12 +177,32 @@ class Overlay:
await asyncio.sleep(sleepTime) await asyncio.sleep(sleepTime)
async def initMain(self): async def initMain(self):
self.uiManager = UIManager("Overlay_Speaker2log", "SOverlay_Speaker2log_UI", self.settings) if self.initialized is True:
await self.mainLoop() self.uiManager = UIManager("Overlay_Speaker2log", "SOverlay_Speaker2log_UI", self.settings)
await self.mainLoop()
def startOverlay(self): def startOverlay(self):
asyncio.run(self.initMain()) asyncio.run(self.initMain())
def shutdown(self):
self.system = None
self.initialized = False
openvr.shutdown()
def checkActive(self):
try:
if self.system is not None and self.initialized is True:
new_event = openvr.VREvent_t()
while self.system.pollNextEvent(new_event):
if new_event.eventType == openvr.VREvent_Quit:
self.shutdown()
return False
return True
except Exception as e:
print("Could not check SteamVR running")
print(e)
return False
if __name__ == '__main__': if __name__ == '__main__':
from overlay_image import OverlayImage from overlay_image import OverlayImage
from threading import Thread, Event from threading import Thread, Event