From 27d732af810f41a14a43ce1ea339ac882fa63922 Mon Sep 17 00:00:00 2001 From: Vicwomg Date: Tue, 5 Nov 2024 00:48:40 -0800 Subject: [PATCH] fix: broken upgrade path for --break-system-packages users (#395) --- pikaraoke/app.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/pikaraoke/app.py b/pikaraoke/app.py index 96bcf17..d20e36b 100644 --- a/pikaraoke/app.py +++ b/pikaraoke/app.py @@ -26,6 +26,7 @@ from flask_babel import Babel from flask_paginate import Pagination, get_page_parameter from selenium import webdriver +from selenium.common.exceptions import SessionNotCreatedException from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By @@ -939,13 +940,21 @@ def main(): options.add_argument("--kiosk") options.add_argument("--start-maximized") options.add_experimental_option("excludeSwitches", ["enable-automation"]) - driver = webdriver.Chrome(service=service, options=options) - driver.get(f"{k.url}/splash") - driver.add_cookie({"name": "user", "value": "PiKaraoke-Host"}) - # Clicking this counts as an interaction, which will allow the browser to autoplay audio - wait = WebDriverWait(driver, 60) - elem = wait.until(EC.element_to_be_clickable((By.ID, "permissions-button"))) - elem.click() + try: + driver = webdriver.Chrome(service=service, options=options) + driver.get(f"{k.url}/splash") + driver.add_cookie({"name": "user", "value": "PiKaraoke-Host"}) + # Clicking this counts as an interaction, which will allow the browser to autoplay audio + wait = WebDriverWait(driver, 60) + elem = wait.until(EC.element_to_be_clickable((By.ID, "permissions-button"))) + elem.click() + except SessionNotCreatedException as e: + print(str(e)) + print( + f"\n[ERROR] Error starting splash screen. If you're running headed mode over SSH, you may need to run `export DISPLAY=:0.0` first to target the host machine's screen. Example: `export DISPLAY=:0.0; pikaraoke`\n" + ) + cherrypy.engine.exit() + sys.exit() # Start the karaoke process k.run()