|
15 | 15 | import json |
16 | 16 | from pathlib import Path |
17 | 17 |
|
| 18 | +def setup_macos_launcher_hack(app_bundle_path): |
| 19 | + """ |
| 20 | + Implement the launcher script hack for macOS to get persistent terminal |
| 21 | + Based on the original packaging approach |
| 22 | + """ |
| 23 | + print("Setting up macOS launcher script hack...") |
| 24 | + |
| 25 | + macos_dir = app_bundle_path / "Contents" / "MacOS" |
| 26 | + original_executable = macos_dir / "Jumperless" |
| 27 | + cli_executable = macos_dir / "Jumperless_cli" |
| 28 | + |
| 29 | + if not original_executable.exists(): |
| 30 | + print(f"Warning: Original executable not found: {original_executable}") |
| 31 | + return |
| 32 | + |
| 33 | + # Rename the original executable to Jumperless_cli |
| 34 | + if cli_executable.exists(): |
| 35 | + cli_executable.unlink() |
| 36 | + original_executable.rename(cli_executable) |
| 37 | + print(f"Renamed {original_executable} to {cli_executable}") |
| 38 | + |
| 39 | + # Create launcher script |
| 40 | + launcher_script_content = '''#!/bin/bash |
| 41 | +# Jumperless macOS Launcher |
| 42 | +# Opens Terminal and runs the CLI application |
| 43 | +
|
| 44 | +# Get the directory of this script (inside the app bundle) |
| 45 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 46 | +CLI_EXECUTABLE="$SCRIPT_DIR/Jumperless_cli" |
| 47 | +
|
| 48 | +# Check if CLI executable exists |
| 49 | +if [ ! -f "$CLI_EXECUTABLE" ]; then |
| 50 | + echo "Error: CLI executable not found at $CLI_EXECUTABLE" |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | +
|
| 54 | +# Use AppleScript to open Terminal and run the CLI app |
| 55 | +osascript -e " |
| 56 | +tell application \\"Terminal\\" |
| 57 | + activate |
| 58 | + set newWindow to do script \\"\\" |
| 59 | + delay 0.5 |
| 60 | + do script \\"cd '$SCRIPT_DIR' && ./Jumperless_cli\\" in newWindow |
| 61 | + set bounds of front window to {100, 100, 1000, 700} |
| 62 | +end tell |
| 63 | +" |
| 64 | +''' |
| 65 | + |
| 66 | + # Write launcher script |
| 67 | + with open(original_executable, 'w') as f: |
| 68 | + f.write(launcher_script_content) |
| 69 | + |
| 70 | + # Make launcher script executable |
| 71 | + os.chmod(original_executable, 0o755) |
| 72 | + print(f"Created launcher script at {original_executable}") |
| 73 | + |
18 | 74 | def create_python_fallback(platform, arch, output_dir): |
19 | 75 | """Create Python fallback package with launcher script""" |
20 | 76 | print(f"Creating Python fallback package for {platform}-{arch}") |
@@ -273,13 +329,16 @@ def package_platform(platform, arch, output_dir): |
273 | 329 |
|
274 | 330 | # Copy executable if it exists |
275 | 331 | if platform == "macos": |
276 | | - # Handle .app bundle for macOS |
| 332 | + # Handle .app bundle for macOS with launcher script hack |
277 | 333 | app_bundle_name = "Jumperless.app" |
278 | 334 | app_bundle_path = Path(f"dist/{platform}/{app_bundle_name}") |
279 | 335 | if app_bundle_path.exists(): |
280 | 336 | # Copy the entire .app bundle |
281 | 337 | shutil.copytree(app_bundle_path, platform_dir / app_bundle_name, dirs_exist_ok=True) |
282 | 338 | print(f"Copied .app bundle: {app_bundle_name}") |
| 339 | + |
| 340 | + # Implement launcher script hack for persistent terminal |
| 341 | + setup_macos_launcher_hack(platform_dir / app_bundle_name) |
283 | 342 | else: |
284 | 343 | print(f"Warning: .app bundle not found: {app_bundle_path}") |
285 | 344 | else: |
@@ -417,12 +476,14 @@ def create_platform_readme(platform_dir, platform): |
417 | 476 | ''' |
418 | 477 | elif platform == "macos": |
419 | 478 | readme_content += ''' |
420 | | -Double-click `Jumperless.app` in Finder to run. |
| 479 | +Double-click `Jumperless.app` in Finder to run. This will open a new Terminal window and run the Jumperless CLI application. |
421 | 480 |
|
422 | 481 | Or open from Terminal: |
423 | 482 | ```bash |
424 | 483 | open Jumperless.app |
425 | 484 | ``` |
| 485 | +
|
| 486 | +The app will automatically launch in a new Terminal window for the best CLI experience. |
426 | 487 | ''' |
427 | 488 | elif platform == "windows": |
428 | 489 | readme_content += ''' |
|
0 commit comments