PadIO: external context channel (watched ~/.config/padio/context) - #14
Merged
Conversation
Add ContextObserver, a @mainactor ObservableObject that watches a single-token file at ~/.config/padio/context and publishes the trimmed token (nil when missing or empty). It mirrors the DispatchSource pattern in ConfigLoader/AppObserver but re-arms the file watch on rename/delete so atomic replaces keep firing, and also watches the parent directory so a file created after launch is picked up. Missing file at launch is not an error. ControllerManager owns it alongside appObserver/configLoader and wires a Combine subscription. Token-to-mode resolution is a follow-up (#9); this is transport only. Closes #8 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Implements #8.
Adds an inbound channel so an external process (the herdr bridge in #12) can tell PadIO which app is in focus, by writing a single token to
~/.config/padio/context.What's here (transport only)
ContextObserver(PadIO/ContextObserver.swift):@MainActor/ObservableObject, publishes@Published private(set) var context: String?. Trims whitespace/newlines; empty or missing file both meannil.ControllerManageralongsideappObserver/configLoader, with a Combine subscription ininit(). Mapping token → mode is the follow-up (PadIO: context_modes resolution (context token to mode) #9); for now the sink just logs.Robustness
rename), which leavesConfigLoader's one-shot pattern watching a stale fd.ContextObservercancels and re-establishes the file source after each event, so repeated atomic writes keep being observed.nil.Producer contract (for the bridge, #12)
rename(2)over~/.config/padio/contextNote
The atomic-replace-breaks-hot-reload issue also affects
config.jsoninConfigLoader; fixing it there is out of scope here and should be filed separately if confirmed.Verified with
BuildProject(builds clean). Runtime smoke test (touch the file, watch the console) is best done once #9 wires it to a visible mode change.🤖 Generated with Claude Code