Skip to content

Commit

Permalink
Factor out install_cli action handler
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdeviant committed Dec 17, 2024
1 parent 4945232 commit d94da9c
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions crates/zed/src/zed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,44 +468,7 @@ fn register_actions(
.register_action(move |_, _: &zed_actions::ResetBufferFontSize, cx| {
theme::reset_buffer_font_size(cx)
})
.register_action(|_, _: &install_cli::Install, cx| {
cx.spawn(|workspace, mut cx| async move {
if cfg!(any(target_os = "linux", target_os = "freebsd")) {
const PROMPT_DETAIL: &str = "If you installed Zed from our official release add ~/.local/bin to your PATH.\n\nIf you installed Zed from a different source like your package manager, then you may need to create an alias/symlink manually.\n\nDepending on your package manager, the CLI might be named zeditor, zedit, zed-editor or something else.";

let prompt = cx.prompt(
PromptLevel::Warning,
"CLI should already be installed",
Some(PROMPT_DETAIL),
&["Ok"],
);
cx.background_executor().spawn(prompt).detach();
return Ok(());
}
let path = install_cli::install_cli(cx.deref())
.await
.context("error creating CLI symlink")?;

workspace.update(&mut cx, |workspace, cx| {
struct InstalledZedCli;

workspace.show_toast(
Toast::new(
NotificationId::unique::<InstalledZedCli>(),
format!(
"Installed `zed` to {}. You can launch {} from your terminal.",
path.to_string_lossy(),
ReleaseChannel::global(cx).display_name()
),
),
cx,
)
})?;
register_zed_scheme(&cx).await.log_err();
Ok(())
})
.detach_and_prompt_err("Error installing zed cli", cx, |_, _| None);
})
.register_action(install_cli)
.register_action(|_, _: &install_cli::RegisterZedScheme, cx| {
cx.spawn(|workspace, mut cx| async move {
register_zed_scheme(&cx).await?;
Expand Down Expand Up @@ -751,6 +714,45 @@ fn test_panic(_: &TestPanic, _: &mut AppContext) {
panic!("Ran the TestPanic action")
}

fn install_cli(_: &mut Workspace, _: &install_cli::Install, cx: &mut ViewContext<Workspace>) {
const LINUX_PROMPT_DETAIL: &str = "If you installed Zed from our official release add ~/.local/bin to your PATH.\n\nIf you installed Zed from a different source like your package manager, then you may need to create an alias/symlink manually.\n\nDepending on your package manager, the CLI might be named zeditor, zedit, zed-editor or something else.";

cx.spawn(|workspace, mut cx| async move {
if cfg!(any(target_os = "linux", target_os = "freebsd")) {
let prompt = cx.prompt(
PromptLevel::Warning,
"CLI should already be installed",
Some(LINUX_PROMPT_DETAIL),
&["Ok"],
);
cx.background_executor().spawn(prompt).detach();
return Ok(());
}
let path = install_cli::install_cli(cx.deref())
.await
.context("error creating CLI symlink")?;

workspace.update(&mut cx, |workspace, cx| {
struct InstalledZedCli;

workspace.show_toast(
Toast::new(
NotificationId::unique::<InstalledZedCli>(),
format!(
"Installed `zed` to {}. You can launch {} from your terminal.",
path.to_string_lossy(),
ReleaseChannel::global(cx).display_name()
),
),
cx,
)
})?;
register_zed_scheme(&cx).await.log_err();
Ok(())
})
.detach_and_prompt_err("Error installing zed cli", cx, |_, _| None);
}

fn quit(_: &Quit, cx: &mut AppContext) {
let should_confirm = WorkspaceSettings::get_global(cx).confirm_quit;
cx.spawn(|mut cx| async move {
Expand Down

0 comments on commit d94da9c

Please sign in to comment.