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")
|
||||
from gi.repository import Gtk, Adw
|
||||
|
||||
import threading
|
||||
from loguru import logger as log
|
||||
|
||||
class OBSActionBase(ActionBase):
|
||||
def __init__(self, action_id: str, action_name: str,
|
||||
deck_controller: "DeckController", page: Page, coords: str, plugin_base: PluginBase):
|
||||
|
@ -70,15 +73,24 @@ class OBSActionBase(ActionBase):
|
|||
self.reconnect_obs()
|
||||
|
||||
def reconnect_obs(self):
|
||||
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)
|
||||
threading.Thread(target=self._reconnect_obs, daemon=True, name="reconnect_obs").start()
|
||||
|
||||
def _reconnect_obs(self):
|
||||
try:
|
||||
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()
|
||||
|
||||
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():
|
||||
self.status_label.set_label(self.plugin_base.lm.get("actions.base.status.connected"))
|
||||
self.status_label.remove_css_class("red")
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import threading
|
||||
from plugins.com_core447_OBSPlugin.OBSActionBase import OBSActionBase
|
||||
from src.backend.DeckManagement.DeckController import DeckController
|
||||
from src.backend.PageManagement.Page import Page
|
||||
|
@ -14,15 +15,15 @@ class RecPlayPause(OBSActionBase):
|
|||
def on_ready(self):
|
||||
# Connect to obs if not connected
|
||||
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.reconnect_obs()
|
||||
|
||||
# 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):
|
||||
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"))
|
||||
return
|
||||
status = self.plugin_base.backend.get_record_status()
|
||||
|
|
|
@ -21,7 +21,7 @@ class SwitchScene(OBSActionBase):
|
|||
def on_ready(self):
|
||||
# Connect to obs if not connected
|
||||
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()
|
||||
|
||||
media_path = os.path.join(self.plugin_base.PATH, "assets", "transition_slide.png")
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# from ...OBSActionBase import OBSActionBase
|
||||
import threading
|
||||
from plugins.com_core447_OBSPlugin.OBSActionBase import OBSActionBase
|
||||
from src.backend.DeckManagement.DeckController import DeckController
|
||||
from src.backend.PageManagement.Page import Page
|
||||
|
@ -16,11 +17,11 @@ class ToggleRecord(OBSActionBase):
|
|||
self.current_state = -1
|
||||
# Connect to obs if not connected
|
||||
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()
|
||||
|
||||
# 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):
|
||||
if self.plugin_base.backend is None:
|
||||
|
|
Loading…
Reference in New Issue