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 <noreply@anthropic.com>
This commit is contained in:
1 parent
1490fe4ea9
commit
b3bd93d8c5
11 files changed
+665
-19
No files matched your search
+11
-5
@@ -24,14 +24,20 @@ use clap::Parser;
|
||||
long_about = None,
|
||||
)]
|
||||
pub struct Cli {
|
||||
/// CAD file to open at startup (.dwg / .dxf). Also used by the OS file
|
||||
/// association when a drawing is double-clicked.
|
||||
pub file: Option<PathBuf>,
|
||||
/// CAD files to open at startup (.dwg / .dxf). Also how the OS file
|
||||
/// association launches us when drawings are double-clicked — selecting
|
||||
/// several hands them all to one launch, so this takes a list.
|
||||
pub files: Vec<PathBuf>,
|
||||
|
||||
/// Start with a new empty drawing, ignoring any file argument.
|
||||
#[arg(long)]
|
||||
pub new: bool,
|
||||
|
||||
/// Always start a new editor process, even when one is already running.
|
||||
/// Without this, opening a drawing hands it to the running editor as a tab.
|
||||
#[arg(long)]
|
||||
pub new_instance: bool,
|
||||
|
||||
/// Open read-only: editing is allowed but saving is disabled.
|
||||
#[arg(long)]
|
||||
pub read_only: bool,
|
||||
@@ -78,8 +84,8 @@ pub struct Cli {
|
||||
/// because the iced daemon's boot closure takes no arguments.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct GuiConfig {
|
||||
/// File to open on launch (`None` for a blank session).
|
||||
pub file: Option<PathBuf>,
|
||||
/// Files to open on launch (empty for a blank session).
|
||||
pub files: Vec<PathBuf>,
|
||||
/// Open a fresh drawing tab on launch instead of the welcome screen.
|
||||
pub new: bool,
|
||||
/// Saving disabled for this session.
|
||||
|
||||
Reference in new issue
Block a user