Skip to content

macOS: open .bup files that launch BenchUp - #67

Merged
dannycoulombe merged 2 commits into
BenchUp3D:mainfrom
furilo:macos-open-bup-at-launch
Nov 14, 2026
Merged

dannycoulombe merged 2 commits into
BenchUp3D:mainfrom
furilo:macos-open-bup-at-launch

Conversation

@furilo

@furilo furilo commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Fixes #58.

Problem

On macOS, opening a .bup while BenchUp is not running (Finder double-click, open file.bup, open -b … file.bup) started the app and then showed "BenchUp cannot open files in the 'BenchUp project' format".

AppKit dispatches the launch open-documents event during finishLaunching, before eframe creates the app. desktop_files::initialize() only added application:openFiles: to winit's delegate from inside the app constructor, so at launch there was no handler and AppKit fell back to NSDocumentController.

Fix

  • main() calls the new desktop_files::prepare_launch() before eframe::run_native. On macOS it observes NSApplicationWillFinishLaunchingNotification, which fires after winit sets its delegate and before AppKit dispatches launch documents. The observer adds application:openFiles: to the delegate at that point, and the files go into the existing queue that the app drains every frame.
    • Installing an Apple Event handler before run_native would not work, because NSApplication installs its own handlers during launch and replaces it. eframe has no hook between building the event loop and running it.
  • Once the handler is installed, AppKit also delivers command-line documents through it. initialize() therefore reads launch arguments directly only when the handler could not be installed, so files are not queued twice. Other platforms are unchanged.
  • The queue accepts only .bup paths, makes relative paths absolute, and opens a repeated request once (the file requested last stays open).
  • The macOS bridge now uses the typed objc2 / objc2-app-kit / objc2-foundation crates instead of hand-written objc_msgSend transmutes. They are the versions eframe, egui-winit and rfd already use, so no new crates enter the lockfile.

Testing

Tested on macOS with a debug build placed in a copy of the app bundle, with an isolated HOME. A launch counted as opened when the autosaved model.json referenced the document:

Scenario 0.7.1 release This branch
open -a BenchUp.app file.bup with BenchUp closed ❌ format error ✅
open -a BenchUp.app --args file.bup (current CLI workaround) ✅ ✅
Executable started directly with an absolute path – ✅
Executable started directly with a relative path – ✅
Opening a file while BenchUp is already running – ✅ (single instance)
  • cargo test -p benchup-app --lib desktop_files: passes. New unit tests cover queue de-duplication and order, plus path filtering and normalisation.
  • The launch-time AppKit path cannot be covered by unit tests, because it needs a real bundle launched through LaunchServices.
  • Linux and Windows code paths are unchanged apart from the shared path filtering. They were not tested locally.

🤖 Generated with Claude Code

When macOS starts BenchUp to open a document, AppKit dispatches the
open-documents event during finishLaunching, before eframe creates the
app and before desktop_files::initialize() added application:openFiles:
to winit's delegate. AppKit then fell back to its document controller
and reported that BenchUp cannot open the BenchUp project format.

Observe NSApplicationWillFinishLaunchingNotification from main() before
the event loop starts. It fires after winit sets its delegate and before
AppKit dispatches launch documents, so the handler is in place in time.
Once installed, AppKit also delivers command-line documents through it,
so launch arguments are only read directly when the handler is missing.

The queue now accepts only .bup paths, makes them absolute, and opens a
repeated request once. The macOS bridge uses the objc2 crates already in
the dependency tree through eframe.

Fixes BenchUp3D#58

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@furilo

furilo commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

@dannycoulombe heads-up: the failing Test core check here isn't caused by this PR. It comes from main.

joinery::slots::tests::direct_rounded_pockets_match_boolean_machining_and_form_closed_solids panics at crates/benchup-core/src/joinery_slots.rs:368, because cut_box(...) returns None and the test unwraps it. The test arrived with 963f45d ("Add pocket joinery and accelerate joint editing and rendering").

I left it out of this PR to keep the fix scoped to #58.

@dannycoulombe

Copy link
Copy Markdown
Collaborator

@furilo Yes, more often than not, they're related to recent updates elsewhere. No worries! You can leave it to me. I'll fix it directly in the PR.

@dannycoulombe
dannycoulombe merged commit 3421231 into BenchUp3D:main Nov 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: opening a .bup while BenchUp is not running fails with "cannot open files in the BenchUp project format"

2 participants