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
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
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):

37
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")

Loading…
Cancel
Save