55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import sys
|
|
import os
|
|
import logging
|
|
from PySide6.QtWidgets import QApplication
|
|
from src.gui.main_window import MainWindow
|
|
from src.gui.style_manager import StyleManager
|
|
|
|
# Configure Logging
|
|
def setup_logging(app_dir):
|
|
log_path = os.path.join(app_dir, "citorrent.log")
|
|
logging.basicConfig(
|
|
level=logging.DEBUG,
|
|
format='%(asctime)s [%(levelname)s] %(name)s: %(message)s',
|
|
handlers=[
|
|
logging.FileHandler(log_path, encoding='utf-8'),
|
|
logging.StreamHandler(sys.stdout)
|
|
]
|
|
)
|
|
return logging.getLogger("Citorrent")
|
|
|
|
def get_app_dir():
|
|
if getattr(sys, 'frozen', False):
|
|
return os.path.dirname(sys.executable)
|
|
return os.path.dirname(os.path.abspath(__file__))
|
|
|
|
def main():
|
|
app_dir = get_app_dir()
|
|
logger = setup_logging(app_dir)
|
|
logger.info("Application starting...")
|
|
|
|
try:
|
|
app = QApplication(sys.argv)
|
|
|
|
# Portable mode: Determine app directory for DB and config
|
|
db_path = os.path.join(app_dir, "citorrent.db")
|
|
save_path = os.path.join(app_dir, "downloads")
|
|
os.makedirs(save_path, exist_ok=True)
|
|
logger.info(f"App directory: {app_dir}, DB path: {db_path}, Save path: {save_path}")
|
|
|
|
# Apply the dark theme stylesheet
|
|
StyleManager.apply_stylesheet(app, "style.qss")
|
|
|
|
window = MainWindow(db_path=db_path, save_path=save_path)
|
|
window.show()
|
|
|
|
sys.exit(app.exec())
|
|
except Exception as e:
|
|
logger.exception("Critical error during application execution")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
|