Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (46 loc) · 1.72 KB
/
Copy pathmain.py
File metadata and controls
60 lines (46 loc) · 1.72 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
"""
Desktop Floating Widget - Main Entry Point.
Monitors connected Bluetooth device battery levels and ChatGPT/Codex usage quotas.
"""
import sys
import os
import traceback
# Ensure current directory is in sys.path
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
if BASE_DIR not in sys.path:
sys.path.insert(0, BASE_DIR)
# Setup error logging
def excepthook(exc_type, exc_value, exc_tb):
err_text = "".join(traceback.format_exception(exc_type, exc_value, exc_tb))
print("Unhandled exception:\n", err_text)
try:
with open(os.path.join(BASE_DIR, "error.log"), "a", encoding="utf-8") as f:
f.write(f"\n--- Error: ---\n{err_text}\n")
except Exception:
pass
sys.__excepthook__(exc_type, exc_value, exc_tb)
sys.excepthook = excepthook
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from core.config_manager import ConfigManager
from ui.floating_widget import FloatingWidget
from ui.tray_manager import TrayManager
def main():
# Enable High DPI support
if hasattr(Qt, 'AA_EnableHighDpiScaling'):
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
if hasattr(Qt, 'AA_UseHighDpiPixmaps'):
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False) # Keep running in system tray
app.setApplicationName("DesktopBatteryCodexWidget")
app.setApplicationDisplayName("桌面悬浮插件 (蓝牙电量 & ChatGPT限额)")
config_mgr = ConfigManager(BASE_DIR)
widget = FloatingWidget(config_mgr)
tray = TrayManager(widget)
widget.show()
widget.raise_()
widget.activateWindow()
sys.exit(app.exec_())
if __name__ == "__main__":
main()