Wire plugin file install command

This commit is contained in:
2026-05-08 21:20:29 -04:00
parent 527762fd36
commit d769b45f54
6 changed files with 113 additions and 20 deletions
@@ -0,0 +1,49 @@
use ely_domain::CommandIntent;
use gpui::{Context, Window};
use super::ElyShell;
impl ElyShell {
pub(super) fn handle_shell_command_intent(
&mut self,
intent: Option<&CommandIntent>,
window: &mut Window,
cx: &mut Context<Self>,
) {
let Some(CommandIntent::Command(command)) = intent else {
return;
};
if install_plugin_from_file_command(command) {
self.choose_plugin_package(window, cx);
}
}
}
fn install_plugin_from_file_command(command: &str) -> bool {
matches!(
command.trim().to_ascii_lowercase().as_str(),
"install-plugin-from-file"
| "install plugin from file"
| "install-plugin"
| "install plugin"
)
}
#[cfg(test)]
mod tests {
use super::install_plugin_from_file_command;
#[test]
fn install_plugin_from_file_command_matches_prd_aliases() {
assert!(install_plugin_from_file_command("install-plugin-from-file"));
assert!(install_plugin_from_file_command("Install Plugin from File"));
assert!(install_plugin_from_file_command("install plugin"));
}
#[test]
fn install_plugin_from_file_command_rejects_other_plugin_commands() {
assert!(!install_plugin_from_file_command("plugins"));
assert!(!install_plugin_from_file_command("open plugins"));
}
}
+15 -16
View File
@@ -1,5 +1,6 @@
mod archive_labels;
mod bookmarks;
mod command_actions;
mod downloads;
mod focus;
mod history;
@@ -25,9 +26,9 @@ mod web_surface_view;
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{
ArchivePolicy, CommandIntent, DownloadPolicy, FavoriteLimit, HistoryRecordingPolicy,
NewTabDestination, ProfileId, ProfileSyncPolicy, SearchEngine, SpaceId, SyncObjectKind,
SyncObjectPolicy, TabId, UrlText,
ArchivePolicy, DownloadPolicy, FavoriteLimit, HistoryRecordingPolicy, NewTabDestination,
ProfileId, ProfileSyncPolicy, SearchEngine, SpaceId, SyncObjectKind, SyncObjectPolicy, TabId,
UrlText,
};
use gpui::{AppContext, Context, Entity, FocusHandle, Subscription, Window};
use gpui_component::input::{InputEvent, InputState, SelectAll};
@@ -53,7 +54,6 @@ pub struct ElyShell {
state: ShellState,
focus_handle: FocusHandle,
command_input: Entity<InputState>,
last_intent: Option<CommandIntent>,
download_action_error: Option<String>,
download_clear_confirmation: bool,
download_security_confirmation: Option<PendingDownloadFileAction>,
@@ -84,21 +84,21 @@ impl ElyShell {
let mut sync_address = false;
let submitted = matches!(event, InputEvent::PressEnter { .. });
let ShellState::Ready(core) = &mut shell.state else {
return;
};
{
let ShellState::Ready(core) = &mut shell.state else {
return;
};
let value = input.read(cx).value().to_string();
core.set_command_query(value);
let value = input.read(cx).value().to_string();
core.set_command_query(value);
if submitted {
submitted_intent = core.submit_command().ok().flatten();
sync_address = core.command_query().is_empty();
if submitted {
submitted_intent = core.submit_command().ok().flatten();
sync_address = core.command_query().is_empty();
}
}
if submitted {
shell.last_intent = submitted_intent;
}
shell.handle_shell_command_intent(submitted_intent.as_ref(), window, cx);
if sync_address {
shell.sync_address_input(window, cx);
@@ -122,7 +122,6 @@ impl ElyShell {
state,
focus_handle: cx.focus_handle(),
command_input,
last_intent: None,
download_action_error: None,
download_clear_confirmation: false,
download_security_confirmation: None,
+19
View File
@@ -10,6 +10,8 @@ use crate::services::{
use super::{ElyShell, ShellState};
const PLUGIN_SETTINGS_URL: &str = "ely://settings/plugins";
#[derive(Clone, Debug)]
pub(super) struct PendingPluginInstall {
package: VerifiedPluginPackage,
@@ -56,6 +58,8 @@ impl PendingPluginUninstall {
impl ElyShell {
pub(super) fn choose_plugin_package(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.ensure_plugin_install_surface(window, cx);
let prompt = cx.prompt_for_paths(PathPromptOptions {
files: false,
directories: true,
@@ -96,6 +100,21 @@ impl ElyShell {
.detach();
}
fn ensure_plugin_install_surface(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if self.active_tab_matches_url(PLUGIN_SETTINGS_URL) {
return;
}
self.open_internal_tab(PLUGIN_SETTINGS_URL, window, cx);
}
fn active_tab_matches_url(&self, url: &str) -> bool {
match &self.state {
ShellState::Ready(core) => core.active_tab().is_ok_and(|tab| tab.url().as_str() == url),
ShellState::StartupError(_) => false,
}
}
pub(super) fn confirm_plugin_install(&mut self, cx: &mut Context<Self>) {
let Some(pending) = self.pending_plugin_install.take() else {
cx.notify();