diff --git a/src/bridge/Greeter.py b/src/bridge/Greeter.py index 503cf7f..3719a6d 100644 --- a/src/bridge/Greeter.py +++ b/src/bridge/Greeter.py @@ -38,13 +38,14 @@ from PyQt5.QtCore import QVariant, QTimer # This Application from logger import logger -from browser.error_prompt import Dialog +from browser.error_prompt import Dialog, general_error_prompt from browser.bridge import Bridge, BridgeObject from config import web_greeter_config from utils.battery import Battery from bindings.screensaver import screensaver from utils.brightness import BrightnessController +import globales from . import ( language_to_dict, @@ -366,11 +367,22 @@ class Greeter(BridgeObject): def start_session(self, session): if not session.strip(): return False - started: bool = LightDMGreeter.start_session_sync(session) - if started or self.is_authenticated: - logger.debug("Session \"%s\" started", session) - screensaver.reset_screensaver() - return started + try: + started: bool = LightDMGreeter.start_session_sync(session) + if started or self.is_authenticated: + logger.debug("Session \"%s\" started", session) + screensaver.reset_screensaver() + return started + except GError as err: + logger.error(err) + general_error_prompt( + globales.greeter.window, + "LightDM couldn't start session", + f"The provided session: \"{session}\" couldn't be started\n" \ + f"{err}", + "An error ocurred" + ) + return False @Bridge.method(result=bool) def suspend(self): diff --git a/src/browser/error_prompt.py b/src/browser/error_prompt.py index 24f6eb6..77561c4 100644 --- a/src/browser/error_prompt.py +++ b/src/browser/error_prompt.py @@ -42,9 +42,9 @@ from PyQt5.QtWidgets import ( QDialog, QVBoxLayout, QLabel, - QPushButton, - QAction + QPushButton ) +from PyQt5.QtGui import QWindow from config import web_greeter_config import globales @@ -144,19 +144,15 @@ class Dialog(QDialog): # pylint: disable=missing-function-docstring self.done(button.role) -def error_prompt(err): - """Prompts a popup dialog on error""" - if not web_greeter_config["config"]["greeter"]["detect_theme_errors"]: - return - - dia = Dialog(parent=globales.greeter.window, title="Error", - message="An error ocurred. Do you want to change to default theme?", - detail=err, - buttons=["Reload theme", "Set default theme", "Cancel"], - ) - - dia.exec() - result = dia.result() +def general_error_prompt(window: QWindow, message: str, detail: str, title: str): + """General error prompt""" + dialog = Dialog(parent = window, + title = title, + message = message, + detail = detail, + buttons = ["Reload theme", "Use default theme", "Cancel"]) + dialog.exec() + result = dialog.result() if result == 2: # Cancel pass @@ -165,3 +161,14 @@ def error_prompt(err): globales.greeter.load_theme() elif result == 0: # Reload globales.greeter.load_theme() + + +def error_prompt(err: str): + """Prompts a popup dialog on error""" + if not web_greeter_config["config"]["greeter"]["detect_theme_errors"]: + return + + general_error_prompt(globales.greeter.window, + "An error ocurred. Do you want to change to default theme?", + f"{err}", + "An error ocurred")