install_cli: Show feedback when installing CLI from welcome screen (#28532)
Closes #28408 Release Notes: - Fixed no feedback provided when installing CLI from welcome page.
This commit is contained in:
parent
46b1df2e2d
commit
0921762b59
5 changed files with 71 additions and 57 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -7221,9 +7221,12 @@ name = "install_cli"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"client",
|
||||
"gpui",
|
||||
"release_channel",
|
||||
"smol",
|
||||
"util",
|
||||
"workspace",
|
||||
"workspace-hack",
|
||||
]
|
||||
|
||||
|
|
|
@ -16,7 +16,10 @@ test-support = []
|
|||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
client.workspace = true
|
||||
gpui.workspace = true
|
||||
release_channel.workspace = true
|
||||
smol.workspace = true
|
||||
util.workspace = true
|
||||
workspace-hack.workspace = true
|
||||
workspace.workspace = true
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
use anyhow::{Result, anyhow};
|
||||
use gpui::{AsyncApp, actions};
|
||||
use anyhow::{Context as _, Result, anyhow};
|
||||
use client::ZED_URL_SCHEME;
|
||||
use gpui::{AppContext as _, AsyncApp, Context, PromptLevel, Window, actions};
|
||||
use release_channel::ReleaseChannel;
|
||||
use std::ops::Deref;
|
||||
use std::path::{Path, PathBuf};
|
||||
use util::ResultExt;
|
||||
use workspace::notifications::{DetachAndPromptErr, NotificationId};
|
||||
use workspace::{Toast, Workspace};
|
||||
|
||||
actions!(cli, [Install, RegisterZedScheme]);
|
||||
|
||||
pub async fn install_cli(cx: &AsyncApp) -> Result<PathBuf> {
|
||||
async fn install_script(cx: &AsyncApp) -> Result<PathBuf> {
|
||||
let cli_path = cx.update(|cx| cx.path_for_auxiliary_executable("cli"))??;
|
||||
let link_path = Path::new("/usr/local/bin/zed");
|
||||
let bin_dir_path = link_path.parent().unwrap();
|
||||
|
@ -56,3 +61,47 @@ pub async fn install_cli(cx: &AsyncApp) -> Result<PathBuf> {
|
|||
Err(anyhow!("error running osascript"))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn register_zed_scheme(cx: &AsyncApp) -> anyhow::Result<()> {
|
||||
cx.update(|cx| cx.register_url_scheme(ZED_URL_SCHEME))?
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn install_cli(window: &mut Window, cx: &mut Context<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_in(window, async move |workspace, cx| {
|
||||
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_spawn(prompt).detach();
|
||||
return Ok(());
|
||||
}
|
||||
let path = install_script(cx.deref())
|
||||
.await
|
||||
.context("error creating CLI symlink")?;
|
||||
|
||||
workspace.update_in(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", window, cx, |_, _, _| None);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use language::language_settings::{EditPredictionProvider, all_language_settings}
|
|||
use settings::{Settings, SettingsStore};
|
||||
use std::sync::Arc;
|
||||
use ui::{CheckboxWithLabel, ElevationIndex, Tooltip, prelude::*};
|
||||
use util::ResultExt;
|
||||
use vim_mode_setting::VimModeSetting;
|
||||
use workspace::{
|
||||
AppState, Welcome, Workspace, WorkspaceId,
|
||||
|
@ -219,13 +220,11 @@ impl Render for WelcomePage {
|
|||
.icon_size(IconSize::XSmall)
|
||||
.icon_color(Color::Muted)
|
||||
.icon_position(IconPosition::Start)
|
||||
.on_click(cx.listener(|_, _, _, cx| {
|
||||
.on_click(cx.listener(|this, _, window, cx| {
|
||||
telemetry::event!("Welcome CLI Installed");
|
||||
cx
|
||||
.spawn(async move |_, cx| {
|
||||
install_cli::install_cli(&cx).await
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
this.workspace.update(cx, |_, cx|{
|
||||
install_cli::install_cli(window, cx);
|
||||
}).log_err();
|
||||
})),
|
||||
)
|
||||
})
|
||||
|
|
|
@ -14,7 +14,7 @@ pub use app_menus::*;
|
|||
use assets::Assets;
|
||||
use assistant_context_editor::AssistantPanelDelegate;
|
||||
use breadcrumbs::Breadcrumbs;
|
||||
use client::{ZED_URL_SCHEME, zed_urls};
|
||||
use client::zed_urls;
|
||||
use collections::VecDeque;
|
||||
use command_palette_hooks::CommandPaletteFilter;
|
||||
use debugger_ui::debugger_panel::DebugPanel;
|
||||
|
@ -25,10 +25,10 @@ use futures::{StreamExt, channel::mpsc, select_biased};
|
|||
use git_ui::git_panel::GitPanel;
|
||||
use git_ui::project_diff::ProjectDiffToolbar;
|
||||
use gpui::{
|
||||
Action, App, AppContext as _, AsyncApp, AsyncWindowContext, Context, DismissEvent, Element,
|
||||
Entity, Focusable, KeyBinding, MenuItem, ParentElement, PathPromptOptions, PromptLevel,
|
||||
ReadGlobal, SharedString, Styled, Task, TitlebarOptions, UpdateGlobal, Window, WindowKind,
|
||||
WindowOptions, actions, point, px,
|
||||
Action, App, AppContext as _, AsyncWindowContext, Context, DismissEvent, Element, Entity,
|
||||
Focusable, KeyBinding, MenuItem, ParentElement, PathPromptOptions, PromptLevel, ReadGlobal,
|
||||
SharedString, Styled, Task, TitlebarOptions, UpdateGlobal, Window, WindowKind, WindowOptions,
|
||||
actions, point, px,
|
||||
};
|
||||
use image_viewer::ImageInfo;
|
||||
use migrate::{MigrationBanner, MigrationEvent, MigrationNotification, MigrationType};
|
||||
|
@ -56,7 +56,7 @@ use std::any::TypeId;
|
|||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{self, AtomicBool};
|
||||
use std::time::Duration;
|
||||
use std::{borrow::Cow, ops::Deref, path::Path, sync::Arc};
|
||||
use std::{borrow::Cow, path::Path, sync::Arc};
|
||||
use terminal_view::terminal_panel::{self, TerminalPanel};
|
||||
use theme::{ActiveTheme, ThemeSettings};
|
||||
use ui::{PopoverMenuHandle, prelude::*};
|
||||
|
@ -676,7 +676,7 @@ fn register_actions(
|
|||
.register_action(install_cli)
|
||||
.register_action(|_, _: &install_cli::RegisterZedScheme, window, cx| {
|
||||
cx.spawn_in(window, async move |workspace, cx| {
|
||||
register_zed_scheme(&cx).await?;
|
||||
install_cli::register_zed_scheme(&cx).await?;
|
||||
workspace.update_in(cx, |workspace, _, cx| {
|
||||
struct RegisterZedScheme;
|
||||
|
||||
|
@ -980,42 +980,7 @@ fn install_cli(
|
|||
window: &mut Window,
|
||||
cx: &mut Context<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_in(window, async move |workspace, cx| {
|
||||
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_spawn(prompt).detach();
|
||||
return Ok(());
|
||||
}
|
||||
let path = install_cli::install_cli(cx.deref())
|
||||
.await
|
||||
.context("error creating CLI symlink")?;
|
||||
|
||||
workspace.update_in(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", window, cx, |_, _, _| None);
|
||||
install_cli::install_cli(window, cx);
|
||||
}
|
||||
|
||||
static WAITING_QUIT_CONFIRMATION: AtomicBool = AtomicBool::new(false);
|
||||
|
@ -1741,11 +1706,6 @@ fn open_settings_file(
|
|||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
async fn register_zed_scheme(cx: &AsyncApp) -> anyhow::Result<()> {
|
||||
cx.update(|cx| cx.register_url_scheme(ZED_URL_SCHEME))?
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue