Repository navigation
Conversation
…e clicked config (#188) macOS delivers double-clicked .profiles documents to a bundled app exclusively as an `odoc` AppleEvent — never via argv — and nothing in the chain handled it (the `profiles.desktop.appkit_events` module that launch/context.py's docstring referenced did not exist). The clicked file was silently dropped, and launch resolution fell back to a literal-name folder search, so double-clicks either applied a *previously loaded* config (wrong handoff toast), showed the macOS "cannot open files in the 'ProFiles launch-handoff document' format" dialog, or proposed creating a new configuration. - new `desktop/appkit_events.capture_open_documents()`: before launch resolution, installs a temporary NSApplication delegate (+ aevt/odoc AE-manager handler), declares the app finished launching so LaunchServices releases the queued event, and pumps the event queue for a bounded 1.5s — only for GUI-style launches (uninformative CWD), degrading to a no-op everywhere else - new `desktop/appkit_events.install_running_doc_handler()`: adds `application:openFiles:` to pywebview's AppDelegate (objc.classAddMethod, same pattern as the media-capture hook) so a double-click landing on the running window applies the config in-process via the handoff route's apply+notify path instead of the macOS error dialog - `launch/context.with_documents()` merges the captured documents into the launch context; `cwd_is_uninformative` is now public and shared - `app.py` remembers the launch `source` and `_handoff_to_running_instance()` now refuses to forward folder-search-resolved configs (source "cwd"/"launcher") — defense-in-depth against silently swapping a running instance's configuration with an arbitrary search hit - `server/routes/config.apply_config_from_disk()` made public so the desktop layer can share the handoff route's apply semantics Verified on macOS with a Briefcase build: double-clicking b.profiles onto a running instance now hands off b.profiles (was: any folder-found config), and double-clicking while the app itself runs applies the clicked config in-process with the toast (was: error dialog). Fixes #188
…ework imports (CI Linux)
…sts run on every CI platform
…earch Launching ProFiles from a folder (Desktop shortcut, shell) searched only the literal names (.profiles, .profiles.yaml, .profiles.yml), so folders holding named configurations (a.profiles, b.profiles, …) found nothing and the app proposed creating a starter instead of loading what the user had put there (observed during the issue #188 double-click investigation). find_config_file() keeps its canonical tiers exactly as before (.profiles, then .profiles.yaml, then .profiles.yml, breadth-first) and adds a second tier reached only when no canonical name exists anywhere in the tree: any file whose name ends with one of those suffixes is accepted, sorted ascending by (depth, name, path) — shallowest wins, ties broken alphabetically, i.e. the first file of the folder in the common single-folder case. The starter template's DISCOVERY note and the loader docstring now describe the actual rule. Single implementation point: loader, launch resolution, reader shim and server state all route through find_config_file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #188
Problem
On macOS, double-clicking a
.profilesfile never loaded the clicked file:.appitself running.profiles/.profiles.yamlthe folder search foundRoot cause
macOS delivers double-clicked documents to a bundled app exclusively as an
odocAppleEvent — never via argv. Nothing handled it: the Briefcase stub registers no AppleEvent handler, pywebview's AppDelegate doesn't implementapplication:openFiles:, and theprofiles.desktop.appkit_eventsmodule thatlaunch/context.py's docstring referenced did not exist. With the document signal lost, resolution fell back to a literal-name (.profiles/.profiles.yaml/.profiles.yml) folder search and picked an arbitrary hit — which the busy-port handoff then faithfully forwarded to the running instance. The handoff mechanism itself was verified fine; only document delivery was broken.Fix
desktop/appkit_eventsmodule (the missing piececontext.pyalready documented):capture_open_documents()installs a temporaryNSApplicationDelegate(+aevt/odocAE-manager handler), callsNSApplication.finishLaunching()so LaunchServices releases the queued event, and pumps the app event queue for a bounded 1.5s. Runs only for GUI-style launches (uninformative CWD — the existing heuristic shared with the Finder probe); degrades to a no-op off macOS / without PyObjC / on any failure. Result merged via newlaunch.context.with_documents().install_running_doc_handler()addsapplication:openFiles:to pywebview's AppDelegate viaobjc.classAddMethod(same pattern as the existing media-capture hook), routing the event through the handoff route's shared apply+notify path so the existing toast poll fires.app.pyremembers the launchsourceand_handoff_to_running_instance()now refuses to forward folder-search-resolved configs (sourcecwd/launcher) — such a launch transparently starts a separate instance on a free port instead of silently swapping a running instance's configuration.server/routes/config.apply_config_from_disk()made public (was_private) so the desktop layer shares the handoff route's apply semantics.Folder config search now accepts named configs (follow-up request)
Launching ProFiles from a folder (Desktop shortcut, shell) searched only the literal names, so a folder holding
a.profiles/b.profilesfound nothing and proposed creating a starter.find_config_file()now adds a second tier reached only when no canonical name exists anywhere in the tree: any file whose name ends with.profiles/.profiles.yaml/.profiles.ymlis accepted, sorted ascending by (depth, name) — shallowest wins, ties broken alphabetically, i.e. the first file of the folder in the common single-folder case. Canonical tiers keep strict precedence (a.profilesanywhere still beats any named config anywhere); the/-root guard and depth bounds are unchanged. Single implementation point: loader, launch resolution, reader shim and server state all route throughfind_config_file().Verification (all empirical, on macOS)
open -a= true LS doc launch) ofb.profilesonto a running instance holdinga.profiles: telemetry showsodoc capture done: 1 document(s): [.../b.profiles], handoff applies b.profiles, app exits 0 — was: arbitrary folder-found config.osascriptodoc to the running.app: config applied in-process, toast event "applied from the double-clicked document", no dialog — was: macOS error dialog.a.profiles+b.profilesloads a.profiles (ascending first) — was: "create a configuration" proposal.Tests
tests/desktop/test_appkit_events.py: capture gating (platform/CWD/failure degradation), teardown ordering, real-NSAppleEventDescriptorextraction (furl + percent-escapes + utxt + empty), running-handler selector installation and callback plumbing.tests/core/config/io/test_yaml_io.py: newTestFindConfigFileWildcard— named-config discovery, ascending sort, canonical-tier precedence (same folder and across depths), named yaml variants, shallowest-beats-alphabetical, non-config files ignored, depth bound.tests/launch/test_context.py:with_documentsmerge/dedupe/source semantics, publiccwd_is_uninformative.tests/test_app.py: handoff gate (folder-search source refused, document/explicit still forwarded).tests/test_app_launch_resolution.py: source recording, headless skip, captured doc driving resolution.tests/desktop/test_launcher.py: applier behavior (apply+notify, reject non-config, missing file) + handler wiring.Full suite: 1561 passed / 1 skipped, coverage ≥85% gate ✓, pylint 9.88 (gate 8.0), ruff clean, CI + Windows packaging dry-run green.
Notes for reviewers
/or inside the runtime prefix) — terminal launches keep their argv/CWD signals and pay nothing.AGENTS.md/tests/AGENTS.mdtrees updated in the same commit (also fixes the pre-existingtest_handoff.pylisting gap).