Fix: App freeze if ip is invalid
This commit is contained in:
parent
e8ad80016b
commit
f8b9a392dd
|
@ -10,6 +10,9 @@ gi.require_version("Gtk", "4.0")
|
||||||
gi.require_version("Adw", "1")
|
gi.require_version("Adw", "1")
|
||||||
from gi.repository import Gtk, Adw
|
from gi.repository import Gtk, Adw
|
||||||
|
|
||||||
|
import threading
|
||||||
|
from loguru import logger as log
|
||||||
|
|
||||||
class OBSActionBase(ActionBase):
|
class OBSActionBase(ActionBase):
|
||||||
def __init__(self, action_id: str, action_name: str,
|
def __init__(self, action_id: str, action_name: str,
|
||||||
deck_controller: "DeckController", page: Page, coords: str, plugin_base: PluginBase):
|
deck_controller: "DeckController", page: Page, coords: str, plugin_base: PluginBase):
|
||||||
|
@ -70,15 +73,24 @@ class OBSActionBase(ActionBase):
|
||||||
self.reconnect_obs()
|
self.reconnect_obs()
|
||||||
|
|
||||||
def reconnect_obs(self):
|
def reconnect_obs(self):
|
||||||
self.plugin_base.backend.connect_to(
|
threading.Thread(target=self._reconnect_obs, daemon=True, name="reconnect_obs").start()
|
||||||
host=self.plugin_base.get_settings().get("ip"),
|
|
||||||
port=self.plugin_base.get_settings().get("port"),
|
def _reconnect_obs(self):
|
||||||
password=self.plugin_base.get_settings().get("password"),
|
try:
|
||||||
timeout=3, legacy=False)
|
self.plugin_base.backend.connect_to(
|
||||||
|
host=self.plugin_base.get_settings().get("ip"),
|
||||||
|
port=self.plugin_base.get_settings().get("port"),
|
||||||
|
password=self.plugin_base.get_settings().get("password"),
|
||||||
|
timeout=3, legacy=False)
|
||||||
|
except Exception as e:
|
||||||
|
log.error(e)
|
||||||
|
|
||||||
self.update_status_label()
|
self.update_status_label()
|
||||||
|
|
||||||
def update_status_label(self) -> None:
|
def update_status_label(self) -> None:
|
||||||
|
threading.Thread(target=self._update_status_label, daemon=True, name="update_status_label").start()
|
||||||
|
|
||||||
|
def _update_status_label(self):
|
||||||
if self.plugin_base.backend.get_connected():
|
if self.plugin_base.backend.get_connected():
|
||||||
self.status_label.set_label(self.plugin_base.lm.get("actions.base.status.connected"))
|
self.status_label.set_label(self.plugin_base.lm.get("actions.base.status.connected"))
|
||||||
self.status_label.remove_css_class("red")
|
self.status_label.remove_css_class("red")
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import threading
|
||||||
from plugins.com_core447_OBSPlugin.OBSActionBase import OBSActionBase
|
from plugins.com_core447_OBSPlugin.OBSActionBase import OBSActionBase
|
||||||
from src.backend.DeckManagement.DeckController import DeckController
|
from src.backend.DeckManagement.DeckController import DeckController
|
||||||
from src.backend.PageManagement.Page import Page
|
from src.backend.PageManagement.Page import Page
|
||||||
|
@ -14,15 +15,15 @@ class RecPlayPause(OBSActionBase):
|
||||||
def on_ready(self):
|
def on_ready(self):
|
||||||
# Connect to obs if not connected
|
# Connect to obs if not connected
|
||||||
if self.plugin_base.backend is not None:
|
if self.plugin_base.backend is not None:
|
||||||
if not self.plugin_base.backend.get_connected():
|
if not self.plugin_base.get_connected():
|
||||||
# self.plugin_base.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False)
|
# self.plugin_base.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False)
|
||||||
self.reconnect_obs()
|
self.reconnect_obs()
|
||||||
|
|
||||||
# Show current rec status
|
# Show current rec status
|
||||||
self.show_current_rec_status()
|
threading.Thread(target=self.show_current_rec_status, daemon=True, name="show_current_rec_status").start()
|
||||||
|
|
||||||
def show_current_rec_status(self, new_paused = False):
|
def show_current_rec_status(self, new_paused = False):
|
||||||
if not self.plugin_base.backend.get_connected():
|
if not self.plugin_base.get_connected():
|
||||||
self.set_media(media_path=os.path.join(self.plugin_base.PATH, "assets", "error.png"))
|
self.set_media(media_path=os.path.join(self.plugin_base.PATH, "assets", "error.png"))
|
||||||
return
|
return
|
||||||
status = self.plugin_base.backend.get_record_status()
|
status = self.plugin_base.backend.get_record_status()
|
||||||
|
|
|
@ -21,7 +21,7 @@ class SwitchScene(OBSActionBase):
|
||||||
def on_ready(self):
|
def on_ready(self):
|
||||||
# Connect to obs if not connected
|
# Connect to obs if not connected
|
||||||
if self.plugin_base.backend is not None:
|
if self.plugin_base.backend is not None:
|
||||||
if not self.plugin_base.backend.get_connected(): # self.plugin_base.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False)
|
if not self.plugin_base.get_connected(): # self.plugin_base.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False)
|
||||||
self.reconnect_obs()
|
self.reconnect_obs()
|
||||||
|
|
||||||
media_path = os.path.join(self.plugin_base.PATH, "assets", "transition_slide.png")
|
media_path = os.path.join(self.plugin_base.PATH, "assets", "transition_slide.png")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# from ...OBSActionBase import OBSActionBase
|
# from ...OBSActionBase import OBSActionBase
|
||||||
|
import threading
|
||||||
from plugins.com_core447_OBSPlugin.OBSActionBase import OBSActionBase
|
from plugins.com_core447_OBSPlugin.OBSActionBase import OBSActionBase
|
||||||
from src.backend.DeckManagement.DeckController import DeckController
|
from src.backend.DeckManagement.DeckController import DeckController
|
||||||
from src.backend.PageManagement.Page import Page
|
from src.backend.PageManagement.Page import Page
|
||||||
|
@ -16,11 +17,11 @@ class ToggleRecord(OBSActionBase):
|
||||||
self.current_state = -1
|
self.current_state = -1
|
||||||
# Connect to obs if not connected
|
# Connect to obs if not connected
|
||||||
if self.plugin_base.backend is not None:
|
if self.plugin_base.backend is not None:
|
||||||
if not self.plugin_base.backend.get_connected(): # self.plugin_base.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False)
|
if not self.plugin_base.get_connected(): # self.plugin_base.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False)
|
||||||
self.reconnect_obs()
|
self.reconnect_obs()
|
||||||
|
|
||||||
# Show current rec status
|
# Show current rec status
|
||||||
self.show_current_rec_status()
|
threading.Thread(target=self.show_current_rec_status, daemon=True, name="show_current_rec_status").start()
|
||||||
|
|
||||||
def show_current_rec_status(self, new_paused = False):
|
def show_current_rec_status(self, new_paused = False):
|
||||||
if self.plugin_base.backend is None:
|
if self.plugin_base.backend is None:
|
||||||
|
|
7
main.py
7
main.py
|
@ -69,3 +69,10 @@ class OBS(PluginBase):
|
||||||
|
|
||||||
# Load custom css
|
# Load custom css
|
||||||
self.add_css_stylesheet(os.path.join(self.PATH, "style.css"))
|
self.add_css_stylesheet(os.path.join(self.PATH, "style.css"))
|
||||||
|
|
||||||
|
def get_connected(self):
|
||||||
|
try:
|
||||||
|
return self.backend.get_connected()
|
||||||
|
except Exception as e:
|
||||||
|
log.error(e)
|
||||||
|
return False
|
Loading…
Reference in New Issue