forked from 1b-agent/opencadstudio-upstream
feat(open): open drawings in the running editor
Double-clicking a drawing started a whole second copy of the app. Now it lands as a tab in the editor already open, and that window comes forward. The election is the bind itself: every GUI launch tries a deterministic per-user loopback port, and the OS grants it to exactly one process and releases it on any death, SIGKILL included. Nothing to reap, no PID to probe, no stale lock after a crash. The winner serves the port from an iced subscription; the loser checks it is talking to a matching editor, hands the paths over and exits. Every surprise — no answer, a stranger on the port, a timeout — boots a normal window, i.e. the old behaviour: the feature can degrade, but it cannot lose the file. The gate in main is positional, after every headless mode has returned. The plugin runner is this same binary re-spawning itself, so a flag list would rot the first time a mode is added; a position cannot. Handing a drawing over that is already open switches to its tab instead of loading a second copy, comparing resolved paths so a symlink or a `..` hop is still recognised as the same file. `opening` is a single slot that a second open would overwrite, and on_file_opened drops any result arriving once it is clear — so drawings handed over at once would silently vanish. They queue in pending_opens, drained from every path that clears the slot, error and cancel included. Exec becomes %F so one launch takes the whole selection; the CLI takes a list and boot fans it out through the same door. --new-instance forces a separate process; --read-only / --script / --new always get their own. Not reused: the automation server. It dispatches arbitrary commands and writes arbitrary paths, and its open replaces the active tab's document in place — publishing that on a port every local process can reach would be unforced privilege escalation. Only its JSON-lines framing is shared. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
1490fe4ea9
commit
b3bd93d8c5
11 files changed
+665
-19
No files matched your search
+24
-1
@@ -100,6 +100,29 @@ fn main() -> iced::Result {
|
||||
std::process::exit(code);
|
||||
}
|
||||
|
||||
// Single instance: a double-clicked drawing belongs as a tab in the
|
||||
// editor that is already open, not in a second copy of the app.
|
||||
//
|
||||
// The gate is POSITIONAL, and that is the point: every headless mode
|
||||
// has already returned above — the plugin runner, which is this same
|
||||
// binary re-spawning itself, most of all. A flag list here would rot
|
||||
// the first time a mode is added; a position cannot.
|
||||
if !args.new_instance {
|
||||
if let io::single_instance::Claim::Existing(stream) = io::single_instance::claim() {
|
||||
// Only bare files forward. `--read-only` / `--script` / `--new`
|
||||
// configure the whole editor rather than a tab, so they always
|
||||
// get a process of their own.
|
||||
let plain_open =
|
||||
!args.read_only && args.script.is_none() && !args.new && !args.files.is_empty();
|
||||
if plain_open && io::single_instance::handoff(stream, &args.files) {
|
||||
return Ok(());
|
||||
}
|
||||
// Nothing to forward, or the far end never acknowledged: fall
|
||||
// through and boot our own window. We hold no listener, so the
|
||||
// editor that owns the port keeps serving.
|
||||
}
|
||||
}
|
||||
|
||||
// GUI: stash the startup config for `app::boot` to pick up.
|
||||
let script_lines = args
|
||||
.script
|
||||
@@ -118,7 +141,7 @@ fn main() -> iced::Result {
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let _ = cli::GUI_CONFIG.set(cli::GuiConfig {
|
||||
file: if args.new { None } else { args.file },
|
||||
files: if args.new { Vec::new() } else { args.files },
|
||||
new: args.new,
|
||||
read_only: args.read_only,
|
||||
script_lines,
|
||||
|
||||
Reference in new issue
Block a user