Skip to content

Add macOS file association support for .ndbx files#529

Open
fdb wants to merge 2 commits intorewrite-in-rustfrom
claude/add-ndbx-file-association-DJwhY
Open

Add macOS file association support for .ndbx files#529
fdb wants to merge 2 commits intorewrite-in-rustfrom
claude/add-ndbx-file-association-DJwhY

Conversation

@fdb
Copy link
Member

@fdb fdb commented Feb 14, 2026

Summary

This PR adds support for opening .ndbx files on macOS through Finder double-clicks and drag-and-drop operations. It includes runtime injection of the application:openFiles: delegate method into winit's app delegate, along with proper file type declarations in the app bundle.

Key Changes

  • New macOS file-open handler module (macos_file_open.rs):

    • Uses Objective-C runtime FFI to inject application:openFiles: into winit's delegate class at runtime
    • Stores received file paths in a thread-safe global Mutex<Vec<PathBuf>>
    • Filters files to only accept .ndbx extensions
    • Injection happens during eframe initialization, before the event loop processes Apple Events
  • Updated Info.plist:

    • Added LSItemContentTypes to declare support for net.nodebox.ndbx file type
    • Added UTExportedTypeDeclarations to define the custom net.nodebox.ndbx type with proper conformance to public.xml and public.data
    • Removed obsolete Java configuration
    • Updated copyright string
  • Enhanced app.rs:

    • Added open_dropped_file() method to handle file loading from both drag-and-drop and macOS file associations
    • Integrated drag-and-drop file handling in the update loop
    • Added macOS-specific polling of pending files from the file-open handler
    • Properly updates project context, recent files, and render state when files are opened
  • Updated lib.rs:

    • Exposed macos_file_open module (macOS-only)
    • Calls inject_file_open_handler() during app initialization

Implementation Details

The solution works around winit 0.30.12's lack of application:openFiles: support by:

  1. Injecting the method directly into the delegate class using class_addMethod
  2. Storing file paths in a global mutex that the app polls each frame
  3. Timing the injection to occur after NSApplication initialization but before event processing
  4. Filtering received files to only process .ndbx documents

https://claude.ai/code/session_01NXut6FX3rsrwY1mDyjUadn

Support opening .ndbx files by dragging them onto the NodeBox window.
Also modernize the macOS Info.plist: remove legacy Java entries, add
UTExportedTypeDeclarations with a proper UTI (net.nodebox.ndbx) so
macOS recognizes .ndbx files and shows NodeBox in "Open With" menus.

On Windows, double-click file opening already works via CLI arguments.

https://claude.ai/code/session_01NXut6FX3rsrwY1mDyjUadn
…o winit's delegate.

winit 0.30.12's NSApplicationDelegate doesn't implement application:openFiles:,
so macOS shows an error when double-clicking .ndbx files. This uses raw ObjC
runtime calls (class_addMethod) to inject the method into the delegate's class
during the eframe creation callback — after the delegate exists but before
Apple Events are dispatched. File paths are stored in a global Mutex and polled
each frame in update().

Handles both cold start (file double-clicked to launch app) and warm start
(file double-clicked while app is already running). No new crate dependencies.

https://claude.ai/code/session_01NXut6FX3rsrwY1mDyjUadn
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.

2 participants