PyInstaller bundles data files into sys._MEIPASS, not the executable directory. - Add get_resource_path() helper in main.py and main_window.py - Use _MEIPASS for bundled resources (icon, web files) - Keep app_dir pointing to executable directory for user data (macros.json) This fixes the missing icon in taskbar and system tray on Windows builds. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
# Main application file for MacroPad Server
|
|
# PySide6 version
|
|
|
|
import os
|
|
import sys
|
|
import multiprocessing
|
|
|
|
|
|
def get_app_dir():
|
|
"""Get the application directory (where macros.json and macro_images are stored)."""
|
|
if getattr(sys, 'frozen', False):
|
|
# Running as compiled executable - use executable's directory for user data
|
|
return os.path.dirname(sys.executable)
|
|
else:
|
|
# Running as script
|
|
return os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
def get_resource_path(relative_path):
|
|
"""Get the path to a bundled resource file."""
|
|
if getattr(sys, 'frozen', False):
|
|
# Running as compiled executable - resources are in _MEIPASS
|
|
base_path = sys._MEIPASS
|
|
else:
|
|
# Running as script - resources are in the script directory
|
|
base_path = os.path.dirname(os.path.abspath(__file__))
|
|
return os.path.join(base_path, relative_path)
|
|
|
|
|
|
def main():
|
|
"""Main entry point."""
|
|
# Required for multiprocessing on Windows
|
|
multiprocessing.freeze_support()
|
|
|
|
# Get directories
|
|
app_dir = get_app_dir()
|
|
|
|
# Import PySide6 after freeze_support
|
|
from PySide6.QtWidgets import QApplication
|
|
from PySide6.QtCore import Qt
|
|
from PySide6.QtGui import QIcon
|
|
|
|
# Create application
|
|
app = QApplication(sys.argv)
|
|
app.setApplicationName("MacroPad Server")
|
|
app.setOrganizationName("MacroPad")
|
|
|
|
# Set application icon (from bundled resources)
|
|
icon_path = get_resource_path("Macro Pad.png")
|
|
if os.path.exists(icon_path):
|
|
app.setWindowIcon(QIcon(icon_path))
|
|
|
|
# Import and create main window
|
|
from gui.main_window import MainWindow
|
|
window = MainWindow(app_dir)
|
|
window.show()
|
|
|
|
# Run application
|
|
sys.exit(app.exec())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|