Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
修复托盘图标
Browse files Browse the repository at this point in the history
  • Loading branch information
BryceWG committed Sep 4, 2024
1 parent bd96f4f commit 12d5769
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Binary file added maa.ico
Binary file not shown.
31 changes: 26 additions & 5 deletions maaupdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def __init__(self):
application_path = os.path.dirname(os.path.abspath(__file__))

icon_path = os.path.join(application_path, 'maa.png')
print(f"Icon path: {icon_path}")
print(f"Icon file exists: {os.path.exists(icon_path)}")

self.setWindowIcon(QIcon(icon_path))

self.init_ui()
Expand Down Expand Up @@ -266,8 +269,17 @@ def update_finished(self, success, message):
self.start_button.setEnabled(True)

def setup_tray(self):
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
else:
base_path = os.path.dirname(os.path.abspath(__file__))

icon_path = os.path.join(base_path, 'maa.png')
print(f"Tray icon path: {icon_path}")
print(f"Tray icon file exists: {os.path.exists(icon_path)}")

self.tray_icon = QSystemTrayIcon(self)
self.tray_icon.setIcon(QIcon('maa.png'))
self.tray_icon.setIcon(QIcon(icon_path))

tray_menu = QMenu()
show_action = QAction("显示UI", self)
Expand Down Expand Up @@ -297,7 +309,16 @@ def quit_app(self):
QApplication.quit()

if __name__ == "__main__":
app = QApplication(sys.argv)
window = UpdateApp()
window.show()
sys.exit(app.exec())
try:
app = QApplication(sys.argv)
if not QSystemTrayIcon.isSystemTrayAvailable():
QMessageBox.critical(None, "系统托盘", "无法检测到系统托盘。")
sys.exit(1)

QApplication.setQuitOnLastWindowClosed(False)
window = UpdateApp()
window.show()
sys.exit(app.exec())
except Exception as e:
print(f"An error occurred: {e}")
input("Press Enter to exit...")
Binary file added out/maaupdater.exe
Binary file not shown.
3 changes: 3 additions & 0 deletions out/update_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Settings]
maa_directory = D:/Číźţ/MAA-v5.5.11452-win-x64

0 comments on commit 12d5769

Please sign in to comment.