logiguard fork v3: full patch set on verified 8c74db0 tree
Includes prior-session patches (carry forward so the app compiles): - crates/gpui/build.rs: cross-compile manifest fix - crates/gpui/src/platform.rs: PlatformWindow::activate_with_token trait method - crates/gpui/src/window.rs: Window::activate_with_token public API - crates/gpui_linux/src/linux/wayland/window.rs: WaylandWindow::activate_with_token + activate() keyboard-serial fix Plus the focus-serial fix: - serial.rs: SerialKind::KeyboardEnter - client.rs: store wl_keyboard.enter serial; latest_serial_of() Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
72
crates/web_search/src/web_search.rs
Normal file
72
crates/web_search/src/web_search.rs
Normal file
@@ -0,0 +1,72 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use cloud_llm_client::WebSearchResponse;
|
||||
use collections::HashMap;
|
||||
use gpui::{App, AppContext as _, Context, Entity, Global, SharedString, Task};
|
||||
|
||||
pub fn init(cx: &mut App) {
|
||||
let registry = cx.new(|_cx| WebSearchRegistry::default());
|
||||
cx.set_global(GlobalWebSearchRegistry(registry));
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Hash, Debug, Ord, PartialOrd)]
|
||||
pub struct WebSearchProviderId(pub SharedString);
|
||||
|
||||
pub trait WebSearchProvider {
|
||||
fn id(&self) -> WebSearchProviderId;
|
||||
fn search(&self, query: String, cx: &mut App) -> Task<Result<WebSearchResponse>>;
|
||||
}
|
||||
|
||||
struct GlobalWebSearchRegistry(Entity<WebSearchRegistry>);
|
||||
|
||||
impl Global for GlobalWebSearchRegistry {}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct WebSearchRegistry {
|
||||
providers: HashMap<WebSearchProviderId, Arc<dyn WebSearchProvider>>,
|
||||
active_provider: Option<Arc<dyn WebSearchProvider>>,
|
||||
}
|
||||
|
||||
impl WebSearchRegistry {
|
||||
pub fn global(cx: &App) -> Entity<Self> {
|
||||
cx.global::<GlobalWebSearchRegistry>().0.clone()
|
||||
}
|
||||
|
||||
pub fn read_global(cx: &App) -> &Self {
|
||||
cx.global::<GlobalWebSearchRegistry>().0.read(cx)
|
||||
}
|
||||
|
||||
pub fn providers(&self) -> impl Iterator<Item = &Arc<dyn WebSearchProvider>> {
|
||||
self.providers.values()
|
||||
}
|
||||
|
||||
pub fn active_provider(&self) -> Option<Arc<dyn WebSearchProvider>> {
|
||||
self.active_provider.clone()
|
||||
}
|
||||
|
||||
pub fn set_active_provider(&mut self, provider: Arc<dyn WebSearchProvider>) {
|
||||
self.active_provider = Some(provider.clone());
|
||||
self.providers.insert(provider.id(), provider);
|
||||
}
|
||||
|
||||
pub fn register_provider<T: WebSearchProvider + 'static>(
|
||||
&mut self,
|
||||
provider: T,
|
||||
_cx: &mut Context<Self>,
|
||||
) {
|
||||
let id = provider.id();
|
||||
let provider = Arc::new(provider);
|
||||
self.providers.insert(id, provider.clone());
|
||||
if self.active_provider.is_none() {
|
||||
self.active_provider = Some(provider);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unregister_provider(&mut self, id: WebSearchProviderId) {
|
||||
self.providers.remove(&id);
|
||||
if self.active_provider.as_ref().map(|provider| provider.id()) == Some(id) {
|
||||
self.active_provider = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user