- Introduced a new i18n module for managing translations using JSON files. - Added English (en.json) and French (fr.json) translation files for UI elements. - Implemented lazy initialization of the translator to load translations on demand. - Added unit tests for translation lookup, fallback behavior, and available languages detection.
89 lines
2.8 KiB
Python
89 lines
2.8 KiB
Python
"""WebDrop Bridge - Application entry point."""
|
|
|
|
import os
|
|
import sys
|
|
|
|
# Force Chromium to treat hover as primary input method and disable touch detection
|
|
# This ensures CSS media queries (hover: hover) evaluate correctly for desktop applications
|
|
os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--touch-events=disabled"
|
|
|
|
# Enable Qt WebEngine Remote Debugging Protocol (Chromium Developer Tools)
|
|
# Allows debugging via browser DevTools at http://localhost:9222 or edge://inspect
|
|
os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = "9222"
|
|
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
from webdrop_bridge.config import Config, ConfigurationError
|
|
from webdrop_bridge.ui.main_window import MainWindow
|
|
from webdrop_bridge.utils.i18n import get_translations_dir
|
|
from webdrop_bridge.utils.i18n import initialize as i18n_init
|
|
from webdrop_bridge.utils.logging import get_logger, setup_logging
|
|
|
|
|
|
def main() -> int:
|
|
"""Main application entry point.
|
|
|
|
Initializes configuration, logging, and creates the main window.
|
|
Returns appropriate exit code.
|
|
|
|
Returns:
|
|
int: Exit code (0 for success, non-zero for error)
|
|
"""
|
|
try:
|
|
# Load configuration from file if it exists, otherwise from environment
|
|
config_path = Config.get_default_config_path()
|
|
if config_path.exists():
|
|
config = Config.from_file(config_path)
|
|
else:
|
|
config = Config.from_env()
|
|
|
|
# Set up logging
|
|
log_file = None
|
|
if config.log_file:
|
|
log_file = config.log_file
|
|
|
|
setup_logging(
|
|
name="webdrop_bridge",
|
|
level=config.log_level,
|
|
log_file=log_file,
|
|
)
|
|
|
|
logger = get_logger(__name__)
|
|
logger.info(f"Starting {config.app_name} v{config.app_version}")
|
|
logger.debug(f"Configuration: {config}")
|
|
|
|
# Initialize internationalization
|
|
translations_dir = get_translations_dir()
|
|
i18n_init(config.language, translations_dir)
|
|
logger.debug(f"i18n initialized: language={config.language}, dir={translations_dir}")
|
|
|
|
except ConfigurationError as e:
|
|
print(f"Configuration error: {e}", file=sys.stderr)
|
|
return 1
|
|
except Exception as e:
|
|
print(f"Failed to initialize logging: {e}", file=sys.stderr)
|
|
return 1
|
|
|
|
try:
|
|
# Create Qt application
|
|
app = QApplication(sys.argv)
|
|
|
|
# Create and show main window
|
|
window = MainWindow(config)
|
|
window.show()
|
|
|
|
logger.info("Main window opened successfully")
|
|
|
|
# Check for updates on startup (non-blocking, async)
|
|
window.check_for_updates_startup()
|
|
|
|
# Run event loop
|
|
return app.exec()
|
|
|
|
except Exception as e:
|
|
logger.exception(f"Unhandled exception: {e}")
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|