Refactor imports and add logging to main.py
Updated import paths to use src.gui and src.core modules. Integrated logger for improved error and status reporting throughout application startup and error handling.
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
from PySide6.QtWidgets import QApplication, QMessageBox
|
from PySide6.QtWidgets import QApplication, QMessageBox
|
||||||
from ytsage_gui_main import YTSageApp # Import the main application class from ytsage_gui_main
|
from src.gui.ytsage_gui_main import YTSageApp # Import the main application class from ytsage_gui_main
|
||||||
from ytsage_yt_dlp import check_ytdlp_binary, setup_ytdlp, get_ytdlp_executable_path # Import the new yt-dlp setup functions
|
from src.core.ytsage_yt_dlp import check_ytdlp_binary, setup_ytdlp, get_ytdlp_executable_path # Import the new yt-dlp setup functions
|
||||||
|
from src.core.ytsage_logging import logger
|
||||||
|
|
||||||
def show_error_dialog(message):
|
def show_error_dialog(message):
|
||||||
error_dialog = QMessageBox()
|
error_dialog = QMessageBox()
|
||||||
@@ -13,20 +14,24 @@ def show_error_dialog(message):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
|
logger.info("Starting YTSage application")
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
# Get the expected binary path and check if it exists
|
# Get the expected binary path and check if it exists
|
||||||
expected_path = get_ytdlp_executable_path()
|
expected_path = get_ytdlp_executable_path()
|
||||||
if not check_ytdlp_binary():
|
if not check_ytdlp_binary():
|
||||||
# No app-specific binary found, show setup dialog regardless of Python package
|
# No app-specific binary found, show setup dialog regardless of Python package
|
||||||
|
logger.warning("No yt-dlp binary found, starting setup process")
|
||||||
yt_dlp_path = setup_ytdlp()
|
yt_dlp_path = setup_ytdlp()
|
||||||
if yt_dlp_path == "yt-dlp": # If user canceled or something went wrong
|
if yt_dlp_path == "yt-dlp": # If user canceled or something went wrong
|
||||||
print(f"Warning: yt-dlp not configured properly")
|
logger.warning("yt-dlp not configured properly")
|
||||||
|
|
||||||
window = YTSageApp() # Instantiate the main application class
|
window = YTSageApp() # Instantiate the main application class
|
||||||
window.show()
|
window.show()
|
||||||
|
logger.info("Application window shown, entering main loop")
|
||||||
sys.exit(app.exec())
|
sys.exit(app.exec())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.critical(f"Critical application error: {str(e)}", exc_info=True)
|
||||||
show_error_dialog(f"Critical error: {str(e)}")
|
show_error_dialog(f"Critical error: {str(e)}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user