-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (58 loc) · 2.23 KB
/
Copy pathmain.py
File metadata and controls
74 lines (58 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from __future__ import annotations
import sys
import traceback
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QApplication
from app.config import APP_NAME, ICON_PATH, ensure_runtime_dirs
from app.services.audio_service import AudioService
from app.services.autostart_service import AutostartService
from app.services.keyboard_hook_service import KeyboardHookService
from app.services.logger_service import get_logger, setup_logging
from app.services.media_control_service import MediaControlService
from app.services.raw_input_service import RawInputService
from app.services.settings_service import SettingsService
from app.services.update_service import UpdateService
from app.ui.main_window import MainWindow
def main() -> int:
ensure_runtime_dirs()
setup_logging()
logger = get_logger(__name__)
logger.info("Starting %s", APP_NAME)
def log_unhandled_exception(exc_type, exc_value, exc_traceback):
logger.critical(
"Unhandled exception:\n%s",
"".join(traceback.format_exception(exc_type, exc_value, exc_traceback)),
)
sys.excepthook = log_unhandled_exception
app = QApplication(sys.argv)
app.setApplicationName(APP_NAME)
app.setOrganizationName(APP_NAME)
app.setQuitOnLastWindowClosed(False)
if ICON_PATH.exists():
app.setWindowIcon(QIcon(str(ICON_PATH)))
settings = SettingsService()
audio_service = AudioService()
keyboard_service = KeyboardHookService()
raw_input_service = RawInputService()
media_control_service = MediaControlService()
autostart_service = AutostartService()
update_service = UpdateService()
window = MainWindow(
settings=settings,
audio_service=audio_service,
keyboard_service=keyboard_service,
raw_input_service=raw_input_service,
media_control_service=media_control_service,
autostart_service=autostart_service,
update_service=update_service,
)
if not settings.get_bool("launch_to_tray"):
window.show()
exit_code = app.exec()
keyboard_service.stop()
raw_input_service.stop()
audio_service.shutdown()
logger.info("Stopped %s", APP_NAME)
return exit_code
if __name__ == "__main__":
raise SystemExit(main())