Skip to content

Commit

Permalink
update cli
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkuiZhang committed Feb 21, 2025
1 parent d10bfe1 commit c5d83ec
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ anyhow.workspace = true
clap.workspace = true
collections.workspace = true
ipc-channel = "0.19"
only_instance.workspace = true
parking_lot.workspace = true
paths.workspace = true
release_channel.workspace = true
Expand All @@ -33,7 +34,7 @@ util.workspace = true
tempfile.workspace = true

[target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies]
exec.workspace = true
exec.workspace = true
fork.workspace = true

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
18 changes: 12 additions & 6 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,11 @@ mod linux {
}

fn launch(&self, ipc_url: String) -> anyhow::Result<()> {
let sock_path = paths::support_dir().join(format!("zed-{}.sock", *RELEASE_CHANNEL));
let sock = UnixDatagram::unbound()?;
if sock.connect(&sock_path).is_err() {
self.boot_background(ipc_url)?;
} else {
if let Ok(sock) = only_instance::other_instance_running() {
// There is already an instance running
sock.send(ipc_url.as_bytes())?;
} else {
self.boot_background(ipc_url)?;
}
Ok(())
}
Expand Down Expand Up @@ -535,7 +534,14 @@ mod windows {
unimplemented!()
}
fn launch(&self, _ipc_url: String) -> anyhow::Result<()> {
unimplemented!()
if only_instance::ensure_only_instance() {
// start a new instance
// send ipc_url to the new instance
} else {
// There is already an instance running
// send ipc_url to the existing instance
}
Ok(())
}
fn run_foreground(&self, _ipc_url: String) -> io::Result<ExitStatus> {
unimplemented!()
Expand Down
2 changes: 1 addition & 1 deletion crates/only_instance/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn ensure_only_instance() -> Result<UnixDatagram> {
UnixDatagram::bind(&sock_path)
}

pub fn ensure_only_instance_cli() -> Result<UnixDatagram> {
pub fn other_instance_running() -> Result<UnixDatagram> {
let sock_path = paths::support_dir().join(format!("zed-{}.sock", *RELEASE_CHANNEL_NAME));
let sock = UnixDatagram::unbound()?;
sock.connect(&sock_path).and(Ok(sock))
Expand Down

0 comments on commit c5d83ec

Please sign in to comment.