From c17f4485342cb3a7a65c1262b93b5f47a2c77195 Mon Sep 17 00:00:00 2001 From: goodtimes-code Date: Sat, 2 Mar 2024 06:49:18 +0100 Subject: [PATCH] Added Mac installer script (creates a .pkg) --- README.md | 10 ++++---- osc-receiver/main.py | 10 ++++++++ osc-receiver/make_installer_mac.sh | 38 ++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100755 osc-receiver/make_installer_mac.sh diff --git a/README.md b/README.md index a426f6e..d58f673 100644 --- a/README.md +++ b/README.md @@ -115,11 +115,11 @@ See *config_laser1.txt* for more optional settings. - /effect/color_change/[r, g, b] - 0 to 255: color intensity of red, green and blue -# Run installer (create binary) -## For Mac & Linux -- `cd osc-receiver` -- `venv/bin/pyinstaller --onefile --paths=venv/lib/python3.12/site-packages main.py` -- Run binary: `/dist/main` +# Create installer +## For Mac +- Increase version number in `make_installer_mac.sh` +- Run: `make_installer_mac.sh` +- Find Mac package in `dist/osc2laser.pkg` # Support & Community Join our [Community](https://community.goodtimes.technology/c/osc2laser/5) to discuss your ideas and issues. diff --git a/osc-receiver/main.py b/osc-receiver/main.py index 5985da0..86be980 100644 --- a/osc-receiver/main.py +++ b/osc-receiver/main.py @@ -9,6 +9,16 @@ import configparser import global_data +# Set the working directory to the directory of the executable +if getattr(sys, 'frozen', False): + # If the application is frozen (packaged by PyInstaller), set the working directory to the executable's directory + application_path = os.path.dirname(sys.executable) +else: + # If the application is not frozen, assume it's running from the source code directory + application_path = os.path.dirname(os.path.abspath(__file__)) + +os.chdir(application_path) + # Initialization logging.basicConfig(encoding='utf-8', level=logging.DEBUG) diff --git a/osc-receiver/make_installer_mac.sh b/osc-receiver/make_installer_mac.sh new file mode 100755 index 0000000..b714d67 --- /dev/null +++ b/osc-receiver/make_installer_mac.sh @@ -0,0 +1,38 @@ +#!/bin/Bash +venv/bin/pyinstaller --onefile --paths=venv/lib/python3.12/site-packages main.py + +mkdir -p dist/osc2laser.app/Contents/MacOS + +mv dist/main dist/osc2laser.app/Contents/MacOS/osc2laser +chmod +x dist/osc2laser.app/Contents/MacOS/osc2laser + +cp config_laser1.txt dist/osc2laser.app/Contents/MacOS/ +cp libHeliosDacAPI.so dist/osc2laser.app/Contents/MacOS/ + +cat > dist/osc2laser.app/Contents/Info.plist < + + + + CFBundleDisplayName + osc2laser + CFBundleExecutable + osc2laser + CFBundleIdentifier + tchnology.goodtimes.osc2laser + CFBundleName + osc2laser + CFBundleVersion + 1.0.0 + CFBundlePackageType + APPL + + +EOF + +# hdiutil create -volname "osc2laser" -srcfolder dist/osc2laser.app -ov -format UDZO dist/osc2laser.dmg + +pkgbuild --component dist/osc2laser.app --install-location /Applications dist/osc2laser.pkg + +# Otherwise the .pkg won't install to /Applications +rm -Rf dist/osc2laser.app \ No newline at end of file