Move install_cli function to a seperate crate
Add install cli button to welcome experience Add toast pop ups for CLI installation status
This commit is contained in:
@@ -122,6 +122,8 @@ impl Workspace {
|
||||
|
||||
pub mod simple_message_notification {
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use gpui::{
|
||||
actions,
|
||||
elements::{Flex, MouseEventHandler, Padding, ParentElement, Svg, Text},
|
||||
@@ -153,9 +155,9 @@ pub mod simple_message_notification {
|
||||
}
|
||||
|
||||
pub struct MessageNotification {
|
||||
message: String,
|
||||
message: Cow<'static, str>,
|
||||
click_action: Option<Box<dyn Action>>,
|
||||
click_message: Option<String>,
|
||||
click_message: Option<Cow<'static, str>>,
|
||||
}
|
||||
|
||||
pub enum MessageNotificationEvent {
|
||||
@@ -167,23 +169,23 @@ pub mod simple_message_notification {
|
||||
}
|
||||
|
||||
impl MessageNotification {
|
||||
pub fn new_message<S: AsRef<str>>(message: S) -> MessageNotification {
|
||||
pub fn new_message<S: Into<Cow<'static, str>>>(message: S) -> MessageNotification {
|
||||
Self {
|
||||
message: message.as_ref().to_string(),
|
||||
message: message.into(),
|
||||
click_action: None,
|
||||
click_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new<S1: AsRef<str>, A: Action, S2: AsRef<str>>(
|
||||
pub fn new<S1: Into<Cow<'static, str>>, A: Action, S2: Into<Cow<'static, str>>>(
|
||||
message: S1,
|
||||
click_action: A,
|
||||
click_message: S2,
|
||||
) -> Self {
|
||||
Self {
|
||||
message: message.as_ref().to_string(),
|
||||
message: message.into(),
|
||||
click_action: Some(Box::new(click_action) as Box<dyn Action>),
|
||||
click_message: Some(click_message.as_ref().to_string()),
|
||||
click_message: Some(click_message.into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,6 +212,8 @@ pub mod simple_message_notification {
|
||||
let click_message = self.click_message.as_ref().map(|message| message.clone());
|
||||
let message = self.message.clone();
|
||||
|
||||
let has_click_action = click_action.is_some();
|
||||
|
||||
MouseEventHandler::<MessageNotificationTag>::new(0, cx, |state, cx| {
|
||||
Flex::column()
|
||||
.with_child(
|
||||
@@ -243,6 +247,7 @@ pub mod simple_message_notification {
|
||||
.on_click(MouseButton::Left, move |_, cx| {
|
||||
cx.dispatch_action(CancelMessageNotification)
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.aligned()
|
||||
.constrained()
|
||||
.with_height(
|
||||
@@ -272,12 +277,19 @@ pub mod simple_message_notification {
|
||||
.contained()
|
||||
.boxed()
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
// Since we're not using a proper overlay, we have to capture these extra events
|
||||
.on_down(MouseButton::Left, |_, _| {})
|
||||
.on_up(MouseButton::Left, |_, _| {})
|
||||
.on_click(MouseButton::Left, move |_, cx| {
|
||||
if let Some(click_action) = click_action.as_ref() {
|
||||
cx.dispatch_any_action(click_action.boxed_clone())
|
||||
}
|
||||
})
|
||||
.with_cursor_style(if has_click_action {
|
||||
CursorStyle::PointingHand
|
||||
} else {
|
||||
CursorStyle::Arrow
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ mod toolbar;
|
||||
|
||||
pub use smallvec;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::{anyhow, Result, Context};
|
||||
use call::ActiveCall;
|
||||
use client::{
|
||||
proto::{self, PeerId},
|
||||
@@ -65,7 +65,7 @@ use crate::{
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
use log::{error, warn};
|
||||
use notifications::NotificationHandle;
|
||||
use notifications::{NotificationHandle, NotifyResultExt};
|
||||
pub use pane::*;
|
||||
pub use pane_group::*;
|
||||
use persistence::{model::SerializedItem, DB};
|
||||
@@ -267,6 +267,28 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
cx.add_action(|_: &mut Workspace, _: &install_cli::Install, cx| {
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let err = install_cli::install_cli(&cx).await.context("Failed to create CLI symlink");
|
||||
|
||||
cx.update(|cx| {
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
if matches!(err, Err(_)) {
|
||||
err.notify_err(workspace, cx);
|
||||
} else {
|
||||
workspace.show_notification(1, cx, |cx| {
|
||||
cx.add_view(|_| MessageNotification::new_message("Successfully installed the 'zed' binary"))
|
||||
});
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
}).detach();
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
let client = &app_state.client;
|
||||
client.add_view_request_handler(Workspace::handle_follow);
|
||||
|
||||
Reference in New Issue
Block a user