forked from Support/sp-hydra-veil-gui
Improved State Management on Startup, to use core's new features
This commit is contained in:
parent
9a13ae1939
commit
8938643338
3 changed files with 23 additions and 7 deletions
|
|
@ -17,12 +17,12 @@ from PyQt6 import QtGui
|
||||||
from PyQt6.QtCore import Qt, QTimer, QEvent
|
from PyQt6.QtCore import Qt, QTimer, QEvent
|
||||||
|
|
||||||
from core.Constants import Constants
|
from core.Constants import Constants
|
||||||
from core.infrastructure.global_state_coordinator import evaluate_state_on_startup
|
|
||||||
from core.infrastructure.service_registry import ServiceLocator
|
from core.infrastructure.service_registry import ServiceLocator
|
||||||
from core.controllers.ConfigurationController import ConfigurationController
|
from core.controllers.ConfigurationController import ConfigurationController
|
||||||
from core.controllers.ProfileController import ProfileController
|
from core.controllers.ProfileController import ProfileController
|
||||||
from core.Errors import UnknownConnectionTypeError
|
from core.Errors import UnknownConnectionTypeError
|
||||||
from core.errors.logger import logger as core_logger
|
from core.errors.logger import logger as core_logger
|
||||||
|
from core.models.Result import Result, ResultError
|
||||||
|
|
||||||
core_logger.propagate = False
|
core_logger.propagate = False
|
||||||
|
|
||||||
|
|
@ -71,7 +71,6 @@ from gui.v2.actions.ticket_failure import (
|
||||||
)
|
)
|
||||||
from gui.v2.actions.should_be_synchronized import should_be_synchronized
|
from gui.v2.actions.should_be_synchronized import should_be_synchronized
|
||||||
|
|
||||||
|
|
||||||
class CustomWindow(QMainWindow):
|
class CustomWindow(QMainWindow):
|
||||||
def __init__(self, force_sync=False):
|
def __init__(self, force_sync=False):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
@ -910,10 +909,6 @@ class CustomWindow(QMainWindow):
|
||||||
|
|
||||||
|
|
||||||
def start_ui(force_sync):
|
def start_ui(force_sync):
|
||||||
worked = evaluate_state_on_startup()
|
|
||||||
if worked.valid:
|
|
||||||
core_logger.info("State evaluated.")
|
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
calculate_max_screensize(app)
|
calculate_max_screensize(app)
|
||||||
window = CustomWindow(force_sync=force_sync)
|
window = CustomWindow(force_sync=force_sync)
|
||||||
|
|
|
||||||
15
gui/v2/actions/error_handlers.py
Normal file
15
gui/v2/actions/error_handlers.py
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
from gui.v2.infrastructure.action_registry import register_action
|
||||||
|
from core.infrastructure.global_state_coordinator import coordinate_evaluation
|
||||||
|
from core.models.Result import Result, ResultError
|
||||||
|
|
||||||
|
from gui.v2.infrastructure.setup_observers import connection_observer
|
||||||
|
|
||||||
|
def empty_filler(result: Result) -> Result:
|
||||||
|
"""To have a callback, even when one is not required."""
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@register_action(ResultError.ZOMBIE_CONNECTION)
|
||||||
|
def evaluate_bad_state() -> Result:
|
||||||
|
"""Start core's evaluation of state with a GUI observer."""
|
||||||
|
return coordinate_evaluation(connection_observer=connection_observer)
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
from core.infrastructure.global_state_coordinator import connected_session_profile_ids, connected_system_profile_id, is_systemwide_on, is_connected
|
from core.infrastructure.global_state_coordinator import connected_session_profile_ids, connected_system_profile_id, is_systemwide_on, is_connected, evaluate_state_on_startup
|
||||||
|
from gui.v2.infrastructure.take_plumbing_action import take_action
|
||||||
|
from gui.v2.actions.error_handlers import empty_filler
|
||||||
from core.controllers.ProfileController import ProfileController
|
from core.controllers.ProfileController import ProfileController
|
||||||
from core.models.BaseProfile import ProfileType
|
from core.models.BaseProfile import ProfileType
|
||||||
from core.models.Result import Result, ResultError
|
from core.models.Result import Result, ResultError
|
||||||
|
|
@ -816,6 +818,10 @@ class MenuPage(Page):
|
||||||
Notifications.subscribe(EventType.SYSTEM_ENABLE, self.turn_on_system_visuals)
|
Notifications.subscribe(EventType.SYSTEM_ENABLE, self.turn_on_system_visuals)
|
||||||
Notifications.subscribe(EventType.SYSTEM_DISABLE, self.turn_off_system_visuals)
|
Notifications.subscribe(EventType.SYSTEM_DISABLE, self.turn_off_system_visuals)
|
||||||
|
|
||||||
|
take_action(
|
||||||
|
action=evaluate_state_on_startup,
|
||||||
|
ui_caller=empty_filler # do nothing on success.
|
||||||
|
)
|
||||||
|
|
||||||
def state_refresh(self):
|
def state_refresh(self):
|
||||||
"""Update the UI with the current Global State Repo"""
|
"""Update the UI with the current Global State Repo"""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue