Browse Source

Add general_error_prompt method and handle lightdm.start_session error

sisyphus
JezerM 3 years ago
parent
commit
4fe39eb8c6
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 14
      src/bridge/Greeter.py
  2. 37
      src/browser/error_prompt.py

14
src/bridge/Greeter.py

@ -38,13 +38,14 @@ from PyQt5.QtCore import QVariant, QTimer
# This Application # This Application
from logger import logger 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 browser.bridge import Bridge, BridgeObject
from config import web_greeter_config from config import web_greeter_config
from utils.battery import Battery from utils.battery import Battery
from bindings.screensaver import screensaver from bindings.screensaver import screensaver
from utils.brightness import BrightnessController from utils.brightness import BrightnessController
import globales
from . import ( from . import (
language_to_dict, language_to_dict,
@ -366,11 +367,22 @@ class Greeter(BridgeObject):
def start_session(self, session): def start_session(self, session):
if not session.strip(): if not session.strip():
return False return False
try:
started: bool = LightDMGreeter.start_session_sync(session) started: bool = LightDMGreeter.start_session_sync(session)
if started or self.is_authenticated: if started or self.is_authenticated:
logger.debug("Session \"%s\" started", session) logger.debug("Session \"%s\" started", session)
screensaver.reset_screensaver() screensaver.reset_screensaver()
return started 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) @Bridge.method(result=bool)
def suspend(self): def suspend(self):

37
src/browser/error_prompt.py

@ -42,9 +42,9 @@ from PyQt5.QtWidgets import (
QDialog, QDialog,
QVBoxLayout, QVBoxLayout,
QLabel, QLabel,
QPushButton, QPushButton
QAction
) )
from PyQt5.QtGui import QWindow
from config import web_greeter_config from config import web_greeter_config
import globales import globales
@ -144,19 +144,15 @@ class Dialog(QDialog):
# pylint: disable=missing-function-docstring # pylint: disable=missing-function-docstring
self.done(button.role) self.done(button.role)
def error_prompt(err): def general_error_prompt(window: QWindow, message: str, detail: str, title: str):
"""Prompts a popup dialog on error""" """General error prompt"""
if not web_greeter_config["config"]["greeter"]["detect_theme_errors"]: dialog = Dialog(parent = window,
return title = title,
message = message,
dia = Dialog(parent=globales.greeter.window, title="Error", detail = detail,
message="An error ocurred. Do you want to change to default theme?", buttons = ["Reload theme", "Use default theme", "Cancel"])
detail=err, dialog.exec()
buttons=["Reload theme", "Set default theme", "Cancel"], result = dialog.result()
)
dia.exec()
result = dia.result()
if result == 2: # Cancel if result == 2: # Cancel
pass pass
@ -165,3 +161,14 @@ def error_prompt(err):
globales.greeter.load_theme() globales.greeter.load_theme()
elif result == 0: # Reload elif result == 0: # Reload
globales.greeter.load_theme() 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")

Loading…
Cancel
Save