From 33785f183d3353fc71faeab4029fb0f593305a50 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Tue, 6 Oct 2026 21:04:20 +0700 Subject: [PATCH] chore: bump gpui-pre to 0.3.8 and clean up unused code --- Cargo.lock | 31 - Cargo.toml | 25 +- crates/assets/Cargo.toml | 1 - crates/assets/src/lib.rs | 21 +- crates/auto_update/src/lib.rs | 20 - crates/browser-signer-proxy/src/lib.rs | 80 +- crates/chat/src/lib.rs | 44 +- crates/chat/src/message.rs | 17 +- crates/chat/src/room.rs | 16 +- crates/chat_ui/Cargo.toml | 1 - crates/chat_ui/src/lib.rs | 2 - crates/common/Cargo.toml | 2 - crates/common/src/debounced_delay.rs | 16 +- crates/common/src/display.rs | 28 +- crates/common/src/lib.rs | 2 - crates/common/src/media_extractor.rs | 66 +- crates/common/src/parser.rs | 12 +- crates/common/src/paths.rs | 29 +- crates/common/src/range.rs | 45 - crates/gpui_tokio/src/lib.rs | 22 +- crates/nip29/Cargo.toml | 4 - crates/nip29/src/group.rs | 97 +- crates/nip29/src/lib.rs | 2 +- crates/nip29/src/protocol.rs | 160 +- crates/nip29_ui/src/lib.rs | 2 +- crates/nip4e/Cargo.toml | 2 - crates/nip4e/src/lib.rs | 8 +- crates/person/src/person.rs | 16 +- crates/settings/src/lib.rs | 62 +- crates/state/Cargo.toml | 1 - crates/state/src/constants.rs | 21 +- crates/state/src/file.rs | 71 +- crates/state/src/lib.rs | 73 +- crates/state/src/nip4e.rs | 7 - crates/state/src/signer.rs | 10 +- crates/theme/Cargo.toml | 1 - crates/theme/src/colors.rs | 1909 +----------------------- crates/theme/src/geometry.rs | 100 +- crates/theme/src/lib.rs | 8 +- crates/theme/src/platform_kind.rs | 12 - crates/theme/src/scale.rs | 116 +- crates/theme/src/scrollbar_mode.rs | 8 - crates/theme/src/theme.rs | 2 +- crates/ui/Cargo.toml | 2 - crates/ui/src/avatar.rs | 12 - crates/ui/src/button.rs | 20 - crates/ui/src/dialog.rs | 35 - crates/ui/src/group_box.rs | 43 +- crates/ui/src/icon.rs | 35 +- crates/ui/src/indicator.rs | 12 +- crates/ui/src/input/input.rs | 26 +- crates/ui/src/menu/menu_item.rs | 3 +- crates/ui/src/menu/popup_menu.rs | 168 +-- crates/ui/src/notification.rs | 31 - crates/ui/src/scroll/scrollable.rs | 17 - crates/ui/src/switch.rs | 5 - crates/ui/src/tab/tab_bar.rs | 50 +- crates/ui/src/window_ext.rs | 12 +- crates/workspace/Cargo.toml | 1 - crates/workspace/src/sidebar/header.rs | 31 +- desktop/Cargo.toml | 1 - web/Cargo.toml | 2 - 62 files changed, 162 insertions(+), 3516 deletions(-) delete mode 100644 crates/common/src/range.rs diff --git a/Cargo.lock b/Cargo.lock index c897cc82..e525bb86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,7 +271,6 @@ version = "1.0.2" dependencies = [ "anyhow", "gpui-pre", - "log", "rust-embed", ] @@ -1089,7 +1088,6 @@ dependencies = [ "common", "gpui-pre", "itertools 0.13.0", - "log", "nostr-sdk", "person", "regex", @@ -1259,10 +1257,8 @@ dependencies = [ "gpui-pre", "instant", "itertools 0.13.0", - "log", "nostr", "nostr-sdk", - "qrcode", "regex", ] @@ -1403,7 +1399,6 @@ dependencies = [ "assets", "auto_update", "chat", - "common", "gpui-pre", "gpui-pre-linux", "gpui-pre-macos", @@ -1427,9 +1422,7 @@ dependencies = [ name = "coop_web" version = "1.0.2" dependencies = [ - "assets", "chat", - "common", "console_error_panic_hook", "console_log", "getrandom 0.2.17", @@ -4524,12 +4517,9 @@ dependencies = [ "anyhow", "chat", "flume 0.11.1", - "futures", "gpui-pre", "log", - "nostr", "nostr-sdk", - "serde_json", "smallvec", "state", ] @@ -4560,10 +4550,8 @@ name = "nip4e" version = "1.0.2" dependencies = [ "anyhow", - "common", "flume 0.11.1", "gpui-pre", - "instant", "log", "nostr-sdk", "person", @@ -5863,15 +5851,6 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "qrcode" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec" -dependencies = [ - "image", -] - [[package]] name = "quick-error" version = "2.0.1" @@ -7094,7 +7073,6 @@ dependencies = [ "gpui-pre", "gpui_tokio", "instant", - "log", "mime_guess", "nostr", "nostr-blossom", @@ -7463,7 +7441,6 @@ dependencies = [ "schemars", "serde", "serde_json", - "smallvec", "tempfile", ] @@ -7977,11 +7954,9 @@ dependencies = [ name = "ui" version = "1.0.2" dependencies = [ - "common", "gpui-base", "gpui-pre", "instant", - "log", "serde", "smallvec", "theme", @@ -9431,7 +9406,6 @@ version = "1.0.2" dependencies = [ "anyhow", "auto_update", - "browser-signer-proxy", "chat", "chat_ui", "common", @@ -9955,8 +9929,3 @@ dependencies = [ "syn 3.0.6", "winnow 1.0.4", ] - -[[patch.unused]] -name = "psm" -version = "0.1.32" -source = "git+https://github.com/rust-lang/stacker?branch=master#d3ac2df79a409c681329006e9b31c96ab9c5fcae" diff --git a/Cargo.toml b/Cargo.toml index 3e25c387..dafaa015 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,17 +9,16 @@ edition = "2024" publish = false [workspace.dependencies] -gpui = { package = "gpui-pre", version = "0.3.5" } -gpui_platform = { package = "gpui-pre-platform", version = "0.3.5", features = ["font-kit", "x11", "wayland"] } -gpui_linux = { package = "gpui-pre-linux", version = "0.3.5" } -gpui_windows = { package = "gpui-pre-windows", version = "0.3.5" } -gpui_macos = { package = "gpui-pre-macos", version = "0.3.5" } -gpui_web = { package = "gpui-pre-web", version = "0.3.5" } -gpui_util = { package = "gpui-pre-util", version = "0.3.5" } -sum_tree = { package = "gpui-pre-sum-tree", version = "0.3.5" } -reqwest_client = { package = "gpui-pre-reqwest-client", version = "0.3.5" } +gpui = { package = "gpui-pre", version = "0.3.8" } +gpui_platform = { package = "gpui-pre-platform", version = "0.3.8", features = ["font-kit", "x11", "wayland"] } +gpui_linux = { package = "gpui-pre-linux", version = "0.3.8" } +gpui_windows = { package = "gpui-pre-windows", version = "0.3.8" } +gpui_macos = { package = "gpui-pre-macos", version = "0.3.8" } +gpui_web = { package = "gpui-pre-web", version = "0.3.8" } +gpui_util = { package = "gpui-pre-util", version = "0.3.8" } +reqwest_client = { package = "gpui-pre-reqwest-client", version = "0.3.8" } gpui_tokio = { path = "crates/gpui_tokio" } -gpui-base = "0.7.0" +gpui-base = "0.7.1" # Nostr nostr-lmdb = { git = "https://github.com/rust-nostr/nostr" } @@ -48,7 +47,6 @@ chrono = { version = "0.4.38", features = ["wasmbind"] } futures = "0.3" itertools = "0.13.0" log = "0.4" -oneshot = "0.1.10" flume = { version = "0.11.1", default-features = false, features = ["async", "select"] } rust-embed = { version = "8.5", features = ["include-exclude"] } serde = { version = "1.0", features = ["derive"] } @@ -58,14 +56,9 @@ smallvec = "1.14.0" smol = "2" webbrowser = "1.0.4" tracing-subscriber = { version = "0.3.18", features = ["fmt"] } -errno = { version = "0.3.14", default-features = false } instant = "0.1" ureq = { version = "3", default-features = false, features = ["rustls", "platform-verifier", "json"] } -[patch.crates-io] -# Use stacker's psm version which may have better WASM support -psm = { git = "https://github.com/rust-lang/stacker", branch = "master" } - [profile.release] strip = true opt-level = "z" diff --git a/crates/assets/Cargo.toml b/crates/assets/Cargo.toml index 3e3d11fd..2d89f8a8 100644 --- a/crates/assets/Cargo.toml +++ b/crates/assets/Cargo.toml @@ -7,5 +7,4 @@ publish.workspace = true [dependencies] gpui.workspace = true anyhow.workspace = true -log.workspace = true rust-embed.workspace = true diff --git a/crates/assets/src/lib.rs b/crates/assets/src/lib.rs index 8229e2af..a1f9b9ee 100644 --- a/crates/assets/src/lib.rs +++ b/crates/assets/src/lib.rs @@ -1,5 +1,5 @@ use anyhow::Context; -use gpui::{App, AssetSource, Result, SharedString}; +use gpui::{AssetSource, Result, SharedString}; use rust_embed::RustEmbed; #[derive(RustEmbed)] @@ -30,22 +30,3 @@ impl AssetSource for Assets { .collect()) } } - -impl Assets { - /// Populate the [`TextSystem`] of the given [`AppContext`] with all `.ttf` fonts in the `fonts` directory. - pub fn load_fonts(&self, cx: &App) -> anyhow::Result<()> { - let font_paths = self.list("fonts")?; - let mut embedded_fonts = Vec::new(); - for font_path in font_paths { - if font_path.ends_with(".ttf") { - let font_bytes = cx - .asset_source() - .load(&font_path)? - .expect("Assets should never return None"); - embedded_fonts.push(font_bytes); - } - } - - cx.text_system().add_fonts(embedded_fonts) - } -} diff --git a/crates/auto_update/src/lib.rs b/crates/auto_update/src/lib.rs index bf094871..1f6e0997 100644 --- a/crates/auto_update/src/lib.rs +++ b/crates/auto_update/src/lib.rs @@ -11,8 +11,6 @@ use crate::source::{AssetFilter, GiteaSource, asset_filter_for}; mod source; -pub use gpui_updater_core::UpdateStatus as AutoUpdateStatus; - const GITEA_API_BASE: &str = "https://git.reya.info/api/v1"; const GITEA_REPO_OWNER: &str = "reya"; const GITEA_REPO_NAME: &str = "coop"; @@ -73,29 +71,17 @@ pub struct AutoUpdater { status: UpdateStatus, /// The newer release found by the last successful check, if any. available: Option, - /// Currently running app version. - pub version: Version, /// The in-flight check or download, if any. task: Option>, } impl AutoUpdater { - /// Whether auto-update is available for this installation. - pub fn is_available(cx: &App) -> bool { - cx.try_global::().is_some() - } - /// Retrieve the global auto updater instance, if one was initialized. pub fn try_global(cx: &App) -> Option> { cx.try_global::() .map(|global| global.0.clone()) } - /// Retrieve the global auto updater instance. - pub fn global(cx: &App) -> Entity { - cx.global::().0.clone() - } - fn set_global(state: Entity, cx: &mut App) { cx.set_global(GlobalAutoUpdater(state)); } @@ -119,16 +105,10 @@ impl AutoUpdater { engine, status: UpdateStatus::Idle, available: None, - version, task: None, } } - /// Whether nothing is happening, so the UI can hide the status line. - pub fn idle(&self) -> bool { - matches!(self.status, UpdateStatus::Idle) - } - /// Whether the running version is the newest release, so the status line can be hidden. pub fn up_to_date(&self) -> bool { matches!(self.status, UpdateStatus::Idle | UpdateStatus::UpToDate) diff --git a/crates/browser-signer-proxy/src/lib.rs b/crates/browser-signer-proxy/src/lib.rs index 0da268a5..6617db1b 100644 --- a/crates/browser-signer-proxy/src/lib.rs +++ b/crates/browser-signer-proxy/src/lib.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; use std::future::Future; -use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}; +use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use std::pin::Pin; use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; @@ -49,8 +49,6 @@ impl Message { enum RequestMethod { GetPublicKey, SignEvent, - Nip04Encrypt, - Nip04Decrypt, Nip44Encrypt, Nip44Decrypt, } @@ -60,8 +58,6 @@ impl RequestMethod { match self { Self::GetPublicKey => "get_public_key", Self::SignEvent => "sign_event", - Self::Nip04Encrypt => "nip04_encrypt", - Self::Nip04Decrypt => "nip04_decrypt", Self::Nip44Encrypt => "nip44_encrypt", Self::Nip44Decrypt => "nip44_decrypt", } @@ -205,36 +201,6 @@ impl Default for BrowserSignerProxyOptions { } } -impl BrowserSignerProxyOptions { - /// Sets the timeout duration. - pub const fn timeout(mut self, timeout: Duration) -> Self { - self.timeout = timeout; - self - } - - /// Sets the IP address. - pub const fn ip_addr(mut self, new_ip: IpAddr) -> Self { - self.addr = SocketAddr::new(new_ip, self.addr.port()); - self - } - - /// Sets the port number. - pub const fn port(mut self, new_port: u16) -> Self { - self.addr = SocketAddr::new(self.addr.ip(), new_port); - self - } - - /// Sets a custom html page. - /// - /// The page must include `/proxy.js` script (``) - /// which will handle communication with the server and update the element - /// with id `nip07-proxy-status` with the status. - pub const fn custom_html_page(mut self, custom_html: &'static str) -> Self { - self.custom_html = custom_html; - self - } -} - impl BrowserSignerProxy { /// Construct a new browser signer proxy pub fn new(options: BrowserSignerProxyOptions) -> Self { @@ -255,14 +221,8 @@ impl BrowserSignerProxy { } } - /// Indicates whether the server is currently running. - #[inline] - pub fn is_started(&self) -> bool { - self.inner.is_started.load(Ordering::SeqCst) - } - - /// Checks if there is an open browser tab ready to respond to requests by - /// verifying the time since the last pending request. + /// Checks if there is an open browser tab ready to respond + /// to requests by verifying the time since the last pending request. #[inline] pub fn is_session_active(&self) -> bool { current_time() - self.inner.state.last_pending_request.load(Ordering::SeqCst) < 2 @@ -419,20 +379,6 @@ impl BrowserSignerProxy { Ok(event) } - #[inline] - async fn _nip04_encrypt(&self, public_key: &PublicKey, content: &str) -> Result { - let params = CryptoParams::new(public_key, content); - self.request(RequestMethod::Nip04Encrypt, serde_json::to_value(params)?) - .await - } - - #[inline] - async fn _nip04_decrypt(&self, public_key: &PublicKey, content: &str) -> Result { - let params = CryptoParams::new(public_key, content); - self.request(RequestMethod::Nip04Decrypt, serde_json::to_value(params)?) - .await - } - #[inline] async fn _nip44_encrypt(&self, public_key: &PublicKey, content: &str) -> Result { let params = CryptoParams::new(public_key, content); @@ -471,26 +417,6 @@ impl AsyncSignEvent for BrowserSignerProxy { } } -impl AsyncNip04 for BrowserSignerProxy { - type Error = Error; - - fn nip04_encrypt_async<'a>( - &'a self, - public_key: &'a PublicKey, - content: &'a str, - ) -> Pin> + Send + 'a>> { - Box::pin(async move { self._nip04_encrypt(public_key, content).await }) - } - - fn nip04_decrypt_async<'a>( - &'a self, - public_key: &'a PublicKey, - encrypted_content: &'a str, - ) -> Pin> + Send + 'a>> { - Box::pin(async move { self._nip04_decrypt(public_key, encrypted_content).await }) - } -} - impl AsyncNip44 for BrowserSignerProxy { type Error = Error; diff --git a/crates/chat/src/lib.rs b/crates/chat/src/lib.rs index c76c65dd..77725881 100644 --- a/crates/chat/src/lib.rs +++ b/crates/chat/src/lib.rs @@ -101,7 +101,6 @@ pub struct ChatRegistry { /// Signal consumer task (cancelled on signer change) signal_consumer: Option>>, /// Fuzzy matcher for room search (cached; intentionally excluded from Debug) - #[allow(dead_code)] matcher: CachedMatcher, /// Subscriptions _subscriptions: SmallVec<[Subscription; 2]>, @@ -549,26 +548,6 @@ impl ChatRegistry { .count() } - /// Count the number of messages seen by a given relay. - pub fn count_messages(&self, relay_url: &RelayUrl) -> usize { - self.seen - .read() - .unwrap() - .values() - .filter(|s| s.contains(relay_url)) - .count() - } - - /// Count the number of trash messages. - pub fn count_trash_messages(&self, cx: &App) -> usize { - self.trash.read(cx).len() - } - - /// Get the trash messages entity. - pub fn trash(&self) -> Entity> { - self.trash.clone() - } - /// Get the relays that have seen a given rumor id. pub fn rumor_seen_on(&self, id: &EventId) -> Option> { self.event_map @@ -579,7 +558,7 @@ impl ChatRegistry { } /// Get the relays that have seen a given gift wrap id. - pub fn seen_on(&self, id: &EventId) -> HashSet { + pub(crate) fn seen_on(&self, id: &EventId) -> HashSet { self.seen .read() .unwrap() @@ -589,7 +568,7 @@ impl ChatRegistry { } /// Add a new room to the start of list. - pub fn add_room(&mut self, room: I, cx: &mut Context) + pub(crate) fn add_room(&mut self, room: I, cx: &mut Context) where I: Into, { @@ -623,7 +602,7 @@ impl ChatRegistry { } /// Sort rooms by their created at. Only notifies if order changed. - pub fn sort(&mut self, cx: &mut Context) { + pub(crate) fn sort(&mut self, cx: &mut Context) { let before: Vec<_> = self.rooms.iter().map(|ev| ev.read(cx).id).collect(); self.rooms.sort_by_key(|ev| Reverse(ev.read(cx).created_at)); let after: Vec<_> = self.rooms.iter().map(|ev| ev.read(cx).id).collect(); @@ -659,7 +638,7 @@ impl ChatRegistry { } /// Reset the registry. - pub fn reset(&mut self, cx: &mut Context) { + pub(crate) fn reset(&mut self, cx: &mut Context) { self.rooms.clear(); self.room_index.clear(); self.search.write().unwrap().clear(); @@ -701,7 +680,7 @@ impl ChatRegistry { } /// Load all rooms from the database. - pub fn get_rooms(&mut self, cx: &mut Context) { + pub(crate) fn get_rooms(&mut self, cx: &mut Context) { let task = self.query_chat_rooms(cx); self.tasks.push(cx.spawn(async move |this, cx| { @@ -796,7 +775,7 @@ impl ChatRegistry { /// /// - If the room doesn't exist, it will be created. /// - Updates room ordering based on the most recent messages. - pub fn new_message(&mut self, message: NewMessage, cx: &mut Context) { + pub(crate) fn new_message(&mut self, message: NewMessage, cx: &mut Context) { self.search.write().unwrap().insert(&message.rumor); let nostr = NostrRegistry::global(cx); @@ -821,17 +800,6 @@ impl ChatRegistry { } } } - - /// Trigger a refresh of the opened chat rooms by their IDs - pub fn refresh_rooms(&mut self, ids: &[u64], cx: &mut Context) { - for room in self.rooms.iter() { - if ids.contains(&room.read(cx).id) { - room.update(cx, |this, cx| { - this.emit_refresh(cx); - }); - } - } - } } /// Unwraps a gift-wrapped event and processes its contents. diff --git a/crates/chat/src/message.rs b/crates/chat/src/message.rs index afe0ea22..72ebb3e9 100644 --- a/crates/chat/src/message.rs +++ b/crates/chat/src/message.rs @@ -6,7 +6,7 @@ use gpui::{SharedString, SharedUri}; use nostr_sdk::prelude::*; use state::FileAttachment; -pub const KIND_FILE_MESSAGE: Kind = Kind::Custom(15); +pub(crate) const KIND_FILE_MESSAGE: Kind = Kind::Custom(15); /// Rendered message. #[derive(Debug, Clone)] @@ -152,31 +152,26 @@ impl Message { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct NewMessage { pub room: u64, - pub gift_wrap: EventId, pub rumor: UnsignedEvent, } impl NewMessage { - pub fn new(gift_wrap: EventId, rumor: UnsignedEvent) -> Self { + pub fn new(_gift_wrap: EventId, rumor: UnsignedEvent) -> Self { let room = rumor.uniq_id(); - Self { - room, - gift_wrap, - rumor, - } + Self { room, rumor } } } /// Trash message. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] -pub struct FailedMessage { +pub(crate) struct FailedMessage { pub raw_event: SharedString, pub reason: SharedString, } impl FailedMessage { - pub fn new(event: &Event, reason: T) -> Self + pub(crate) fn new(event: &Event, reason: T) -> Self where T: Into, { @@ -194,7 +189,7 @@ pub struct Mention { } impl Mention { - pub fn new(public_key: PublicKey, range: Range) -> Self { + pub(crate) fn new(public_key: PublicKey, range: Range) -> Self { Self { public_key, range } } } diff --git a/crates/chat/src/room.rs b/crates/chat/src/room.rs index 691d8c29..cecf1984 100644 --- a/crates/chat/src/room.rs +++ b/crates/chat/src/room.rs @@ -78,7 +78,7 @@ pub struct Room { pub created_at: Timestamp, /// Subject of the room - pub subject: Option, + pub(crate) subject: Option, /// All members of the room pub(super) members: Vec, @@ -186,13 +186,16 @@ impl Room { } /// Sets this room is ongoing conversation - pub fn set_ongoing(&mut self, cx: &mut Context) { + pub(crate) fn set_ongoing(&mut self, cx: &mut Context) { self.kind = RoomKind::Ongoing; cx.notify(); } /// Updates the creation timestamp of the room - pub fn set_created_at(&mut self, created_at: impl Into, cx: &mut Context) { + pub(crate) fn set_created_at(&mut self, created_at: T, cx: &mut Context) + where + T: Into, + { self.created_at = created_at.into(); cx.notify(); } @@ -297,7 +300,7 @@ impl Room { } /// Push a new message to the current room - pub fn push_message(&mut self, message: NewMessage, cx: &mut Context) { + pub(crate) fn push_message(&mut self, message: NewMessage, cx: &mut Context) { let created_at = message.rumor.created_at; let new_message = created_at > self.created_at; @@ -309,11 +312,6 @@ impl Room { } } - /// Emits a signal to reload the current room's messages. - pub fn emit_refresh(&mut self, cx: &mut Context) { - cx.emit(RoomEvent::Reload); - } - /// Get gossip relays for each member pub fn connect(&self, cx: &App) -> Task> { let nostr = NostrRegistry::global(cx); diff --git a/crates/chat_ui/Cargo.toml b/crates/chat_ui/Cargo.toml index fa820e42..193b0aaa 100644 --- a/crates/chat_ui/Cargo.toml +++ b/crates/chat_ui/Cargo.toml @@ -18,7 +18,6 @@ nostr-sdk.workspace = true anyhow.workspace = true itertools.workspace = true smallvec.workspace = true -log.workspace = true serde.workspace = true regex = "1" diff --git a/crates/chat_ui/src/lib.rs b/crates/chat_ui/src/lib.rs index 1421c581..cbde582f 100644 --- a/crates/chat_ui/src/lib.rs +++ b/crates/chat_ui/src/lib.rs @@ -243,8 +243,6 @@ impl ChatPanel { } } RoomEvent::Reload => { - // Defer to avoid re-entrant read on Room while - // emit_refresh holds a write lock (via refresh_rooms). cx.defer_in(window, |this, window, cx| { this.get_messages(window, cx); }); diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 4c8c198a..af857673 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -13,8 +13,6 @@ nostr-sdk.workspace = true itertools.workspace = true chrono.workspace = true futures.workspace = true -log.workspace = true dirs = "5.0" -qrcode = "0.14.1" regex = "1.10" diff --git a/crates/common/src/debounced_delay.rs b/crates/common/src/debounced_delay.rs index 17e1c226..d7a6f6d3 100644 --- a/crates/common/src/debounced_delay.rs +++ b/crates/common/src/debounced_delay.rs @@ -1,9 +1,9 @@ use std::marker::PhantomData; -use instant::Duration; -use futures::channel::oneshot; use futures::FutureExt; +use futures::channel::oneshot; use gpui::{Context, Task, Window}; +use instant::Duration; pub struct DebouncedDelay { task: Option>, @@ -11,12 +11,6 @@ pub struct DebouncedDelay { _phantom_data: PhantomData, } -impl Default for DebouncedDelay { - fn default() -> Self { - Self::new() - } -} - impl DebouncedDelay { pub fn new() -> Self { Self { @@ -64,3 +58,9 @@ impl DebouncedDelay { })); } } + +impl Default for DebouncedDelay { + fn default() -> Self { + Self::new() + } +} diff --git a/crates/common/src/display.rs b/crates/common/src/display.rs index a288168f..c38411d3 100644 --- a/crates/common/src/display.rs +++ b/crates/common/src/display.rs @@ -1,10 +1,6 @@ -use std::sync::Arc; - use chrono::{Local, TimeZone}; -use gpui::{Image, ImageFormat, SharedString}; +use gpui::SharedString; use nostr_sdk::prelude::*; -use qrcode::QrCode; -use qrcode::render::svg; const NOW: &str = "now"; const SECONDS_IN_MINUTE: i64 = 60; @@ -59,25 +55,3 @@ impl TimestampExt for Timestamp { } } } - -pub trait StringExt { - fn to_qr(&self) -> Option>; -} - -impl> StringExt for T { - fn to_qr(&self) -> Option> { - let s = self.as_ref(); - let code = QrCode::new(s).unwrap(); - let svg = code - .render() - .min_dimensions(256, 256) - .dark_color(svg::Color("#000000")) - .light_color(svg::Color("#FFFFFF")) - .build(); - - Some(Arc::new(Image::from_bytes( - ImageFormat::Svg, - svg.into_bytes(), - ))) - } -} diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 7d7720e3..265f3e21 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -4,7 +4,6 @@ pub use event::*; pub use media_extractor::*; pub use parser::*; pub use paths::*; -pub use range::*; mod debounced_delay; mod display; @@ -12,4 +11,3 @@ mod event; mod media_extractor; mod parser; mod paths; -mod range; diff --git a/crates/common/src/media_extractor.rs b/crates/common/src/media_extractor.rs index 8f7dee8d..c688b3f8 100644 --- a/crates/common/src/media_extractor.rs +++ b/crates/common/src/media_extractor.rs @@ -1,30 +1,25 @@ use gpui::SharedUri; use regex::Regex; -/// Extracts media URLs from a string and returns both the extracted URLs -/// and the string with media URLs removed -pub struct MediaExtractor { +/// Extracts media URLs from a string and returns both +/// the extracted URLs and the string with media URLs removed +struct MediaExtractor { image_regex: Regex, - video_regex: Regex, } impl MediaExtractor { /// Creates a new MediaExtractor with compiled regex patterns - pub fn new() -> Self { + fn new() -> Self { MediaExtractor { // Match common image extensions image_regex: Regex::new( r#"(?i)\bhttps?://[^\s<>"']+\.(?:jpg|jpeg|png|gif|bmp|webp|svg|ico)(?:\?[^\s<>"']*)?\b"#, ).unwrap(), - // Match common video extensions - video_regex: Regex::new( - r#"(?i)\bhttps?://[^\s<>"']+\.(?:mp4|mov|avi|mkv|webm|flv|wmv|m4v|3gp)(?:\?[^\s<>"']*)?\b"#, - ).unwrap(), } } /// Extracts all media URLs from a string - pub fn extract_media_urls(&self, text: &str) -> Vec { + fn extract_media_urls(&self, text: &str) -> Vec { let mut urls = Vec::new(); // Extract image URLs @@ -32,30 +27,22 @@ impl MediaExtractor { urls.push(capture.as_str().to_string().into()); } - // Extract video URLs - // for capture in self.video_regex.find_iter(text) { - // urls.push(capture.as_str().to_string().into()); - // } - urls } /// Removes all media URLs from a string and returns the cleaned text - pub fn remove_media_urls(&self, text: &str) -> String { + fn remove_media_urls(&self, text: &str) -> String { let mut result = text.to_string(); // Remove image URLs result = self.image_regex.replace_all(&result, "").to_string(); - // Remove video URLs - // result = self.video_regex.replace_all(&result, "").to_string(); - // Clean up extra whitespace that might result from removal self.cleanup_text(&result) } /// Extracts media URLs and removes them from the string, returning both - pub fn extract_and_remove(&self, text: &str) -> (Vec, String) { + fn extract_and_remove(&self, text: &str) -> (Vec, String) { let urls = self.extract_media_urls(text); let cleaned_text = self.remove_media_urls(text); (urls, cleaned_text) @@ -69,33 +56,6 @@ impl MediaExtractor { let re = Regex::new(r"\s+").unwrap(); re.replace_all(text, " ").trim().to_string() } - - /// Validates if a URL is a valid media URL - pub fn is_media_url(&self, url: &str) -> bool { - self.image_regex.is_match(url) || self.video_regex.is_match(url) - } - - /// Categorizes extracted URLs into images and videos - pub fn categorize_urls(&self, urls: &[SharedUri]) -> (Vec, Vec) { - let mut images = Vec::new(); - let mut videos = Vec::new(); - - for url in urls { - if self.image_regex.is_match(url) { - images.push(url.clone()); - } else if self.video_regex.is_match(url) { - videos.push(url.clone()); - } - } - - (images, videos) - } -} - -impl Default for MediaExtractor { - fn default() -> Self { - Self::new() - } } /// Convenience function for one-time extraction and removal @@ -103,15 +63,3 @@ pub fn extract_and_remove_media_urls(text: &str) -> (Vec, String) { let extractor = MediaExtractor::new(); extractor.extract_and_remove(text) } - -/// Convenience function for just extracting media URLs -pub fn extract_media_urls(text: &str) -> Vec { - let extractor = MediaExtractor::new(); - extractor.extract_media_urls(text) -} - -/// Convenience function for just removing media URLs -pub fn remove_media_urls(text: &str) -> String { - let extractor = MediaExtractor::new(); - extractor.remove_media_urls(text) -} diff --git a/crates/common/src/parser.rs b/crates/common/src/parser.rs index c14bb9eb..0886654a 100644 --- a/crates/common/src/parser.rs +++ b/crates/common/src/parser.rs @@ -26,12 +26,6 @@ struct Match { #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct NostrParser; -impl Default for NostrParser { - fn default() -> Self { - Self::new() - } -} - impl NostrParser { /// Create new parser pub const fn new() -> Self { @@ -44,6 +38,12 @@ impl NostrParser { } } +impl Default for NostrParser { + fn default() -> Self { + Self::new() + } +} + struct FindMatches<'a> { bytes: &'a [u8], pos: usize, diff --git a/crates/common/src/paths.rs b/crates/common/src/paths.rs index 1f23e62c..ba00e87b 100644 --- a/crates/common/src/paths.rs +++ b/crates/common/src/paths.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use std::sync::OnceLock; /// Returns the path to the user's home directory. -pub fn home_dir() -> &'static PathBuf { +fn home_dir() -> &'static PathBuf { static HOME_DIR: OnceLock = OnceLock::new(); HOME_DIR.get_or_init(|| dirs::home_dir().expect("failed to determine home directory")) } @@ -36,30 +36,3 @@ pub fn config_dir() -> &'static PathBuf { home_dir().join(".config").join("coop") }) } - -/// Returns the path to the support directory used by Coop. -pub fn support_dir() -> &'static PathBuf { - static SUPPORT_DIR: OnceLock = OnceLock::new(); - SUPPORT_DIR.get_or_init(|| { - if cfg!(target_os = "macos") { - return home_dir().join("Library/Application Support/Coop"); - } - - if cfg!(any(target_os = "linux", target_os = "freebsd")) { - return if let Ok(flatpak_xdg_data) = std::env::var("FLATPAK_XDG_DATA_HOME") { - flatpak_xdg_data.into() - } else { - dirs::data_local_dir().expect("failed to determine XDG_DATA_HOME directory") - } - .join("coop"); - } - - if cfg!(target_os = "windows") { - return dirs::data_local_dir() - .expect("failed to determine LocalAppData directory") - .join("coop"); - } - - config_dir().clone() - }) -} diff --git a/crates/common/src/range.rs b/crates/common/src/range.rs deleted file mode 100644 index d0692e46..00000000 --- a/crates/common/src/range.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::cmp::{self}; -use std::ops::{Range, RangeInclusive}; - -pub trait RangeExt { - fn sorted(&self) -> Self; - fn to_inclusive(&self) -> RangeInclusive; - fn overlaps(&self, other: &Range) -> bool; - fn contains_inclusive(&self, other: &Range) -> bool; -} - -impl RangeExt for Range { - fn sorted(&self) -> Self { - cmp::min(&self.start, &self.end).clone()..cmp::max(&self.start, &self.end).clone() - } - - fn to_inclusive(&self) -> RangeInclusive { - self.start.clone()..=self.end.clone() - } - - fn overlaps(&self, other: &Range) -> bool { - self.start < other.end && other.start < self.end - } - - fn contains_inclusive(&self, other: &Range) -> bool { - self.start <= other.start && other.end <= self.end - } -} - -impl RangeExt for RangeInclusive { - fn sorted(&self) -> Self { - cmp::min(self.start(), self.end()).clone()..=cmp::max(self.start(), self.end()).clone() - } - - fn to_inclusive(&self) -> RangeInclusive { - self.clone() - } - - fn overlaps(&self, other: &Range) -> bool { - self.start() < &other.end && &other.start <= self.end() - } - - fn contains_inclusive(&self, other: &Range) -> bool { - self.start() <= &other.start && &other.end <= self.end() - } -} diff --git a/crates/gpui_tokio/src/lib.rs b/crates/gpui_tokio/src/lib.rs index 7c2fff3f..6a72551b 100644 --- a/crates/gpui_tokio/src/lib.rs +++ b/crates/gpui_tokio/src/lib.rs @@ -1,16 +1,10 @@ -//! Vendored from zed's `crates/gpui_tokio` (Apache-2.0) because the `gpui-pre` family -//! does not republish it, and `nostr-sdk`'s reqwest client needs a Tokio runtime. - use std::future::Future; -use gpui::{App, AppContext, Global, ReadGlobal, Task}; +use gpui::{App, AppContext, Global, Task}; use gpui_util::defer; -pub use tokio::task::JoinError; +use tokio::task::JoinError; /// Initializes the Tokio wrapper using a new Tokio runtime with 2 worker threads. -/// -/// If you need more threads (or access to the runtime outside of GPUI), you can create the runtime -/// yourself and pass a Handle to `init_from_handle`. pub fn init(cx: &mut App) { let runtime = tokio::runtime::Builder::new_multi_thread() // Since we now have two executors, let's try to keep our footprint small @@ -26,14 +20,6 @@ pub fn init(cx: &mut App) { }); } -/// Initializes the Tokio wrapper using a Tokio runtime handle. -pub fn init_from_handle(cx: &mut App, handle: tokio::runtime::Handle) { - cx.set_global(GlobalTokio { - owned_runtime: None, - handle, - }); -} - struct GlobalTokio { owned_runtime: Option, handle: tokio::runtime::Handle, @@ -95,8 +81,4 @@ impl Tokio { }) }) } - - pub fn handle(cx: &App) -> tokio::runtime::Handle { - GlobalTokio::global(cx).handle.clone() - } } diff --git a/crates/nip29/Cargo.toml b/crates/nip29/Cargo.toml index 05fbb7c1..ba605cc0 100644 --- a/crates/nip29/Cargo.toml +++ b/crates/nip29/Cargo.toml @@ -5,12 +5,8 @@ edition.workspace = true publish.workspace = true [dependencies] -nostr.workspace = true nostr-sdk.workspace = true anyhow.workspace = true -futures.workspace = true -serde_json.workspace = true - state = { path = "../state" } chat = { path = "../chat" } diff --git a/crates/nip29/src/group.rs b/crates/nip29/src/group.rs index 3775d64d..032fe68e 100644 --- a/crates/nip29/src/group.rs +++ b/crates/nip29/src/group.rs @@ -3,10 +3,7 @@ use std::time::Duration; use anyhow::{Result, anyhow, bail}; use chat::Message; -use futures::io::AsyncReadExt; -use gpui::http_client::{AsyncBody, Builder, HttpRequestExt, Method, RedirectPolicy, StatusCode}; use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task}; -use nostr::nips::nip98::{HttpData, HttpMethod}; use nostr_sdk::prelude::*; use smallvec::{SmallVec, smallvec}; use state::NostrRegistry; @@ -14,14 +11,13 @@ use state::NostrRegistry; use crate::LOCAL_KEYS; use crate::protocol::{ ACTIVITY_KINDS, Activity, GroupAdmins, GroupId, GroupKey, GroupMembers, GroupMetadata, - GroupParticipants, GroupPins, GroupRoles, LivekitSession, MEMBERSHIP_KINDS, Membership, - PIN_LIST, Pin, RENDER_KINDS, STATE_KINDS, TimelineWindow, + GroupPins, GroupRoles, MEMBERSHIP_KINDS, Membership, PIN_LIST, Pin, RENDER_KINDS, STATE_KINDS, + TimelineWindow, }; const REPLAY_LIMIT: usize = 100; const PAGE_LIMIT: usize = 50; const PAGE_TIMEOUT: Duration = Duration::from_secs(10); -const LIVEKIT_TIMEOUT: Duration = Duration::from_secs(10); const LEAVE_WINDOW_SECS: u64 = 5 * 60; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -75,7 +71,6 @@ pub struct Group { members: GroupMembers, admins: GroupAdmins, roles: GroupRoles, - participants: GroupParticipants, pins: GroupPins, membership: Membership, membership_events: Vec, @@ -103,7 +98,6 @@ impl Group { members: GroupMembers::default(), admins: GroupAdmins::default(), roles: GroupRoles::default(), - participants: GroupParticipants::default(), pins: GroupPins::default(), membership: Membership::Unknown, membership_events: Vec::new(), @@ -163,10 +157,6 @@ impl Group { &self.roles } - pub fn participants(&self) -> &GroupParticipants { - &self.participants - } - pub fn pins(&self) -> &GroupPins { &self.pins } @@ -190,10 +180,6 @@ impl Group { }) } - pub fn loading(&self) -> bool { - self.loading - } - pub fn loading_more(&self) -> bool { self.loading_more } @@ -214,10 +200,6 @@ impl Group { self.refused.as_deref() } - pub fn previous_tag(&self, me: PublicKey) -> Option { - self.window.previous_tag(me) - } - pub fn send_message( &mut self, content: &str, @@ -236,15 +218,6 @@ impl Group { self.dispatch(move |id, prev| id.reaction(target, &emoji, prev), cx) } - pub fn put_user( - &mut self, - public_key: PublicKey, - roles: Vec, - cx: &mut Context, - ) -> Task> { - self.dispatch(move |id, prev| id.put_user(public_key, &roles, prev), cx) - } - pub fn remove_user( &mut self, public_key: PublicKey, @@ -421,68 +394,6 @@ impl Group { cx.notify(); } - pub fn livekit_session(&self, cx: &App) -> Task> { - let url = match self.key.livekit_token_url() { - Ok(url) => url, - Err(error) => return Task::ready(Err(error)), - }; - - let nostr = NostrRegistry::global(cx); - let signer = nostr.read(cx).signer(); - - let client = cx.http_client(); - - cx.background_spawn(async move { - let authorization = HttpData::new(url.clone(), HttpMethod::GET) - .to_authorization(&signer) - .await?; - - let request = Builder::new() - .uri(url.as_str()) - .method(Method::GET) - .header("Authorization", authorization) - .follow_redirects(RedirectPolicy::NoFollow) - .timeout(LIVEKIT_TIMEOUT) - .body(AsyncBody::default())?; - - let response = client.send(request).await?; - - if !response.status().is_success() { - bail!( - "nip29: the AV token endpoint answered {}", - response.status() - ); - } - - let mut body = Vec::new(); - response.into_body().read_to_end(&mut body).await?; - - LivekitSession::parse(&body) - }) - } - - pub fn livekit_supported(&self, cx: &App) -> Task> { - let url = match self.key.livekit_probe_url() { - Ok(url) => url, - Err(error) => return Task::ready(Err(error)), - }; - - let client = cx.http_client(); - - cx.background_spawn(async move { - let request = Builder::new() - .uri(url.as_str()) - .method(Method::GET) - .follow_redirects(RedirectPolicy::NoFollow) - .timeout(LIVEKIT_TIMEOUT) - .body(AsyncBody::default())?; - - let response = client.send(request).await?; - - Ok(response.status() == StatusCode::NO_CONTENT) - }) - } - pub(crate) fn save_envelope(&self, event: Event, cx: &App) -> Task> { let cache_tag = self.key.cache_tag(); let nostr = NostrRegistry::global(cx); @@ -681,10 +592,6 @@ impl Group { Ok(roles) => self.roles = roles, Err(_) => return false, }, - Kind::GroupLivekitParticipants => match GroupParticipants::parse(event) { - Ok(participants) => self.participants = participants, - Err(_) => return false, - }, Kind::Custom(PIN_LIST) => match GroupPins::parse(event) { Ok(pins) => self.pins = pins, Err(_) => return false, diff --git a/crates/nip29/src/lib.rs b/crates/nip29/src/lib.rs index 7fb8b75e..72de7e53 100644 --- a/crates/nip29/src/lib.rs +++ b/crates/nip29/src/lib.rs @@ -317,7 +317,7 @@ impl GroupsRegistry { })); } - pub fn reset(&mut self, cx: &mut Context) { + pub(crate) fn reset(&mut self, cx: &mut Context) { self.notification_listener = None; self.signal_consumer = None; self.tasks.clear(); diff --git a/crates/nip29/src/protocol.rs b/crates/nip29/src/protocol.rs index 6f14714c..4bbe2fc1 100644 --- a/crates/nip29/src/protocol.rs +++ b/crates/nip29/src/protocol.rs @@ -6,12 +6,12 @@ use std::str::FromStr; use anyhow::{Result, anyhow, bail}; use nostr_sdk::prelude::*; -pub const TIMELINE_WINDOW: usize = 50; +pub(crate) const TIMELINE_WINDOW: usize = 50; const PREVIOUS_REFS: usize = 3; const PREVIOUS_REF_LEN: usize = 8; -pub const RENDER_KINDS: [Kind; 5] = [ +pub(crate) const RENDER_KINDS: [Kind; 5] = [ Kind::TextNote, Kind::ChatMessage, Kind::Thread, @@ -19,21 +19,20 @@ pub const RENDER_KINDS: [Kind; 5] = [ Kind::Reaction, ]; -pub const PIN_LIST: u16 = 39_005; -pub const UPDATE_PIN_LIST: u16 = 9_010; +pub(crate) const PIN_LIST: u16 = 39_005; +pub(crate) const UPDATE_PIN_LIST: u16 = 9_010; -pub const STATE_KINDS: [Kind; 6] = [ +pub(crate) const STATE_KINDS: [Kind; 5] = [ Kind::GroupMetadata, Kind::GroupAdmins, Kind::GroupMembers, Kind::GroupRoles, - Kind::GroupLivekitParticipants, Kind::Custom(PIN_LIST), ]; -pub const MEMBERSHIP_KINDS: [Kind; 2] = [Kind::GroupPutUser, Kind::GroupRemoveUser]; +pub(crate) const MEMBERSHIP_KINDS: [Kind; 2] = [Kind::GroupPutUser, Kind::GroupRemoveUser]; -pub const ACTIVITY_KINDS: [Kind; 4] = [ +pub(crate) const ACTIVITY_KINDS: [Kind; 4] = [ Kind::GroupPutUser, Kind::GroupRemoveUser, Kind::GroupJoinRequest, @@ -128,22 +127,6 @@ impl GroupId { EventBuilder::new(Kind::GroupLeaveRequest, reason).tag(self.h_tag()) } - pub fn put_user( - &self, - public_key: PublicKey, - roles: &[String], - previous: Option, - ) -> EventBuilder { - let mut values = Vec::with_capacity(1 + roles.len()); - values.push(public_key.to_hex()); - values.extend(roles.iter().cloned()); - - EventBuilder::new(Kind::GroupPutUser, "") - .tag(self.h_tag()) - .tag(Tag::custom("p", values)) - .tag_maybe(previous) - } - pub fn remove_user(&self, public_key: PublicKey, previous: Option) -> EventBuilder { EventBuilder::new(Kind::GroupRemoveUser, "") .tag(self.h_tag()) @@ -263,47 +246,6 @@ impl GroupKey { self.hash(&mut hasher); hasher.finish() } - - pub fn livekit_token_url(&self) -> Result { - self.livekit_url(Some(self.id.as_str())) - } - - pub fn livekit_probe_url(&self) -> Result { - self.livekit_url(None) - } - - fn livekit_url(&self, group: Option<&str>) -> Result { - let mut url: Url = self.relay.clone().into(); - let scheme = if self.relay.scheme().is_secure() { - "https" - } else { - "http" - }; - - url.set_path("/"); - url.set_query(None); - url.set_fragment(None); - url.set_scheme(scheme) - .map_err(|_| anyhow!("{scheme} is not available for {}", self.relay))?; - - { - let mut segments = url - .path_segments_mut() - .map_err(|_| anyhow!("{} cannot carry a path", self.relay))?; - - segments - .pop_if_empty() - .push(".well-known") - .push("nip29") - .push("livekit"); - - if let Some(group) = group { - segments.push(group); - } - } - - Ok(url) - } } #[derive(Debug, Clone, PartialEq, Eq)] @@ -347,14 +289,6 @@ impl GroupReference { Ok(Self { id, relay, invite }) } - pub fn id(&self) -> &GroupId { - &self.id - } - - pub fn relay(&self) -> &RelayUrl { - &self.relay - } - pub fn invite(&self) -> Option<&str> { self.invite.as_deref() } @@ -376,7 +310,7 @@ impl FromStr for GroupReference { pub struct GroupMetadata { pub name: Option, pub picture: Option, - pub banner: Option, + pub(crate) banner: Option, pub about: Option, pub private: bool, pub restricted: bool, @@ -478,7 +412,7 @@ impl GroupMetadata { #[derive(Debug, Clone)] pub struct GroupCandidate { pub key: GroupKey, - pub metadata: GroupMetadata, + pub(crate) metadata: GroupMetadata, } impl GroupCandidate { @@ -539,10 +473,6 @@ impl GroupMembers { Ok(Self(event.tags.public_keys().collect())) } - pub fn contains(&self, public_key: &PublicKey) -> bool { - self.0.contains(public_key) - } - pub fn iter(&self) -> impl Iterator { self.0.iter() } @@ -560,7 +490,6 @@ impl GroupMembers { #[derive(Debug, Clone, PartialEq, Eq)] pub struct Role { pub name: String, - pub description: Option, } #[derive(Debug, Clone, Default)] @@ -580,10 +509,7 @@ impl GroupRoles { .next() .ok_or_else(|| anyhow!("role tag has no name"))?; - roles.push(Role { - name: name.clone(), - description: fields.next().cloned(), - }); + roles.push(Role { name: name.clone() }); } Ok(Self(roles)) @@ -594,37 +520,6 @@ impl GroupRoles { } } -#[derive(Debug, Clone, Default)] -pub struct GroupParticipants(Vec); - -impl GroupParticipants { - pub fn parse(event: &Event) -> Result { - if event.kind != Kind::GroupLivekitParticipants { - bail!("not a group participants event: kind {}", event.kind); - } - - let mut participants = Vec::new(); - - for tag in event.tags.iter().filter(|tag| tag.kind() == "participant") { - let Some(public_key) = tag.content() else { - continue; - }; - - participants.push(PublicKey::parse(public_key)?); - } - - Ok(Self(participants)) - } - - pub fn contains(&self, public_key: &PublicKey) -> bool { - self.0.contains(public_key) - } - - pub fn iter(&self) -> impl Iterator { - self.0.iter() - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub enum Pin { Event(EventId), @@ -680,43 +575,14 @@ impl GroupPins { } #[derive(Debug, Clone, PartialEq, Eq)] -pub struct LivekitSession { - pub token: String, - pub server_url: String, -} - -impl LivekitSession { - pub fn parse(body: &[u8]) -> Result { - let value: serde_json::Value = serde_json::from_slice(body)?; - - let token = value - .get("token") - .or_else(|| value.get("jwt")) - .and_then(serde_json::Value::as_str) - .ok_or_else(|| anyhow!("the AV response carries no token"))?; - - let server_url = value - .get("url") - .or_else(|| value.get("server_url")) - .and_then(serde_json::Value::as_str) - .ok_or_else(|| anyhow!("the AV response carries no server url"))?; - - Ok(Self { - token: token.to_owned(), - server_url: server_url.to_owned(), - }) - } -} - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct GroupListEntry { +pub(crate) struct GroupListEntry { pub id: GroupId, pub relay: RelayUrl, pub name: Option, } #[derive(Debug, Clone, Default)] -pub struct GroupList(Vec); +pub(crate) struct GroupList(Vec); impl GroupList { pub fn parse(event: &Event) -> Result { @@ -897,7 +763,7 @@ impl Activity { } #[derive(Debug, Clone, Default)] -pub struct TimelineWindow(Vec); +pub(crate) struct TimelineWindow(Vec); impl TimelineWindow { pub fn new() -> Self { diff --git a/crates/nip29_ui/src/lib.rs b/crates/nip29_ui/src/lib.rs index f020eef4..4da55506 100644 --- a/crates/nip29_ui/src/lib.rs +++ b/crates/nip29_ui/src/lib.rs @@ -315,7 +315,7 @@ pub struct GroupPanel { } impl GroupPanel { - pub fn new(group: Entity, window: &mut Window, cx: &mut Context) -> Self { + pub(crate) fn new(group: Entity, window: &mut Window, cx: &mut Context) -> Self { let (id, name, count, head) = { let group = group.read(cx); let rows = group.rows(); diff --git a/crates/nip4e/Cargo.toml b/crates/nip4e/Cargo.toml index 9ec26d9b..13e077f9 100644 --- a/crates/nip4e/Cargo.toml +++ b/crates/nip4e/Cargo.toml @@ -5,7 +5,6 @@ edition.workspace = true publish.workspace = true [dependencies] -common = { path = "../common" } state = { path = "../state" } person = { path = "../person" } ui = { path = "../ui" } @@ -14,7 +13,6 @@ settings = { path = "../settings" } gpui.workspace = true nostr-sdk.workspace = true -instant.workspace = true anyhow.workspace = true smallvec.workspace = true log.workspace = true diff --git a/crates/nip4e/src/lib.rs b/crates/nip4e/src/lib.rs index b08ffe52..d4d27ae1 100644 --- a/crates/nip4e/src/lib.rs +++ b/crates/nip4e/src/lib.rs @@ -45,7 +45,7 @@ pub enum DeviceEvent { } impl DeviceEvent { - pub fn error(error: T) -> Self + pub(crate) fn error(error: T) -> Self where T: Into, { @@ -60,9 +60,9 @@ impl DeviceEvent { pub struct DeviceRegistry { signer: Entity>, /// Whether there is a pending request for encryption key approval - pub pending_request: bool, + pub(crate) pending_request: bool, /// Whether an announcement has been made for this device - pub announcement_existed: Arc, + pub(crate) announcement_existed: Arc, /// Relay notification listener notification_listener: Option>>, tasks: Vec>>, @@ -398,7 +398,7 @@ impl DeviceRegistry { } /// Request encryption keys from other device - pub fn request(&mut self, cx: &mut Context) { + pub(crate) fn request(&mut self, cx: &mut Context) { let nostr = NostrRegistry::global(cx); let client = nostr.read(cx).client(); let signer = nostr.read(cx).signer(); diff --git a/crates/person/src/person.rs b/crates/person/src/person.rs index 243268b5..7577ddb7 100644 --- a/crates/person/src/person.rs +++ b/crates/person/src/person.rs @@ -47,12 +47,6 @@ impl Hash for Person { } } -impl From for Person { - fn from(public_key: PublicKey) -> Self { - Self::new(public_key, Metadata::default()) - } -} - impl Person { pub fn new(public_key: PublicKey, metadata: Metadata) -> Self { Self { @@ -64,13 +58,13 @@ impl Person { } /// Build profile encryption keys announcement - pub fn with_announcement(mut self, announcement: Announcement) -> Self { + pub(crate) fn with_announcement(mut self, announcement: Announcement) -> Self { self.announcement = Some(announcement); self } /// Build profile messaging relays - pub fn with_messaging_relays(mut self, relays: I) -> Self + pub(crate) fn with_messaging_relays(mut self, relays: I) -> Self where I: IntoIterator, { @@ -135,17 +129,17 @@ impl Person { } /// Set profile metadata - pub fn set_metadata(&mut self, metadata: Metadata) { + pub(crate) fn set_metadata(&mut self, metadata: Metadata) { self.metadata = metadata; } /// Set profile encryption keys announcement - pub fn set_announcement(&mut self, announcement: Announcement) { + pub(crate) fn set_announcement(&mut self, announcement: Announcement) { self.announcement = Some(announcement); } /// Set profile messaging relays - pub fn set_messaging_relays(&mut self, relays: I) + pub(crate) fn set_messaging_relays(&mut self, relays: I) where I: IntoIterator, { diff --git a/crates/settings/src/lib.rs b/crates/settings/src/lib.rs index b8625609..e4b455cc 100644 --- a/crates/settings/src/lib.rs +++ b/crates/settings/src/lib.rs @@ -38,14 +38,29 @@ macro_rules! setting_accessors { }; } +macro_rules! setting_getters { + ($(pub $field:ident: $type:ty),* $(,)?) => { + impl AppSettings { + $( + paste::paste! { + pub fn [](cx: &App) -> $type { + Self::global(cx).read(cx).inner.read(cx).$field.clone() + } + } + )* + } + }; +} + setting_accessors! { - pub theme: Option, pub theme_mode: ThemeMode, pub hide_avatar: bool, pub screening: bool, pub nip4e: bool, - pub trusted_relays: Vec, pub file_server: Url, +} + +setting_getters! { pub pinned_rooms: Vec, pub pinned_groups: Vec, } @@ -60,14 +75,6 @@ pub enum SignerKind { } impl SignerKind { - pub fn auto(&self) -> bool { - matches!(self, SignerKind::Auto) - } - - pub fn user(&self) -> bool { - matches!(self, SignerKind::User) - } - pub fn encryption(&self) -> bool { matches!(self, SignerKind::Encryption) } @@ -158,12 +165,6 @@ impl Default for Settings { } } -impl AsRef for Settings { - fn as_ref(&self) -> &Settings { - self - } -} - struct GlobalAppSettings(Entity); impl Global for GlobalAppSettings {} @@ -182,11 +183,6 @@ impl AppSettings { cx.global::().0.clone() } - /// The underlying settings entity, which notifies whenever any field changes. - pub fn entity(&self) -> &Entity { - &self.inner - } - /// Set the global settings instance fn set_global(state: Entity, cx: &mut App) { cx.set_global(GlobalAppSettings(state)); @@ -313,30 +309,6 @@ impl AppSettings { self.inner.read(cx).nip4e } - /// Check if the given relay is already authenticated - pub fn trusted_relay(&self, url: &RelayUrl, cx: &App) -> bool { - self.inner - .read(cx) - .trusted_relays - .iter() - .any(|relay| relay == url.as_str_without_trailing_slash()) - } - - /// Add a relay to the trusted list - pub fn add_trusted_relay(&mut self, url: &RelayUrl, cx: &mut Context) { - self.inner.update(cx, |this, cx| { - if !this - .trusted_relays - .iter() - .any(|relay| relay == url.as_str_without_trailing_slash()) - { - this.trusted_relays - .push(url.as_str_without_trailing_slash().to_string()); - cx.notify(); - } - }); - } - /// Check if the chat room is pinned pub fn pinned_room(&self, id: u64, cx: &App) -> bool { self.inner.read(cx).pinned_rooms.contains(&id) diff --git a/crates/state/Cargo.toml b/crates/state/Cargo.toml index daebc7a9..18c2196f 100644 --- a/crates/state/Cargo.toml +++ b/crates/state/Cargo.toml @@ -17,7 +17,6 @@ gpui.workspace = true instant.workspace = true flume.workspace = true futures.workspace = true -log.workspace = true anyhow.workspace = true webbrowser.workspace = true serde_json.workspace = true diff --git a/crates/state/src/constants.rs b/crates/state/src/constants.rs index d2bf9e30..0cd257a9 100644 --- a/crates/state/src/constants.rs +++ b/crates/state/src/constants.rs @@ -1,14 +1,11 @@ /// Client name (Application name) pub const CLIENT_NAME: &str = "Coop"; -/// COOP's public key -pub const COOP_PUBKEY: &str = "npub1j3rz3ndl902lya6ywxvy5c983lxs8mpukqnx4pa4lt5wrykwl5ys7wpw3x"; - /// App ID pub const APP_ID: &str = "su.reya.coop"; /// Keyring name -pub const MASTER_KEYRING: &str = "Coop Master Key"; +pub(crate) const MASTER_KEYRING: &str = "Coop Master Key"; pub const USER_KEYRING: &str = "Coop User Credential"; /// Default timeout for subscription @@ -26,20 +23,12 @@ pub const DEVICE_GIFTWRAP: &str = "device-gift-wraps"; /// Default subscription id for user gift wrap events pub const USER_GIFTWRAP: &str = "user-gift-wraps"; -/// Default timeout for Nostr Connect -pub const NOSTR_CONNECT_TIMEOUT: u64 = 60; - -/// Default Nostr Connect relay -pub const NOSTR_CONNECT_RELAY: &str = "wss://relay.nip46.com"; - -/// Default vertex relays -pub const WOT_RELAYS: [&str; 1] = ["wss://relay.vertexlab.io"]; +/// Default search relays +pub(crate) const INDEXER_RELAYS: [&str; 2] = + ["wss://indexer.coracle.social", "wss://user.kindpag.es"]; /// Default search relays -pub const INDEXER_RELAYS: [&str; 2] = ["wss://indexer.coracle.social", "wss://user.kindpag.es"]; - -/// Default search relays -pub const SEARCH_RELAYS: [&str; 2] = ["wss://antiprimal.net", "wss://search.nos.today"]; +pub(crate) const SEARCH_RELAYS: [&str; 2] = ["wss://antiprimal.net", "wss://search.nos.today"]; /// Default bootstrap relays pub const BOOTSTRAP_RELAYS: [&str; 4] = [ diff --git a/crates/state/src/file.rs b/crates/state/src/file.rs index 53c808dc..2dc380a3 100644 --- a/crates/state/src/file.rs +++ b/crates/state/src/file.rs @@ -15,9 +15,9 @@ use nostr::nips::nip94::Sha256Hash; use nostr_sdk::prelude::*; use sha2::{Digest, Sha256}; -pub const ALGORITHM: &str = "aes-gcm"; +pub(crate) const ALGORITHM: &str = "aes-gcm"; -pub const MAX_FILE_SIZE: usize = 25 * 1024 * 1024; +pub(crate) const MAX_FILE_SIZE: usize = 25 * 1024 * 1024; const TAG_SHA256: &str = "x"; const TAG_ORIGINAL_SHA256: &str = "ox"; @@ -30,7 +30,7 @@ const TAG_DIM: &str = "dim"; const TAG_ALT: &str = "alt"; #[derive(Debug, Clone, PartialEq, Eq)] -pub struct EncryptedFile { +pub(crate) struct EncryptedFile { pub data: Vec, pub key: String, pub nonce: String, @@ -115,7 +115,7 @@ impl FileAttachment { } } -pub fn encrypt(data: &[u8]) -> Result { +pub(crate) fn encrypt(data: &[u8]) -> Result { let key = Aes256Gcm::generate_key(OsRng); let nonce = AesGcm::::generate_nonce(OsRng); let cipher = AesGcm::::new(&key); @@ -131,7 +131,7 @@ pub fn encrypt(data: &[u8]) -> Result { }) } -pub fn decrypt(data: &[u8], key: &str, nonce: &str) -> Result, Error> { +pub(crate) fn decrypt(data: &[u8], key: &str, nonce: &str) -> Result, Error> { let key = decode(key, "decryption key")?; let nonce = decode(nonce, "decryption nonce")?; @@ -159,7 +159,7 @@ pub fn decrypt(data: &[u8], key: &str, nonce: &str) -> Result, Error> { } } -pub fn sha256_hex(data: &[u8]) -> String { +pub(crate) fn sha256_hex(data: &[u8]) -> String { let hash: [u8; 32] = Sha256::digest(data).into(); Sha256Hash::from_byte_array(hash).to_hex() @@ -227,7 +227,7 @@ pub async fn upload_encrypted( Err(anyhow!("File upload not supported on web")) } -pub async fn download_and_decrypt( +pub(crate) async fn download_and_decrypt( url: &Url, key: &str, nonce: &str, @@ -318,63 +318,6 @@ pub async fn download_and_decrypt_to_file( Err(anyhow!("File download not supported on web")) } -/// The cache file a decrypted blob for `plaintext_sha256` is written to. -#[cfg(not(target_arch = "wasm32"))] -fn blob_cache_path(plaintext_sha256: &str) -> PathBuf { - std::env::temp_dir() - .join("coop-blobs") - .join(plaintext_sha256) -} - -/// Download an encrypted blob whose pointer carries the *plaintext* hash -/// and write the decrypted bytes to a content-addressed cache file, -/// so later renders skip the network. -/// -/// The cache file carries no extension: `img` sniffs the format from the bytes. -#[cfg(not(target_arch = "wasm32"))] -pub async fn download_and_decrypt_to_cache( - url: &Url, - key: &str, - nonce: &str, - plaintext_sha256: &str, - cx: &AsyncApp, -) -> Result { - let path = blob_cache_path(plaintext_sha256); - - if smol::fs::metadata(&path).await.is_ok() { - return Ok(path); - } - - let data = download_and_decrypt(url, key, nonce, None, cx).await?; - - if !sha256_hex(&data).eq_ignore_ascii_case(plaintext_sha256) { - bail!("Blob hash mismatch"); - } - - let Some(parent) = path.parent() else { - bail!("Invalid blob cache path"); - }; - smol::fs::create_dir_all(parent).await?; - - // Write under a temporary name first, so an interrupted download is never reused - let partial = path.with_extension("download"); - smol::fs::write(&partial, data).await?; - smol::fs::rename(&partial, &path).await?; - - Ok(path) -} - -#[cfg(target_arch = "wasm32")] -pub async fn download_and_decrypt_to_cache( - _url: &Url, - _key: &str, - _nonce: &str, - _plaintext_sha256: &str, - _cx: &AsyncApp, -) -> Result { - Err(anyhow!("Blob download not supported on web")) -} - fn tag_value<'a>(tags: &'a Tags, name: &str) -> Option<&'a str> { tags.iter() .find(|tag| tag.kind() == name) diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index 15909b35..3499ae37 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -52,8 +52,6 @@ impl Global for GlobalNostrRegistry {} /// Signer event. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub enum StateEvent { - /// The state is busy - Busy, /// User has no signer NoSigner, /// The signer has changed @@ -67,7 +65,7 @@ impl StateEvent { matches!(self, StateEvent::SignerChanged) } - pub fn error(error: T) -> Self + pub(crate) fn error(error: T) -> Self where T: Into, { @@ -180,11 +178,6 @@ impl NostrRegistry { self.current_user } - /// Whether the initial credential check has concluded - pub fn ready(&self) -> bool { - self.ready - } - fn mark_ready(&mut self, cx: &mut Context) { if self.ready { return; @@ -525,68 +518,4 @@ impl NostrRegistry { Ok(results) }) } - - /// Perform a WoT (via Vertex) search for a given query. - pub fn wot_search(&self, query: &str, cx: &App) -> Task, Error>> { - let client = self.client(); - let query = query.to_string(); - let signer = self.signer.clone(); - - cx.background_spawn(async move { - // Construct a vertex request event - let event = EventBuilder::new(Kind::Custom(5315), "") - .tags(vec![ - Tag::custom("param", vec!["search", &query]), - Tag::custom("param", vec!["limit", "10"]), - ]) - .finalize_async(&signer) - .await?; - - // Send the event to vertex relays - let output = client.send_event(&event).to(WOT_RELAYS).await?; - - // Construct a filter to get the response or error from vertex - let filter = Filter::new() - .kinds(vec![Kind::Custom(6315), Kind::Custom(7000)]) - .event(output.id().to_owned()); - - // Construct target for subscription - let target: HashMap<&str, Vec> = WOT_RELAYS - .into_iter() - .map(|relay| (relay, vec![filter.clone()])) - .collect(); - - // Stream events from the wot relays - let mut stream = client - .stream_events(target) - .timeout(Duration::from_secs(TIMEOUT)) - .await?; - - while let Some((_url, res)) = stream.next().await { - if let Ok(event) = res { - match event.kind { - Kind::Custom(6315) => { - let content: serde_json::Value = serde_json::from_str(&event.content)?; - let pubkeys: Vec = content - .as_array() - .into_iter() - .flatten() - .filter_map(|item| item.as_object()) - .filter_map(|obj| obj.get("pubkey").and_then(|v| v.as_str())) - .filter_map(|pubkey_str| PublicKey::parse(pubkey_str).ok()) - .collect(); - - return Ok(pubkeys); - } - Kind::Custom(7000) => { - return Err(anyhow!("Search error")); - } - _ => {} - } - } - } - - Err(anyhow!("No results for query: {query}")) - }) - } } diff --git a/crates/state/src/nip4e.rs b/crates/state/src/nip4e.rs index 179e863f..e0d53583 100644 --- a/crates/state/src/nip4e.rs +++ b/crates/state/src/nip4e.rs @@ -8,9 +8,6 @@ pub struct Announcement { } impl Announcement { - /// Parse an announcement from an event, returning `None` when the `n` - /// tag is missing or malformed so callers never mistake the author's - /// identity key for an encryption key. pub fn from_event(event: &Event) -> Option { let public_key = event .tags @@ -22,10 +19,6 @@ impl Announcement { Some(Self { public_key }) } - pub fn new(public_key: PublicKey) -> Self { - Self { public_key } - } - /// Returns the public key of the device that created this announcement. pub fn public_key(&self) -> PublicKey { self.public_key diff --git a/crates/state/src/signer.rs b/crates/state/src/signer.rs index cf9a2bf6..050d9076 100644 --- a/crates/state/src/signer.rs +++ b/crates/state/src/signer.rs @@ -50,7 +50,7 @@ impl UniversalSigner { } /// Swap the inner signer in-place. All clones see the new signer. - pub fn swap_inner(&self, new_signer: T) + pub(crate) fn swap_inner(&self, new_signer: T) where T: AsyncGetPublicKey + AsyncSignEvent + AsyncNip44 + 'static, ::Error: Error + Send + Sync + 'static, @@ -137,14 +137,6 @@ where } } -impl UniversalSigner { - #[allow(dead_code)] - fn with_inner(&self, f: impl FnOnce(&dyn InnerSigner) -> R) -> R { - let guard = self.inner.read().expect("RwLock poisoned"); - f(&**guard) - } -} - impl AsyncGetPublicKey for UniversalSigner { type Error = UniversalSignerError; diff --git a/crates/theme/Cargo.toml b/crates/theme/Cargo.toml index 314f8d0e..dfa74265 100644 --- a/crates/theme/Cargo.toml +++ b/crates/theme/Cargo.toml @@ -12,7 +12,6 @@ log.workspace = true serde.workspace = true serde_json.workspace = true schemars.workspace = true -smallvec.workspace = true [dev-dependencies] tempfile = "3.10" diff --git a/crates/theme/src/colors.rs b/crates/theme/src/colors.rs index 9496ba0c..f2ca4bd0 100644 --- a/crates/theme/src/colors.rs +++ b/crates/theme/src/colors.rs @@ -2,7 +2,7 @@ use gpui::{Hsla, Rgba, hsla}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use crate::scale::{ColorScale, ColorScaleSet, ColorScales}; +use crate::scale::{ColorScale, ColorScaleSet}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Deserialize, Serialize, JsonSchema)] pub struct ThemeColors { @@ -105,7 +105,7 @@ impl ThemeColors { /// Returns the default colors for light themes. /// /// Themes that do not specify all colors are refined off of these defaults. - pub fn light() -> Self { + pub(crate) fn light() -> Self { Self { background: neutral().light().step_1(), surface_background: neutral().light().step_2(), @@ -191,7 +191,7 @@ impl ThemeColors { /// Returns the default colors for dark themes. /// /// Themes that do not specify all colors are refined off of these defaults. - pub fn dark() -> Self { + pub(crate) fn dark() -> Self { Self { background: neutral().dark().step_1(), surface_background: neutral().dark().step_2(), @@ -296,14 +296,13 @@ fn warning() -> ColorScaleSet { /// - h: 0..360.0 /// - s: 0.0..100.0 /// - l: 0.0..100.0 -pub fn hsl(h: f32, s: f32, l: f32) -> Hsla { +pub(crate) fn hsl(h: f32, s: f32, l: f32) -> Hsla { hsla(h / 360., s / 100.0, l / 100.0, 1.0) } type StaticColorScale = [&'static str; 12]; struct StaticColorScaleSet { - scale: &'static str, light: StaticColorScale, light_alpha: StaticColorScale, dark: StaticColorScale, @@ -323,7 +322,6 @@ impl TryFrom for ColorScaleSet { } Ok(Self::new( - value.scale, to_color_scale(value.light)?, to_color_scale(value.light_alpha)?, to_color_scale(value.dark)?, @@ -332,48 +330,8 @@ impl TryFrom for ColorScaleSet { } } -/// Color scales used to build the default themes. -pub fn default_color_scales() -> ColorScales { - ColorScales { - gray: gray(), - mauve: mauve(), - slate: slate(), - sage: sage(), - olive: olive(), - sand: sand(), - gold: gold(), - bronze: bronze(), - brown: brown(), - yellow: yellow(), - amber: amber(), - orange: orange(), - tomato: tomato(), - red: red(), - ruby: ruby(), - crimson: crimson(), - pink: pink(), - plum: plum(), - purple: purple(), - violet: violet(), - iris: iris(), - indigo: indigo(), - blue: blue(), - cyan: cyan(), - teal: teal(), - jade: jade(), - green: green(), - grass: grass(), - lime: lime(), - mint: mint(), - sky: sky(), - black: black(), - white: white(), - } -} - pub(crate) fn gray() -> ColorScaleSet { StaticColorScaleSet { - scale: "Gray", light: [ "#fcfcfcff", "#f9f9f9ff", @@ -435,521 +393,8 @@ pub(crate) fn gray() -> ColorScaleSet { .unwrap() } -pub(crate) fn mauve() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Mauve", - light: [ - "#fdfcfdff", - "#faf9fbff", - "#f2eff3ff", - "#eae7ecff", - "#e3dfe6ff", - "#dbd8e0ff", - "#d0cdd7ff", - "#bcbac7ff", - "#8e8c99ff", - "#84828eff", - "#65636dff", - "#211f26ff", - ], - light_alpha: [ - "#55005503", - "#2b005506", - "#30004010", - "#20003618", - "#20003820", - "#14003527", - "#10003332", - "#08003145", - "#05001d73", - "#0500197d", - "#0400119c", - "#020008e0", - ], - dark: [ - "#121113ff", - "#1a191bff", - "#232225ff", - "#2b292dff", - "#323035ff", - "#3c393fff", - "#49474eff", - "#625f69ff", - "#6f6d78ff", - "#7c7a85ff", - "#b5b2bcff", - "#eeeef0ff", - ], - dark_alpha: [ - "#00000000", - "#f5f4f609", - "#ebeaf814", - "#eee5f81d", - "#efe6fe25", - "#f1e6fd30", - "#eee9ff40", - "#eee7ff5d", - "#eae6fd6e", - "#ece9fd7c", - "#f5f1ffb7", - "#fdfdffef", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn slate() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Slate", - light: [ - "#fcfcfdff", - "#f9f9fbff", - "#f0f0f3ff", - "#e8e8ecff", - "#e0e1e6ff", - "#d9d9e0ff", - "#cdced6ff", - "#b9bbc6ff", - "#8b8d98ff", - "#80838dff", - "#60646cff", - "#1c2024ff", - ], - light_alpha: [ - "#00005503", - "#00005506", - "#0000330f", - "#00002d17", - "#0009321f", - "#00002f26", - "#00062e32", - "#00083046", - "#00051d74", - "#00071b7f", - "#0007149f", - "#000509e3", - ], - dark: [ - "#111113ff", - "#18191bff", - "#212225ff", - "#272a2dff", - "#2e3135ff", - "#363a3fff", - "#43484eff", - "#5a6169ff", - "#696e77ff", - "#777b84ff", - "#b0b4baff", - "#edeef0ff", - ], - dark_alpha: [ - "#00000000", - "#d8f4f609", - "#ddeaf814", - "#d3edf81d", - "#d9edfe25", - "#d6ebfd30", - "#d9edff40", - "#d9edff5d", - "#dfebfd6d", - "#e5edfd7b", - "#f1f7feb5", - "#fcfdffef", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn sage() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Sage", - light: [ - "#fbfdfcff", - "#f7f9f8ff", - "#eef1f0ff", - "#e6e9e8ff", - "#dfe2e0ff", - "#d7dad9ff", - "#cbcfcdff", - "#b8bcbaff", - "#868e8bff", - "#7c8481ff", - "#5f6563ff", - "#1a211eff", - ], - light_alpha: [ - "#00804004", - "#00402008", - "#002d1e11", - "#001f1519", - "#00180820", - "#00140d28", - "#00140a34", - "#000f0847", - "#00110b79", - "#00100a83", - "#000a07a0", - "#000805e5", - ], - dark: [ - "#101211ff", - "#171918ff", - "#202221ff", - "#272a29ff", - "#2e3130ff", - "#373b39ff", - "#444947ff", - "#5b625fff", - "#63706bff", - "#717d79ff", - "#adb5b2ff", - "#eceeedff", - ], - dark_alpha: [ - "#00000000", - "#f0f2f108", - "#f3f5f412", - "#f2fefd1a", - "#f1fbfa22", - "#edfbf42d", - "#edfcf73c", - "#ebfdf657", - "#dffdf266", - "#e5fdf674", - "#f4fefbb0", - "#fdfffeed", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn olive() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Olive", - light: [ - "#fcfdfcff", - "#f8faf8ff", - "#eff1efff", - "#e7e9e7ff", - "#dfe2dfff", - "#d7dad7ff", - "#cccfccff", - "#b9bcb8ff", - "#898e87ff", - "#7f847dff", - "#60655fff", - "#1d211cff", - ], - light_alpha: [ - "#00550003", - "#00490007", - "#00200010", - "#00160018", - "#00180020", - "#00140028", - "#000f0033", - "#040f0047", - "#050f0078", - "#040e0082", - "#020a00a0", - "#010600e3", - ], - dark: [ - "#111210ff", - "#181917ff", - "#212220ff", - "#282a27ff", - "#2f312eff", - "#383a36ff", - "#454843ff", - "#5c625bff", - "#687066ff", - "#767d74ff", - "#afb5adff", - "#eceeecff", - ], - dark_alpha: [ - "#00000000", - "#f1f2f008", - "#f4f5f312", - "#f3fef21a", - "#f2fbf122", - "#f4faed2c", - "#f2fced3b", - "#edfdeb57", - "#ebfde766", - "#f0fdec74", - "#f6fef4b0", - "#fdfffded", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn sand() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Sand", - light: [ - "#fdfdfcff", - "#f9f9f8ff", - "#f1f0efff", - "#e9e8e6ff", - "#e2e1deff", - "#dad9d6ff", - "#cfcecaff", - "#bcbbb5ff", - "#8d8d86ff", - "#82827cff", - "#63635eff", - "#21201cff", - ], - light_alpha: [ - "#55550003", - "#25250007", - "#20100010", - "#1f150019", - "#1f180021", - "#19130029", - "#19140035", - "#1915014a", - "#0f0f0079", - "#0c0c0083", - "#080800a1", - "#060500e3", - ], - dark: [ - "#111110ff", - "#191918ff", - "#222221ff", - "#2a2a28ff", - "#31312eff", - "#3b3a37ff", - "#494844ff", - "#62605bff", - "#6f6d66ff", - "#7c7b74ff", - "#b5b3adff", - "#eeeeecff", - ], - dark_alpha: [ - "#00000000", - "#f4f4f309", - "#f6f6f513", - "#fefef31b", - "#fbfbeb23", - "#fffaed2d", - "#fffbed3c", - "#fff9eb57", - "#fffae965", - "#fffdee73", - "#fffcf4b0", - "#fffffded", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn gold() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Gold", - light: [ - "#fdfdfcff", - "#faf9f2ff", - "#f2f0e7ff", - "#eae6dbff", - "#e1dccfff", - "#d8d0bfff", - "#cbc0aaff", - "#b9a88dff", - "#978365ff", - "#8c7a5eff", - "#71624bff", - "#3b352bff", - ], - light_alpha: [ - "#55550003", - "#9d8a000d", - "#75600018", - "#6b4e0024", - "#60460030", - "#64440040", - "#63420055", - "#633d0072", - "#5332009a", - "#492d00a1", - "#362100b4", - "#130c00d4", - ], - dark: [ - "#121211ff", - "#1b1a17ff", - "#24231fff", - "#2d2b26ff", - "#38352eff", - "#444039ff", - "#544f46ff", - "#696256ff", - "#978365ff", - "#a39073ff", - "#cbb99fff", - "#e8e2d9ff", - ], - dark_alpha: [ - "#91911102", - "#f9e29d0b", - "#f8ecbb15", - "#ffeec41e", - "#feecc22a", - "#feebcb37", - "#ffedcd48", - "#fdeaca5f", - "#ffdba690", - "#fedfb09d", - "#fee7c6c8", - "#fef7ede7", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn bronze() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Bronze", - light: [ - "#fdfcfcff", - "#fdf7f5ff", - "#f6edeaff", - "#efe4dfff", - "#e7d9d3ff", - "#dfcdc5ff", - "#d3bcb3ff", - "#c2a499ff", - "#a18072ff", - "#957468ff", - "#7d5e54ff", - "#43302bff", - ], - light_alpha: [ - "#55000003", - "#cc33000a", - "#92250015", - "#80280020", - "#7423002c", - "#7324003a", - "#6c1f004c", - "#671c0066", - "#551a008d", - "#4c150097", - "#3d0f00ab", - "#1d0600d4", - ], - dark: [ - "#141110ff", - "#1c1917ff", - "#262220ff", - "#302a27ff", - "#3b3330ff", - "#493e3aff", - "#5a4c47ff", - "#6f5f58ff", - "#a18072ff", - "#ae8c7eff", - "#d4b3a5ff", - "#ede0d9ff", - ], - dark_alpha: [ - "#d1110004", - "#fbbc910c", - "#faceb817", - "#facdb622", - "#ffd2c12d", - "#ffd1c03c", - "#fdd0c04f", - "#ffd6c565", - "#fec7b09b", - "#fecab5a9", - "#ffd7c6d1", - "#fff1e9ec", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn brown() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Brown", - light: [ - "#fefdfcff", - "#fcf9f6ff", - "#f6eee7ff", - "#f0e4d9ff", - "#ebdacaff", - "#e4cdb7ff", - "#dcbc9fff", - "#cea37eff", - "#ad7f58ff", - "#a07553ff", - "#815e46ff", - "#3e332eff", - ], - light_alpha: [ - "#aa550003", - "#aa550009", - "#a04b0018", - "#9b4a0026", - "#9f4d0035", - "#a04e0048", - "#a34e0060", - "#9f4a0081", - "#823c00a7", - "#723300ac", - "#522100b9", - "#140600d1", - ], - dark: [ - "#12110fff", - "#1c1816ff", - "#28211dff", - "#322922ff", - "#3e3128ff", - "#4d3c2fff", - "#614a39ff", - "#7c5f46ff", - "#ad7f58ff", - "#b88c67ff", - "#dbb594ff", - "#f2e1caff", - ], - dark_alpha: [ - "#91110002", - "#fba67c0c", - "#fcb58c19", - "#fbbb8a24", - "#fcb88931", - "#fdba8741", - "#ffbb8856", - "#ffbe8773", - "#feb87da8", - "#ffc18cb3", - "#fed1aad9", - "#feecd4f2", - ], - } - .try_into() - .unwrap() -} - pub(crate) fn yellow() -> ColorScaleSet { StaticColorScaleSet { - scale: "Yellow", light: [ "#fdfdf9ff", "#fefce9ff", @@ -1011,73 +456,8 @@ pub(crate) fn yellow() -> ColorScaleSet { .unwrap() } -pub(crate) fn amber() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Amber", - light: [ - "#fefdfbff", - "#fefbe9ff", - "#fff7c2ff", - "#ffee9cff", - "#fbe577ff", - "#f3d673ff", - "#e9c162ff", - "#e2a336ff", - "#ffc53dff", - "#ffba18ff", - "#ab6400ff", - "#4f3422ff", - ], - light_alpha: [ - "#c0800004", - "#f4d10016", - "#ffde003d", - "#ffd40063", - "#f8cf0088", - "#eab5008c", - "#dc9b009d", - "#da8a00c9", - "#ffb300c2", - "#ffb300e7", - "#ab6400ff", - "#341500dd", - ], - dark: [ - "#16120cff", - "#1d180fff", - "#302008ff", - "#3f2700ff", - "#4d3000ff", - "#5c3d05ff", - "#714f19ff", - "#8f6424ff", - "#ffc53dff", - "#ffd60aff", - "#ffca16ff", - "#ffe7b3ff", - ], - dark_alpha: [ - "#e63c0006", - "#fd9b000d", - "#fa820022", - "#fc820032", - "#fd8b0041", - "#fd9b0051", - "#ffab2567", - "#ffae3587", - "#ffc53dff", - "#ffd60aff", - "#ffca16ff", - "#ffe7b3ff", - ], - } - .try_into() - .unwrap() -} - pub(crate) fn orange() -> ColorScaleSet { StaticColorScaleSet { - scale: "Orange", light: [ "#fefcfbff", "#fff7edff", @@ -1141,7 +521,6 @@ pub(crate) fn orange() -> ColorScaleSet { pub(crate) fn tomato() -> ColorScaleSet { StaticColorScaleSet { - scale: "Tomato", light: [ "#fffcfcff", "#fff8f7ff", @@ -1202,1283 +581,3 @@ pub(crate) fn tomato() -> ColorScaleSet { .try_into() .unwrap() } - -pub(crate) fn red() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Red", - light: [ - "#fffcfcff", - "#fff7f7ff", - "#feebecff", - "#ffdbdcff", - "#ffcdceff", - "#fdbdbeff", - "#f4a9aaff", - "#eb8e90ff", - "#e5484dff", - "#dc3e42ff", - "#ce2c31ff", - "#641723ff", - ], - light_alpha: [ - "#ff000003", - "#ff000008", - "#f3000d14", - "#ff000824", - "#ff000632", - "#f8000442", - "#df000356", - "#d2000571", - "#db0007b7", - "#d10005c1", - "#c40006d3", - "#55000de8", - ], - dark: [ - "#191111ff", - "#201314ff", - "#3b1219ff", - "#500f1cff", - "#611623ff", - "#72232dff", - "#8c333aff", - "#b54548ff", - "#e5484dff", - "#ec5d5eff", - "#ff9592ff", - "#ffd1d9ff", - ], - dark_alpha: [ - "#f4121209", - "#f22f3e11", - "#ff173f2d", - "#fe0a3b44", - "#ff204756", - "#ff3e5668", - "#ff536184", - "#ff5d61b0", - "#fe4e54e4", - "#ff6465eb", - "#ff9592ff", - "#ffd1d9ff", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn ruby() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Ruby", - light: [ - "#fffcfdff", - "#fff7f8ff", - "#feeaedff", - "#ffdce1ff", - "#ffced6ff", - "#f8bfc8ff", - "#efacb8ff", - "#e592a3ff", - "#e54666ff", - "#dc3b5dff", - "#ca244dff", - "#64172bff", - ], - light_alpha: [ - "#ff005503", - "#ff002008", - "#f3002515", - "#ff002523", - "#ff002a31", - "#e4002440", - "#ce002553", - "#c300286d", - "#db002cb9", - "#d2002cc4", - "#c10030db", - "#550016e8", - ], - dark: [ - "#191113ff", - "#1e1517ff", - "#3a141eff", - "#4e1325ff", - "#5e1a2eff", - "#6f2539ff", - "#883447ff", - "#b3445aff", - "#e54666ff", - "#ec5a72ff", - "#ff949dff", - "#fed2e1ff", - ], - dark_alpha: [ - "#f4124a09", - "#fe5a7f0e", - "#ff235d2c", - "#fd195e42", - "#fe2d6b53", - "#ff447665", - "#ff577d80", - "#ff5c7cae", - "#fe4c70e4", - "#ff617beb", - "#ff949dff", - "#ffd3e2fe", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn crimson() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Crimson", - light: [ - "#fffcfdff", - "#fef7f9ff", - "#ffe9f0ff", - "#fedce7ff", - "#faceddff", - "#f3bed1ff", - "#eaacc3ff", - "#e093b2ff", - "#e93d82ff", - "#df3478ff", - "#cb1d63ff", - "#621639ff", - ], - light_alpha: [ - "#ff005503", - "#e0004008", - "#ff005216", - "#f8005123", - "#e5004f31", - "#d0004b41", - "#bf004753", - "#b6004a6c", - "#e2005bc2", - "#d70056cb", - "#c4004fe2", - "#530026e9", - ], - dark: [ - "#191114ff", - "#201318ff", - "#381525ff", - "#4d122fff", - "#5c1839ff", - "#6d2545ff", - "#873356ff", - "#b0436eff", - "#e93d82ff", - "#ee518aff", - "#ff92adff", - "#fdd3e8ff", - ], - dark_alpha: [ - "#f4126709", - "#f22f7a11", - "#fe2a8b2a", - "#fd158741", - "#fd278f51", - "#fe459763", - "#fd559b7f", - "#fe5b9bab", - "#fe418de8", - "#ff5693ed", - "#ff92adff", - "#ffd5eafd", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn pink() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Pink", - light: [ - "#fffcfeff", - "#fef7fbff", - "#fee9f5ff", - "#fbdcefff", - "#f6cee7ff", - "#efbfddff", - "#e7acd0ff", - "#dd93c2ff", - "#d6409fff", - "#cf3897ff", - "#c2298aff", - "#651249ff", - ], - light_alpha: [ - "#ff00aa03", - "#e0008008", - "#f4008c16", - "#e2008b23", - "#d1008331", - "#c0007840", - "#b6006f53", - "#af006f6c", - "#c8007fbf", - "#c2007ac7", - "#b60074d6", - "#59003bed", - ], - dark: [ - "#191117ff", - "#21121dff", - "#37172fff", - "#4b143dff", - "#591c47ff", - "#692955ff", - "#833869ff", - "#a84885ff", - "#d6409fff", - "#de51a8ff", - "#ff8dccff", - "#fdd1eaff", - ], - dark_alpha: [ - "#f412bc09", - "#f420bb12", - "#fe37cc29", - "#fc1ec43f", - "#fd35c24e", - "#fd51c75f", - "#fd62c87b", - "#ff68c8a2", - "#fe49bcd4", - "#ff5cc0dc", - "#ff8dccff", - "#ffd3ecfd", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn plum() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Plum", - light: [ - "#fefcffff", - "#fdf7fdff", - "#fbebfbff", - "#f7def8ff", - "#f2d1f3ff", - "#e9c2ecff", - "#deade3ff", - "#cf91d8ff", - "#ab4abaff", - "#a144afff", - "#953ea3ff", - "#53195dff", - ], - light_alpha: [ - "#aa00ff03", - "#c000c008", - "#cc00cc14", - "#c200c921", - "#b700bd2e", - "#a400b03d", - "#9900a852", - "#9000a56e", - "#89009eb5", - "#7f0092bb", - "#730086c1", - "#40004be6", - ], - dark: [ - "#181118ff", - "#201320ff", - "#351a35ff", - "#451d47ff", - "#512454ff", - "#5e3061ff", - "#734079ff", - "#92549cff", - "#ab4abaff", - "#b658c4ff", - "#e796f3ff", - "#f4d4f4ff", - ], - dark_alpha: [ - "#f112f108", - "#f22ff211", - "#fd4cfd27", - "#f646ff3a", - "#f455ff48", - "#f66dff56", - "#f07cfd70", - "#ee84ff95", - "#e961feb6", - "#ed70ffc0", - "#f19cfef3", - "#feddfef4", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn purple() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Purple", - light: [ - "#fefcfeff", - "#fbf7feff", - "#f7edfeff", - "#f2e2fcff", - "#ead5f9ff", - "#e0c4f4ff", - "#d1afecff", - "#be93e4ff", - "#8e4ec6ff", - "#8347b9ff", - "#8145b5ff", - "#402060ff", - ], - light_alpha: [ - "#aa00aa03", - "#8000e008", - "#8e00f112", - "#8d00e51d", - "#8000db2a", - "#7a01d03b", - "#6d00c350", - "#6600c06c", - "#5c00adb1", - "#53009eb8", - "#52009aba", - "#250049df", - ], - dark: [ - "#18111bff", - "#1e1523ff", - "#301c3bff", - "#3d224eff", - "#48295cff", - "#54346bff", - "#664282ff", - "#8457aaff", - "#8e4ec6ff", - "#9a5cd0ff", - "#d19dffff", - "#ecd9faff", - ], - dark_alpha: [ - "#b412f90b", - "#b744f714", - "#c150ff2d", - "#bb53fd42", - "#be5cfd51", - "#c16dfd61", - "#c378fd7a", - "#c47effa4", - "#b661ffc2", - "#bc6fffcd", - "#d19dffff", - "#f1ddfffa", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn violet() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Violet", - light: [ - "#fdfcfeff", - "#faf8ffff", - "#f4f0feff", - "#ebe4ffff", - "#e1d9ffff", - "#d4cafeff", - "#c2b5f5ff", - "#aa99ecff", - "#6e56cfff", - "#654dc4ff", - "#6550b9ff", - "#2f265fff", - ], - light_alpha: [ - "#5500aa03", - "#4900ff07", - "#4400ee0f", - "#4300ff1b", - "#3600ff26", - "#3100fb35", - "#2d01dd4a", - "#2b00d066", - "#2400b7a9", - "#2300abb2", - "#1f0099af", - "#0b0043d9", - ], - dark: [ - "#14121fff", - "#1b1525ff", - "#291f43ff", - "#33255bff", - "#3c2e69ff", - "#473876ff", - "#56468bff", - "#6958adff", - "#6e56cfff", - "#7d66d9ff", - "#baa7ffff", - "#e2ddfeff", - ], - dark_alpha: [ - "#4422ff0f", - "#853ff916", - "#8354fe36", - "#7d51fd50", - "#845ffd5f", - "#8f6cfd6d", - "#9879ff83", - "#977dfea8", - "#8668ffcc", - "#9176fed7", - "#baa7ffff", - "#e3defffe", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn iris() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Iris", - light: [ - "#fdfdffff", - "#f8f8ffff", - "#f0f1feff", - "#e6e7ffff", - "#dadcffff", - "#cbcdffff", - "#b8baf8ff", - "#9b9ef0ff", - "#5b5bd6ff", - "#5151cdff", - "#5753c6ff", - "#272962ff", - ], - light_alpha: [ - "#0000ff02", - "#0000ff07", - "#0011ee0f", - "#000bff19", - "#000eff25", - "#000aff34", - "#0008e647", - "#0008d964", - "#0000c0a4", - "#0000b6ae", - "#0600abac", - "#000246d8", - ], - dark: [ - "#13131eff", - "#171625ff", - "#202248ff", - "#262a65ff", - "#303374ff", - "#3d3e82ff", - "#4a4a95ff", - "#5958b1ff", - "#5b5bd6ff", - "#6e6adeff", - "#b1a9ffff", - "#e0dffeff", - ], - dark_alpha: [ - "#3636fe0e", - "#564bf916", - "#525bff3b", - "#4d58ff5a", - "#5b62fd6b", - "#6d6ffd7a", - "#7777fe8e", - "#7b7afeac", - "#6a6afed4", - "#7d79ffdc", - "#b1a9ffff", - "#e1e0fffe", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn indigo() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Indigo", - light: [ - "#fdfdfeff", - "#f7f9ffff", - "#edf2feff", - "#e1e9ffff", - "#d2deffff", - "#c1d0ffff", - "#abbdf9ff", - "#8da4efff", - "#3e63ddff", - "#3358d4ff", - "#3a5bc7ff", - "#1f2d5cff", - ], - light_alpha: [ - "#00008002", - "#0040ff08", - "#0047f112", - "#0044ff1e", - "#0044ff2d", - "#003eff3e", - "#0037ed54", - "#0034dc72", - "#0031d2c1", - "#002ec9cc", - "#002bb7c5", - "#001046e0", - ], - dark: [ - "#11131fff", - "#141726ff", - "#182449ff", - "#1d2e62ff", - "#253974ff", - "#304384ff", - "#3a4f97ff", - "#435db1ff", - "#3e63ddff", - "#5472e4ff", - "#9eb1ffff", - "#d6e1ffff", - ], - dark_alpha: [ - "#1133ff0f", - "#3354fa17", - "#2f62ff3c", - "#3566ff57", - "#4171fd6b", - "#5178fd7c", - "#5a7fff90", - "#5b81feac", - "#4671ffdb", - "#5c7efee3", - "#9eb1ffff", - "#d6e1ffff", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn blue() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Blue", - light: [ - "#fbfdffff", - "#f4faffff", - "#e6f4feff", - "#d5efffff", - "#c2e5ffff", - "#acd8fcff", - "#8ec8f6ff", - "#5eb1efff", - "#0090ffff", - "#0588f0ff", - "#0d74ceff", - "#113264ff", - ], - light_alpha: [ - "#0080ff04", - "#008cff0b", - "#008ff519", - "#009eff2a", - "#0093ff3d", - "#0088f653", - "#0083eb71", - "#0084e6a1", - "#0090ffff", - "#0086f0fa", - "#006dcbf2", - "#002359ee", - ], - dark: [ - "#0d1520ff", - "#111927ff", - "#0d2847ff", - "#003362ff", - "#004074ff", - "#104d87ff", - "#205d9eff", - "#2870bdff", - "#0090ffff", - "#3b9effff", - "#70b8ffff", - "#c2e6ffff", - ], - dark_alpha: [ - "#004df211", - "#1166fb18", - "#0077ff3a", - "#0075ff57", - "#0081fd6b", - "#0f89fd7f", - "#2a91fe98", - "#3094feb9", - "#0090ffff", - "#3b9effff", - "#70b8ffff", - "#c2e6ffff", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn cyan() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Cyan", - light: [ - "#fafdfeff", - "#f2fafbff", - "#def7f9ff", - "#caf1f6ff", - "#b5e9f0ff", - "#9ddde7ff", - "#7dcedcff", - "#3db9cfff", - "#00a2c7ff", - "#0797b9ff", - "#107d98ff", - "#0d3c48ff", - ], - light_alpha: [ - "#0099cc05", - "#009db10d", - "#00c2d121", - "#00bcd435", - "#01b4cc4a", - "#00a7c162", - "#009fbb82", - "#00a3c0c2", - "#00a2c7ff", - "#0094b7f8", - "#007491ef", - "#00323ef2", - ], - dark: [ - "#0b161aff", - "#101b20ff", - "#082c36ff", - "#003848ff", - "#004558ff", - "#045468ff", - "#12677eff", - "#11809cff", - "#00a2c7ff", - "#23afd0ff", - "#4ccce6ff", - "#b6ecf7ff", - ], - dark_alpha: [ - "#0091f70a", - "#02a7f211", - "#00befd28", - "#00baff3b", - "#00befd4d", - "#00c7fd5e", - "#14cdff75", - "#11cfff95", - "#00cfffc3", - "#28d6ffcd", - "#52e1fee5", - "#bbf3fef7", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn teal() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Teal", - light: [ - "#fafefdff", - "#f3fbf9ff", - "#e0f8f3ff", - "#ccf3eaff", - "#b8eae0ff", - "#a1ded2ff", - "#83cdc1ff", - "#53b9abff", - "#12a594ff", - "#0d9b8aff", - "#008573ff", - "#0d3d38ff", - ], - light_alpha: [ - "#00cc9905", - "#00aa800c", - "#00c69d1f", - "#00c39633", - "#00b49047", - "#00a6855e", - "#0099807c", - "#009783ac", - "#009e8ced", - "#009684f2", - "#008573ff", - "#00332df2", - ], - dark: [ - "#0d1514ff", - "#111c1bff", - "#0d2d2aff", - "#023b37ff", - "#084843ff", - "#145750ff", - "#1c6961ff", - "#207e73ff", - "#12a594ff", - "#0eb39eff", - "#0bd8b6ff", - "#adf0ddff", - ], - dark_alpha: [ - "#00deab05", - "#12fbe60c", - "#00ffe61e", - "#00ffe92d", - "#00ffea3b", - "#1cffe84b", - "#2efde85f", - "#32ffe775", - "#13ffe49f", - "#0dffe0ae", - "#0afed5d6", - "#b8ffebef", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn jade() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Jade", - light: [ - "#fbfefdff", - "#f4fbf7ff", - "#e6f7edff", - "#d6f1e3ff", - "#c3e9d7ff", - "#acdec8ff", - "#8bceb6ff", - "#56ba9fff", - "#29a383ff", - "#26997bff", - "#208368ff", - "#1d3b31ff", - ], - light_alpha: [ - "#00c08004", - "#00a3460b", - "#00ae4819", - "#00a85129", - "#00a2553c", - "#009a5753", - "#00945f74", - "#00976ea9", - "#00916bd6", - "#008764d9", - "#007152df", - "#002217e2", - ], - dark: [ - "#0d1512ff", - "#121c18ff", - "#0f2e22ff", - "#0b3b2cff", - "#114837ff", - "#1b5745ff", - "#246854ff", - "#2a7e68ff", - "#29a383ff", - "#27b08bff", - "#1fd8a4ff", - "#adf0d4ff", - ], - dark_alpha: [ - "#00de4505", - "#27fba60c", - "#02f99920", - "#00ffaa2d", - "#11ffb63b", - "#34ffc24b", - "#45fdc75e", - "#48ffcf75", - "#38feca9d", - "#31fec7ab", - "#21fec0d6", - "#b8ffe1ef", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn green() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Green", - light: [ - "#fbfefcff", - "#f4fbf6ff", - "#e6f6ebff", - "#d6f1dfff", - "#c4e8d1ff", - "#adddc0ff", - "#8eceaaff", - "#5bb98bff", - "#30a46cff", - "#2b9a66ff", - "#218358ff", - "#193b2dff", - ], - light_alpha: [ - "#00c04004", - "#00a32f0b", - "#00a43319", - "#00a83829", - "#019c393b", - "#00963c52", - "#00914071", - "#00924ba4", - "#008f4acf", - "#008647d4", - "#00713fde", - "#002616e6", - ], - dark: [ - "#0e1512ff", - "#121b17ff", - "#132d21ff", - "#113b29ff", - "#174933ff", - "#20573eff", - "#28684aff", - "#2f7c57ff", - "#30a46cff", - "#33b074ff", - "#3dd68cff", - "#b1f1cbff", - ], - dark_alpha: [ - "#00de4505", - "#29f99d0b", - "#22ff991e", - "#11ff992d", - "#2bffa23c", - "#44ffaa4b", - "#50fdac5e", - "#54ffad73", - "#44ffa49e", - "#43fea4ab", - "#46fea5d4", - "#bbffd7f0", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn grass() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Grass", - light: [ - "#fbfefbff", - "#f5fbf5ff", - "#e9f6e9ff", - "#daf1dbff", - "#c9e8caff", - "#b2ddb5ff", - "#94ce9aff", - "#65ba74ff", - "#46a758ff", - "#3e9b4fff", - "#2a7e3bff", - "#203c25ff", - ], - light_alpha: [ - "#00c00004", - "#0099000a", - "#00970016", - "#009f0725", - "#00930536", - "#008f0a4d", - "#018b0f6b", - "#008d199a", - "#008619b9", - "#007b17c1", - "#006514d5", - "#002006df", - ], - dark: [ - "#0e1511ff", - "#141a15ff", - "#1b2a1eff", - "#1d3a24ff", - "#25482dff", - "#2d5736ff", - "#366740ff", - "#3e7949ff", - "#46a758ff", - "#53b365ff", - "#71d083ff", - "#c2f0c2ff", - ], - dark_alpha: [ - "#00de1205", - "#5ef7780a", - "#70fe8c1b", - "#57ff802c", - "#68ff8b3b", - "#71ff8f4b", - "#77fd925d", - "#77fd9070", - "#65ff82a1", - "#72ff8dae", - "#89ff9fcd", - "#ceffceef", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn lime() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Lime", - light: [ - "#fcfdfaff", - "#f8faf3ff", - "#eef6d6ff", - "#e2f0bdff", - "#d3e7a6ff", - "#c2da91ff", - "#abc978ff", - "#8db654ff", - "#bdee63ff", - "#b0e64cff", - "#5c7c2fff", - "#37401cff", - ], - light_alpha: [ - "#66990005", - "#6b95000c", - "#96c80029", - "#8fc60042", - "#81bb0059", - "#72aa006e", - "#61990087", - "#559200ab", - "#93e4009c", - "#8fdc00b3", - "#375f00d0", - "#1e2900e3", - ], - dark: [ - "#11130cff", - "#151a10ff", - "#1f2917ff", - "#29371dff", - "#334423ff", - "#3d522aff", - "#496231ff", - "#577538ff", - "#bdee63ff", - "#d4ff70ff", - "#bde56cff", - "#e3f7baff", - ], - dark_alpha: [ - "#11bb0003", - "#78f7000a", - "#9bfd4c1a", - "#a7fe5c29", - "#affe6537", - "#b2fe6d46", - "#b6ff6f57", - "#b6fd6d6c", - "#caff69ed", - "#d4ff70ff", - "#d1fe77e4", - "#e9febff7", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn mint() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Mint", - light: [ - "#f9fefdff", - "#f2fbf9ff", - "#ddf9f2ff", - "#c8f4e9ff", - "#b3ecdeff", - "#9ce0d0ff", - "#7ecfbdff", - "#4cbba5ff", - "#86ead4ff", - "#7de0cbff", - "#027864ff", - "#16433cff", - ], - light_alpha: [ - "#00d5aa06", - "#00b18a0d", - "#00d29e22", - "#00cc9937", - "#00c0914c", - "#00b08663", - "#00a17d81", - "#009e7fb3", - "#00d3a579", - "#00c39982", - "#007763fd", - "#00312ae9", - ], - dark: [ - "#0e1515ff", - "#0f1b1bff", - "#092c2bff", - "#003a38ff", - "#004744ff", - "#105650ff", - "#1e685fff", - "#277f70ff", - "#86ead4ff", - "#a8f5e5ff", - "#58d5baff", - "#c4f5e1ff", - ], - dark_alpha: [ - "#00dede05", - "#00f9f90b", - "#00fff61d", - "#00fff42c", - "#00fff23a", - "#0effeb4a", - "#34fde55e", - "#41ffdf76", - "#92ffe7e9", - "#aefeedf5", - "#67ffded2", - "#cbfee9f5", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn sky() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Sky", - light: [ - "#f9feffff", - "#f1fafdff", - "#e1f6fdff", - "#d1f0faff", - "#bee7f5ff", - "#a9daedff", - "#8dcae3ff", - "#60b3d7ff", - "#7ce2feff", - "#74daf8ff", - "#00749eff", - "#1d3e56ff", - ], - light_alpha: [ - "#00d5ff06", - "#00a4db0e", - "#00b3ee1e", - "#00ace42e", - "#00a1d841", - "#0092ca56", - "#0089c172", - "#0085bf9f", - "#00c7fe83", - "#00bcf38b", - "#00749eff", - "#002540e2", - ], - dark: [ - "#0d141fff", - "#111a27ff", - "#112840ff", - "#113555ff", - "#154467ff", - "#1b537bff", - "#1f6692ff", - "#197caeff", - "#7ce2feff", - "#a8eeffff", - "#75c7f0ff", - "#c2f3ffff", - ], - dark_alpha: [ - "#0044ff0f", - "#1171fb18", - "#1184fc33", - "#128fff49", - "#1c9dfd5d", - "#28a5ff72", - "#2badfe8b", - "#1db2fea9", - "#7ce3fffe", - "#a8eeffff", - "#7cd3ffef", - "#c2f3ffff", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn black() -> ColorScaleSet { - StaticColorScaleSet { - scale: "Black", - light: [ - "#0000000d", - "#0000001a", - "#00000026", - "#00000033", - "#0000004d", - "#00000066", - "#00000080", - "#00000099", - "#000000b3", - "#000000cc", - "#000000e6", - "#000000f2", - ], - light_alpha: [ - "#0000000d", - "#0000001a", - "#00000026", - "#00000033", - "#0000004d", - "#00000066", - "#00000080", - "#00000099", - "#000000b3", - "#000000cc", - "#000000e6", - "#000000f2", - ], - dark: [ - "#0000000d", - "#0000001a", - "#00000026", - "#00000033", - "#0000004d", - "#00000066", - "#00000080", - "#00000099", - "#000000b3", - "#000000cc", - "#000000e6", - "#000000f2", - ], - dark_alpha: [ - "#0000000d", - "#0000001a", - "#00000026", - "#00000033", - "#0000004d", - "#00000066", - "#00000080", - "#00000099", - "#000000b3", - "#000000cc", - "#000000e6", - "#000000f2", - ], - } - .try_into() - .unwrap() -} - -pub(crate) fn white() -> ColorScaleSet { - StaticColorScaleSet { - scale: "White", - light: [ - "#ffffff0d", - "#ffffff1a", - "#ffffff26", - "#ffffff33", - "#ffffff4d", - "#ffffff66", - "#ffffff80", - "#ffffff99", - "#ffffffb3", - "#ffffffcc", - "#ffffffe6", - "#fffffff2", - ], - light_alpha: [ - "#ffffff0d", - "#ffffff1a", - "#ffffff26", - "#ffffff33", - "#ffffff4d", - "#ffffff66", - "#ffffff80", - "#ffffff99", - "#ffffffb3", - "#ffffffcc", - "#ffffffe6", - "#fffffff2", - ], - dark: [ - "#ffffff0d", - "#ffffff1a", - "#ffffff26", - "#ffffff33", - "#ffffff4d", - "#ffffff66", - "#ffffff80", - "#ffffff99", - "#ffffffb3", - "#ffffffcc", - "#ffffffe6", - "#fffffff2", - ], - dark_alpha: [ - "#ffffff0d", - "#ffffff1a", - "#ffffff26", - "#ffffff33", - "#ffffff4d", - "#ffffff66", - "#ffffff80", - "#ffffff99", - "#ffffffb3", - "#ffffffcc", - "#ffffffe6", - "#fffffff2", - ], - } - .try_into() - .unwrap() -} diff --git a/crates/theme/src/geometry.rs b/crates/theme/src/geometry.rs index bd020653..10ed548c 100644 --- a/crates/theme/src/geometry.rs +++ b/crates/theme/src/geometry.rs @@ -1,57 +1,9 @@ -use std::fmt::{self, Debug, Display, Formatter}; +use std::fmt::Debug; -use gpui::{AbsoluteLength, Axis, Length, Pixels}; +use gpui::Axis; use serde::{Deserialize, Serialize}; -/// A enum for defining the placement of the element. -/// -/// See also: [`Side`] if you need to define the left, right side. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] -pub enum Placement { - #[serde(rename = "top")] - Top, - #[serde(rename = "bottom")] - Bottom, - #[serde(rename = "left")] - Left, - #[serde(rename = "right")] - Right, -} - -impl Display for Placement { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self { - Placement::Top => write!(f, "Top"), - Placement::Bottom => write!(f, "Bottom"), - Placement::Left => write!(f, "Left"), - Placement::Right => write!(f, "Right"), - } - } -} - -impl Placement { - #[inline] - pub fn is_horizontal(&self) -> bool { - matches!(self, Placement::Left | Placement::Right) - } - - #[inline] - pub fn is_vertical(&self) -> bool { - matches!(self, Placement::Top | Placement::Bottom) - } - - #[inline] - pub fn axis(&self) -> Axis { - match self { - Placement::Top | Placement::Bottom => Axis::Vertical, - Placement::Left | Placement::Right => Axis::Horizontal, - } - } -} - /// A enum for defining the side of the element. -/// -/// See also: [`Placement`] if you need to define the 4 edges. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum Side { #[serde(rename = "left")] @@ -94,39 +46,6 @@ impl AxisExt for Axis { } } -/// A trait for converting [`Pixels`] to `f32` and `f64`. -pub trait PixelsExt { - fn as_f32(&self) -> f32; - #[allow(clippy::wrong_self_convention)] - fn as_f64(self) -> f64; -} -impl PixelsExt for Pixels { - fn as_f32(&self) -> f32 { - f32::from(self) - } - - fn as_f64(self) -> f64 { - f64::from(self) - } -} - -/// A trait to extend the [`Length`] enum with utility methods. -pub trait LengthExt { - /// Converts the [`Length`] to [`Pixels`] based on a given `base_size` and `rem_size`. - /// - /// If the [`Length`] is [`Length::Auto`], it returns `None`. - fn to_pixels(&self, base_size: AbsoluteLength, rem_size: Pixels) -> Option; -} - -impl LengthExt for Length { - fn to_pixels(&self, base_size: AbsoluteLength, rem_size: Pixels) -> Option { - match self { - Length::Auto => None, - Length::Definite(len) => Some(len.to_pixels(base_size, rem_size)), - } - } -} - /// A struct for defining the edges of an element. /// /// A extend version of [`gpui::Edges`] to serialize/deserialize. @@ -142,18 +61,3 @@ pub struct Edges { /// The size of the left edge. pub left: T, } - -impl Edges -where - T: Clone + Debug + Default + PartialEq, -{ - /// Creates a new `Edges` instance with all edges set to the same value. - pub fn all(value: T) -> Self { - Self { - top: value.clone(), - right: value.clone(), - bottom: value.clone(), - left: value, - } - } -} diff --git a/crates/theme/src/lib.rs b/crates/theme/src/lib.rs index e21198f1..1bbaee9f 100644 --- a/crates/theme/src/lib.rs +++ b/crates/theme/src/lib.rs @@ -31,7 +31,7 @@ pub const CLIENT_SIDE_DECORATION_SHADOW: Pixels = px(10.0); pub const CLIENT_SIDE_DECORATION_BORDER: Pixels = px(1.0); /// Defines window titlebar height -pub const TITLEBAR_HEIGHT: Pixels = px(36.0); +pub(crate) const TITLEBAR_HEIGHT: Pixels = px(36.0); /// Defines workspace tabbar height pub const TABBAR_HEIGHT: Pixels = px(36.0); @@ -145,9 +145,6 @@ pub struct Theme { /// Notification settings pub notification: NotificationSettings, - - /// Platform kind - pub platform: PlatformKind, } impl Deref for Theme { @@ -173,7 +170,7 @@ impl Theme { } /// Returns the global theme mutable reference - pub fn global_mut(cx: &mut App) -> &mut Theme { + pub(crate) fn global_mut(cx: &mut App) -> &mut Theme { cx.global_mut::() } @@ -274,7 +271,6 @@ impl From for Theme { mode, colors: *colors, theme: Rc::new(family), - platform, } } } diff --git a/crates/theme/src/platform_kind.rs b/crates/theme/src/platform_kind.rs index afc545a2..a38151e8 100644 --- a/crates/theme/src/platform_kind.rs +++ b/crates/theme/src/platform_kind.rs @@ -18,16 +18,4 @@ impl PlatformKind { Self::Web } } - - pub fn is_linux(&self) -> bool { - matches!(self, Self::Linux) - } - - pub fn is_windows(&self) -> bool { - matches!(self, Self::Windows) - } - - pub fn is_mac(&self) -> bool { - matches!(self, Self::Mac) - } } diff --git a/crates/theme/src/scale.rs b/crates/theme/src/scale.rs index 444db1f9..4359a5bd 100644 --- a/crates/theme/src/scale.rs +++ b/crates/theme/src/scale.rs @@ -1,6 +1,4 @@ -#![allow(dead_code)] - -use gpui::{Hsla, SharedString}; +use gpui::Hsla; /// A collection of colors that are used to style the UI. /// @@ -9,21 +7,6 @@ use gpui::{Hsla, SharedString}; pub struct ColorScaleStep(usize); impl ColorScaleStep { - /// All of the steps in a [`ColorScale`]. - pub const ALL: [ColorScaleStep; 12] = [ - Self::ONE, - Self::TWO, - Self::THREE, - Self::FOUR, - Self::FIVE, - Self::SIX, - Self::SEVEN, - Self::EIGHT, - Self::NINE, - Self::TEN, - Self::ELEVEN, - Self::TWELVE, - ]; pub const EIGHT: Self = Self(8); pub const ELEVEN: Self = Self(11); pub const FIVE: Self = Self(5); @@ -153,89 +136,8 @@ impl ColorScale { } } -pub struct ColorScales { - pub gray: ColorScaleSet, - pub mauve: ColorScaleSet, - pub slate: ColorScaleSet, - pub sage: ColorScaleSet, - pub olive: ColorScaleSet, - pub sand: ColorScaleSet, - pub gold: ColorScaleSet, - pub bronze: ColorScaleSet, - pub brown: ColorScaleSet, - pub yellow: ColorScaleSet, - pub amber: ColorScaleSet, - pub orange: ColorScaleSet, - pub tomato: ColorScaleSet, - pub red: ColorScaleSet, - pub ruby: ColorScaleSet, - pub crimson: ColorScaleSet, - pub pink: ColorScaleSet, - pub plum: ColorScaleSet, - pub purple: ColorScaleSet, - pub violet: ColorScaleSet, - pub iris: ColorScaleSet, - pub indigo: ColorScaleSet, - pub blue: ColorScaleSet, - pub cyan: ColorScaleSet, - pub teal: ColorScaleSet, - pub jade: ColorScaleSet, - pub green: ColorScaleSet, - pub grass: ColorScaleSet, - pub lime: ColorScaleSet, - pub mint: ColorScaleSet, - pub sky: ColorScaleSet, - pub black: ColorScaleSet, - pub white: ColorScaleSet, -} - -impl IntoIterator for ColorScales { - type IntoIter = std::vec::IntoIter; - type Item = ColorScaleSet; - - fn into_iter(self) -> Self::IntoIter { - vec![ - self.gray, - self.mauve, - self.slate, - self.sage, - self.olive, - self.sand, - self.gold, - self.bronze, - self.brown, - self.yellow, - self.amber, - self.orange, - self.tomato, - self.red, - self.ruby, - self.crimson, - self.pink, - self.plum, - self.purple, - self.violet, - self.iris, - self.indigo, - self.blue, - self.cyan, - self.teal, - self.jade, - self.green, - self.grass, - self.lime, - self.mint, - self.sky, - self.black, - self.white, - ] - .into_iter() - } -} - /// Provides groups of [`ColorScale`]s for light and dark themes, as well as transparent versions of each scale. pub struct ColorScaleSet { - name: SharedString, light: ColorScale, dark: ColorScale, light_alpha: ColorScale, @@ -243,15 +145,13 @@ pub struct ColorScaleSet { } impl ColorScaleSet { - pub fn new( - name: impl Into, + pub(crate) fn new( light: ColorScale, light_alpha: ColorScale, dark: ColorScale, dark_alpha: ColorScale, ) -> Self { Self { - name: name.into(), light, light_alpha, dark, @@ -259,23 +159,19 @@ impl ColorScaleSet { } } - pub fn name(&self) -> &SharedString { - &self.name - } - - pub fn light(&self) -> &ColorScale { + pub(crate) fn light(&self) -> &ColorScale { &self.light } - pub fn light_alpha(&self) -> &ColorScale { + pub(crate) fn light_alpha(&self) -> &ColorScale { &self.light_alpha } - pub fn dark(&self) -> &ColorScale { + pub(crate) fn dark(&self) -> &ColorScale { &self.dark } - pub fn dark_alpha(&self) -> &ColorScale { + pub(crate) fn dark_alpha(&self) -> &ColorScale { &self.dark_alpha } } diff --git a/crates/theme/src/scrollbar_mode.rs b/crates/theme/src/scrollbar_mode.rs index e9fbf769..b1e4e319 100644 --- a/crates/theme/src/scrollbar_mode.rs +++ b/crates/theme/src/scrollbar_mode.rs @@ -13,12 +13,4 @@ impl ScrollbarMode { pub fn is_scrolling(&self) -> bool { matches!(self, Self::Scrolling) } - - pub fn is_hover(&self) -> bool { - matches!(self, Self::Hover) - } - - pub fn is_always(&self) -> bool { - matches!(self, Self::Always) - } } diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index ab7da1ed..3d48f359 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -117,7 +117,7 @@ impl ThemeFamily { /// # Ok(()) /// # } /// ``` - pub fn from_file>(path: P) -> anyhow::Result { + pub(crate) fn from_file>(path: P) -> anyhow::Result { let json_data = std::fs::read(path)?; let theme_family = serde_json::from_slice(&json_data)?; diff --git a/crates/ui/Cargo.toml b/crates/ui/Cargo.toml index 5e0c6c5f..05f32c64 100644 --- a/crates/ui/Cargo.toml +++ b/crates/ui/Cargo.toml @@ -5,7 +5,6 @@ edition.workspace = true publish.workspace = true [dependencies] -common = { path = "../common" } theme = { path = "../theme" } gpui.workspace = true @@ -13,6 +12,5 @@ gpui-base.workspace = true instant.workspace = true serde.workspace = true smallvec.workspace = true -log.workspace = true uuid = "1.10" diff --git a/crates/ui/src/avatar.rs b/crates/ui/src/avatar.rs index f4bbceab..52e6f422 100644 --- a/crates/ui/src/avatar.rs +++ b/crates/ui/src/avatar.rs @@ -391,18 +391,6 @@ impl Avatar { self.seed = Some(seed.into()); self } - - /// Applies a grayscale filter to the avatar image. - pub fn grayscale(mut self, grayscale: bool) -> Self { - self.grayscale = grayscale; - self - } - - /// Sets the border color of the avatar. - pub fn border_color(mut self, color: impl Into) -> Self { - self.border_color = Some(color.into()); - self - } } impl Sizable for Avatar { diff --git a/crates/ui/src/button.rs b/crates/ui/src/button.rs index 1add51af..5ed81266 100644 --- a/crates/ui/src/button.rs +++ b/crates/ui/src/button.rs @@ -208,12 +208,6 @@ impl Button { self } - /// Set true to show the indicator. - pub fn indicator(mut self) -> Self { - self.indicator = true; - self - } - /// Add click handler. pub fn on_click( mut self, @@ -223,20 +217,6 @@ impl Button { self } - /// Add hover handler, the bool parameter indicates whether the mouse is hovering. - pub fn on_hover(mut self, handler: impl Fn(&bool, &mut Window, &mut App) + 'static) -> Self { - self.on_hover = Some(Rc::new(handler)); - self - } - - /// Set the tab index of the button, it will be used to focus the button by tab key. - /// - /// Default is 0. - pub fn tab_index(mut self, tab_index: isize) -> Self { - self.tab_index = tab_index; - self - } - /// Set the tab stop of the button, if true, the button will be focusable by tab key. /// /// Default is true. diff --git a/crates/ui/src/dialog.rs b/crates/ui/src/dialog.rs index f63dffd5..16eeff21 100644 --- a/crates/ui/src/dialog.rs +++ b/crates/ui/src/dialog.rs @@ -58,12 +58,6 @@ impl DialogButtonProps { self.cancel_text = Some(cancel_text.into()); self } - - /// Sets the variant of the Cancel button. Default is `ButtonVariant::default()`. - pub fn cancel_variant(mut self, cancel_variant: ButtonVariant) -> Self { - self.cancel_variant = cancel_variant; - self - } } #[derive(IntoElement)] @@ -145,23 +139,12 @@ impl Dialog { } /// Set to use confirm dialog, with OK and Cancel buttons. - /// - /// See also [`Self::alert`] pub fn confirm(self) -> Self { self.footer(|ok, cancel, window, cx| vec![cancel(window, cx), ok(window, cx)]) .overlay_closable(false) .show_close(false) } - /// Set to as a alter dialog, with OK button. - /// - /// See also [`Self::confirm`] - pub fn alert(self) -> Self { - self.footer(|ok, _, window, cx| vec![ok(window, cx)]) - .overlay_closable(false) - .show_close(false) - } - /// Set the button props of the dialog. pub fn button_props(mut self, button_props: DialogButtonProps) -> Self { self.button_props = button_props; @@ -207,30 +190,12 @@ impl Dialog { self } - /// Shift the dialog down from the window centre, defaults to `None`. - pub fn margin_top(mut self, margin_top: Pixels) -> Self { - self.margin_top = Some(margin_top); - self - } - /// Sets the width of the dialog, defaults to 480px. pub fn width(mut self, width: Pixels) -> Self { self.width = width; self } - /// Set the maximum width of the dialog, defaults to `None`. - pub fn max_w(mut self, max_width: Pixels) -> Self { - self.max_width = Some(max_width); - self - } - - /// Set the overlay of the dialog, defaults to `true`. - pub fn overlay(mut self, overlay: bool) -> Self { - self.overlay = overlay; - self - } - /// Set the overlay closable of the dialog, defaults to `true`. /// /// When the overlay is clicked, the dialog will be closed. diff --git a/crates/ui/src/group_box.rs b/crates/ui/src/group_box.rs index 031dc1f4..92696438 100644 --- a/crates/ui/src/group_box.rs +++ b/crates/ui/src/group_box.rs @@ -1,14 +1,12 @@ -use std::str::FromStr; - use gpui::prelude::FluentBuilder; use gpui::{ - div, relative, AnyElement, App, ElementId, InteractiveElement as _, IntoElement, ParentElement, - RenderOnce, StyleRefinement, Styled, Window, + AnyElement, App, ElementId, InteractiveElement as _, IntoElement, ParentElement, RenderOnce, + StyleRefinement, Styled, Window, div, relative, }; use smallvec::SmallVec; use theme::ActiveTheme; -use crate::{v_flex, StyledExt as _}; +use crate::{StyledExt as _, v_flex}; /// The variant of the GroupBox. #[derive(Debug, Clone, Default, Copy, PartialEq, Eq, Hash)] @@ -37,27 +35,6 @@ pub trait GroupBoxVariants: Sized { } } -impl GroupBoxVariant { - /// Convert the GroupBoxVariant to a string. - pub const fn as_str(&self) -> &str { - match self { - GroupBoxVariant::Normal => "normal", - GroupBoxVariant::Fill => "fill", - } - } -} - -impl FromStr for GroupBoxVariant { - type Err = (); - - fn from_str(s: &str) -> Result { - match s.to_lowercase().as_str() { - "fill" => Ok(GroupBoxVariant::Fill), - _ => Ok(GroupBoxVariant::Normal), - } - } -} - /// GroupBox is a styled container element that with /// an optional title to groups related content together. #[derive(IntoElement)] @@ -98,20 +75,6 @@ impl GroupBox { self.title = Some(title.into_any_element()); self } - - /// Set the style of the title of the group box to override the default style, default is None. - #[must_use] - pub fn title_style(mut self, style: StyleRefinement) -> Self { - self.title_style = style; - self - } - - /// Set the style of the content of the group box to override the default style, default is None. - #[must_use] - pub fn content_style(mut self, style: StyleRefinement) -> Self { - self.content_style = style; - self - } } impl Default for GroupBox { diff --git a/crates/ui/src/icon.rs b/crates/ui/src/icon.rs index b2642e6a..f0c3cb7e 100644 --- a/crates/ui/src/icon.rs +++ b/crates/ui/src/icon.rs @@ -1,19 +1,14 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ - AnyElement, App, AppContext, Context, Entity, Hsla, IntoElement, Radians, Render, RenderOnce, - SharedString, StyleRefinement, Styled, Svg, Transformation, Window, svg, + AnyElement, App, Context, Hsla, IntoElement, Radians, Render, RenderOnce, SharedString, + StyleRefinement, Styled, Svg, Transformation, Window, svg, }; use theme::ActiveTheme; use crate::{Sizable, Size}; -pub trait IconNamed { - /// Returns the embedded path of the icon. - fn path(self) -> SharedString; -} - -impl From for Icon { - fn from(value: T) -> Self { +impl From for Icon { + fn from(value: IconName) -> Self { Icon::build(value) } } @@ -95,13 +90,6 @@ pub enum IconName { } impl IconName { - /// Return the icon as a Entity - pub fn view(self, cx: &mut App) -> Entity { - Icon::build(self).view(cx) - } -} - -impl IconNamed for IconName { fn path(self) -> SharedString { match self { Self::ArrowLeft => "icons/arrow-left.svg", @@ -232,7 +220,7 @@ impl Icon { icon.into() } - fn build(name: impl IconNamed) -> Self { + fn build(name: IconName) -> Self { Self::default().path(name.path()) } @@ -244,11 +232,6 @@ impl Icon { self } - /// Create a new view for the icon - pub fn view(self, cx: &mut App) -> Entity { - cx.new(|_| self) - } - pub fn transform(mut self, transformation: gpui::Transformation) -> Self { self.base = self.base.with_transformation(transformation); self @@ -257,14 +240,6 @@ impl Icon { pub fn empty() -> Self { Self::default() } - - /// Rotate the icon by the given angle - pub fn rotate(mut self, radians: impl Into) -> Self { - self.base = self - .base - .with_transformation(Transformation::rotate(radians)); - self - } } impl Styled for Icon { diff --git a/crates/ui/src/indicator.rs b/crates/ui/src/indicator.rs index f6065599..6b144d39 100644 --- a/crates/ui/src/indicator.rs +++ b/crates/ui/src/indicator.rs @@ -1,10 +1,9 @@ -use instant::Duration; - use gpui::prelude::FluentBuilder as _; use gpui::{ - div, ease_in_out, percentage, Animation, AnimationExt as _, App, Hsla, IntoElement, - ParentElement, RenderOnce, Styled as _, Transformation, Window, + Animation, AnimationExt as _, App, Hsla, IntoElement, ParentElement, RenderOnce, Styled as _, + Transformation, Window, div, ease_in_out, percentage, }; +use instant::Duration; use crate::{Icon, IconName, Sizable, Size}; @@ -26,11 +25,6 @@ impl Indicator { } } - pub fn icon(mut self, icon: impl Into) -> Self { - self.icon = icon.into(); - self - } - pub fn color(mut self, color: Hsla) -> Self { self.color = Some(color); self diff --git a/crates/ui/src/input/input.rs b/crates/ui/src/input/input.rs index d9dddd32..ac47efe3 100644 --- a/crates/ui/src/input/input.rs +++ b/crates/ui/src/input/input.rs @@ -2,7 +2,7 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ AnyElement, App, DefiniteLength, Edges, Entity, Hsla, InteractiveElement as _, IntoElement, MouseButton, ParentElement as _, Pixels, Rems, RenderOnce, StyleRefinement, Styled, TextAlign, - Window, div, px, relative, + Window, div, px, }; use gpui_base::InputBase; use gpui_base::input::{InputBaseState, InputEditorStyle, InputMode, InputModeKind, TextareaMode}; @@ -134,18 +134,6 @@ impl Input { self } - /// Set full height of the input (Multi-line only). - pub fn h_full(mut self) -> Self { - self.height = Some(relative(1.)); - self - } - - /// Set height of the input (Multi-line only). - pub fn h(mut self, height: impl Into) -> Self { - self.height = Some(height.into()); - self - } - /// Set the appearance of the input field, if false the input field will no border, background. pub fn appearance(mut self, appearance: bool) -> Self { self.appearance = appearance; @@ -158,24 +146,12 @@ impl Input { self } - /// Set to enable toggle button for password mask state. - pub fn mask_toggle(mut self) -> Self { - self.mask_toggle = true; - self - } - /// Set to disable the input field. pub fn disabled(mut self, disabled: bool) -> Self { self.disabled = disabled; self } - /// Set the tab index for the input, default is 0. - pub fn tab_index(mut self, index: isize) -> Self { - self.tab_index = index; - self - } - fn render_toggle_mask_button(state: &Entity>) -> impl IntoElement { Button::new("toggle-mask") .icon(IconName::Eye) diff --git a/crates/ui/src/menu/menu_item.rs b/crates/ui/src/menu/menu_item.rs index 48d5bd30..7dcfafb7 100644 --- a/crates/ui/src/menu/menu_item.rs +++ b/crates/ui/src/menu/menu_item.rs @@ -7,7 +7,7 @@ use gpui::{ use smallvec::SmallVec; use theme::ActiveTheme; -use crate::{h_flex, Disableable, StyledExt}; +use crate::{Disableable, StyledExt, h_flex}; #[derive(IntoElement)] pub(crate) struct MenuItemElement { @@ -61,7 +61,6 @@ impl MenuItemElement { } /// Set a handler for when the mouse enters the MenuItem. - #[allow(unused)] pub fn on_hover(mut self, handler: impl Fn(&bool, &mut Window, &mut App) + 'static) -> Self { self.on_hover = Some(Box::new(handler)); self diff --git a/crates/ui/src/menu/popup_menu.rs b/crates/ui/src/menu/popup_menu.rs index 67ca119a..c805eca9 100644 --- a/crates/ui/src/menu/popup_menu.rs +++ b/crates/ui/src/menu/popup_menu.rs @@ -85,23 +85,6 @@ impl PopupMenuItem { } } - /// Create a new menu item with custom element render. - #[inline] - pub fn element(builder: F) -> Self - where - F: Fn(&mut Window, &mut App) -> E + 'static, - E: IntoElement, - { - PopupMenuItem::ElementItem { - icon: None, - disabled: false, - checked: false, - action: None, - render: Box::new(move |window, cx| builder(window, cx).into_any_element()), - handler: None, - } - } - /// Create a new submenu item that opens another popup menu. #[inline] pub fn submenu(label: impl Into, menu: Entity) -> Self { @@ -214,21 +197,6 @@ impl PopupMenuItem { self } - /// Create a link menu item. - #[inline] - pub fn link(label: impl Into, href: impl Into) -> Self { - let href = href.into(); - PopupMenuItem::Item { - icon: None, - label: label.into(), - disabled: false, - checked: false, - action: None, - is_link: true, - handler: Some(Rc::new(move |_, _, cx| cx.open_url(&href))), - } - } - #[inline] fn is_clickable(&self) -> bool { !matches!(self, PopupMenuItem::Separator) @@ -334,28 +302,12 @@ impl PopupMenu { cx.new(|cx| f(Self::new(cx), window, cx)) } - /// Set the focus handle of Entity to handle actions. - /// - /// When the menu is dismissed or before an action is triggered, the focus will be returned to this handle. - /// - /// Then the action will be dispatched to this handle. - pub fn action_context(mut self, handle: FocusHandle) -> Self { - self.action_context = Some(handle); - self - } - /// Set min width of the popup menu, default is 120px pub fn min_w(mut self, width: impl Into) -> Self { self.min_width = Some(width.into()); self } - /// Set max width of the popup menu, default is 500px - pub fn max_w(mut self, width: impl Into) -> Self { - self.max_width = Some(width.into()); - self - } - /// Set max height of the popup menu, default is half of the window height pub fn max_h(mut self, height: impl Into) -> Self { self.max_height = Some(height.into()); @@ -376,34 +328,11 @@ impl PopupMenu { self } - /// Set the side to show check icon, default is `Side::Left`. - pub fn check_side(mut self, side: Side) -> Self { - self.check_side = side; - self - } - - /// Set the menu to show external link icon, default is true. - pub fn external_link_icon(mut self, visible: bool) -> Self { - self.external_link_icon = visible; - self - } - /// Add Menu Item pub fn menu(self, label: impl Into, action: Box) -> Self { self.menu_with_disabled(label, action, false) } - /// Add Menu Item with enable state - pub fn menu_with_enable( - mut self, - label: impl Into, - action: Box, - enable: bool, - ) -> Self { - self.add_menu_item(label, None, action, !enable, false); - self - } - /// Add Menu Item with disabled state pub fn menu_with_disabled( mut self, @@ -421,70 +350,14 @@ impl PopupMenu { self } - /// Add Menu to open link - pub fn link(self, label: impl Into, href: impl Into) -> Self { - self.link_with_disabled(label, href, false) - } - - /// Add Menu to open link with disabled state - pub fn link_with_disabled( - mut self, - label: impl Into, - href: impl Into, - disabled: bool, - ) -> Self { - let href = href.into(); - self.menu_items - .push(PopupMenuItem::link(label, href).disabled(disabled)); - self - } - - /// Add Menu to open link - pub fn link_with_icon( - self, - label: impl Into, - icon: impl Into, - href: impl Into, - ) -> Self { - self.link_with_icon_and_disabled(label, icon, href, false) - } - - /// Add Menu to open link with icon and disabled state - fn link_with_icon_and_disabled( - mut self, - label: impl Into, - icon: impl Into, - href: impl Into, - disabled: bool, - ) -> Self { - let href = href.into(); - self.menu_items.push( - PopupMenuItem::link(label, href) - .icon(icon) - .disabled(disabled), - ); - self - } - /// Add Menu Item with Icon. pub fn menu_with_icon( - self, - label: impl Into, - icon: impl Into, - action: Box, - ) -> Self { - self.menu_with_icon_and_disabled(label, icon, action, false) - } - - /// Add Menu Item with Icon and disabled state - pub fn menu_with_icon_and_disabled( mut self, label: impl Into, icon: impl Into, action: Box, - disabled: bool, ) -> Self { - self.add_menu_item(label, Some(icon.into()), action, disabled, false); + self.add_menu_item(label, Some(icon.into()), action, false, false); self } @@ -510,41 +383,6 @@ impl PopupMenu { self } - /// Add Menu Item with custom element render with check state - pub fn menu_element_with_check( - self, - checked: bool, - action: Box, - builder: F, - ) -> Self - where - F: Fn(&mut Window, &mut App) -> E + 'static, - E: IntoElement, - { - self.menu_element_with_check_and_disabled(checked, action, false, builder) - } - - /// Add Menu Item with custom element render with check state and disabled state - fn menu_element_with_check_and_disabled( - mut self, - checked: bool, - action: Box, - disabled: bool, - builder: F, - ) -> Self - where - F: Fn(&mut Window, &mut App) -> E + 'static, - E: IntoElement, - { - self.menu_items.push( - PopupMenuItem::element(builder) - .action(action) - .checked(checked) - .disabled(disabled), - ); - self - } - /// Add a separator Menu Item pub fn separator(mut self) -> Self { if self.menu_items.is_empty() { @@ -636,10 +474,6 @@ impl PopupMenu { None } - pub fn is_empty(&self) -> bool { - self.menu_items.is_empty() - } - fn clickable_menu_items(&self) -> impl Iterator { self.menu_items .iter() diff --git a/crates/ui/src/notification.rs b/crates/ui/src/notification.rs index 973bea7b..36256b8a 100644 --- a/crates/ui/src/notification.rs +++ b/crates/ui/src/notification.rs @@ -156,13 +156,6 @@ impl Notification { self } - /// Create an info notification with the given message. - pub fn info(message: impl Into) -> Self { - Self::new() - .message(message) - .with_kind(NotificationKind::Info) - } - /// Create a success notification with the given message. pub fn success(message: impl Into) -> Self { Self::new() @@ -209,14 +202,6 @@ impl Notification { self } - /// Set the icon of the notification. - /// - /// If icon is None, the notification will use the default icon of the type. - pub fn icon(mut self, icon: impl Into) -> Self { - self.icon = Some(icon.into()); - self - } - /// Set the type of the notification, default is NotificationType::Info. pub fn with_kind(mut self, kind: NotificationKind) -> Self { self.kind = Some(kind); @@ -229,15 +214,6 @@ impl Notification { self } - /// Set the click callback of the notification. - pub fn on_click( - mut self, - on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, - ) -> Self { - self.on_click = Some(Rc::new(on_click)); - self - } - /// Set the action button of the notification. /// /// When an action is set, the notification will not autohide. @@ -611,13 +587,6 @@ impl NotificationList { } cx.notify(); } - - pub fn notifications(&self) -> Vec> { - self.notifications - .iter() - .map(|(_, note, _)| note.clone()) - .collect() - } } impl Render for NotificationList { diff --git a/crates/ui/src/scroll/scrollable.rs b/crates/ui/src/scroll/scrollable.rs index 6fac9324..4ff97f84 100644 --- a/crates/ui/src/scroll/scrollable.rs +++ b/crates/ui/src/scroll/scrollable.rs @@ -31,23 +31,6 @@ pub trait ScrollableElement: InteractiveElement + Styled + ParentElement + Eleme fn vertical_scrollbar(self, scroll_handle: &H) -> Self { self.scrollbar(scroll_handle, ScrollbarAxis::Vertical) } - /// Adds a horizontal scrollbar to the element. - #[track_caller] - fn horizontal_scrollbar(self, scroll_handle: &H) -> Self { - self.scrollbar(scroll_handle, ScrollbarAxis::Horizontal) - } - - /// Almost equivalent to [`StatefulInteractiveElement::overflow_scroll`], but adds scrollbars. - #[track_caller] - fn overflow_scrollbar(self) -> Scrollable { - Scrollable::new(self, ScrollbarAxis::Both) - } - - /// Almost equivalent to [`StatefulInteractiveElement::overflow_x_scroll`], but adds Horizontal scrollbar. - #[track_caller] - fn overflow_x_scrollbar(self) -> Scrollable { - Scrollable::new(self, ScrollbarAxis::Horizontal) - } /// Almost equivalent to [`StatefulInteractiveElement::overflow_y_scroll`], but adds Vertical scrollbar. #[track_caller] diff --git a/crates/ui/src/switch.rs b/crates/ui/src/switch.rs index cdf6ab99..c570c8af 100644 --- a/crates/ui/src/switch.rs +++ b/crates/ui/src/switch.rs @@ -63,11 +63,6 @@ impl Switch { self.on_click = Some(Rc::new(handler)); self } - - pub fn label_side(mut self, label_side: Side) -> Self { - self.label_side = label_side; - self - } } impl Sizable for Switch { diff --git a/crates/ui/src/tab/tab_bar.rs b/crates/ui/src/tab/tab_bar.rs index 985e71c7..24b0b8b9 100644 --- a/crates/ui/src/tab/tab_bar.rs +++ b/crates/ui/src/tab/tab_bar.rs @@ -2,17 +2,15 @@ use std::rc::Rc; use gpui::prelude::FluentBuilder as _; use gpui::{ - Anchor, AnyElement, App, Div, ElementId, InteractiveElement, IntoElement, ParentElement, - RenderOnce, ScrollHandle, Stateful, StatefulInteractiveElement as _, StyleRefinement, Styled, - Window, div, px, + AnyElement, App, Div, ElementId, InteractiveElement, IntoElement, ParentElement, RenderOnce, + ScrollHandle, Stateful, StatefulInteractiveElement as _, StyleRefinement, Styled, Window, div, + px, }; use smallvec::SmallVec; use theme::ActiveTheme; use super::Tab; -use crate::button::{Button, ButtonVariants as _}; -use crate::menu::{DropdownMenu as _, PopupMenuItem}; -use crate::{IconName, Selectable, Sizable, StyledExt, h_flex}; +use crate::{Selectable, StyledExt, h_flex}; /// A TabBar element that contains multiple [`Tab`] items. #[derive(IntoElement)] @@ -25,7 +23,6 @@ pub struct TabBar { children: SmallVec<[Tab; 2]>, last_empty_space: AnyElement, selected_index: Option, - menu: bool, segmented: bool, #[allow(clippy::type_complexity)] on_click: Option>, @@ -44,7 +41,6 @@ impl TabBar { last_empty_space: div().w_3().into_any_element(), selected_index: None, on_click: None, - menu: false, segmented: false, } } @@ -55,12 +51,6 @@ impl TabBar { self } - /// Set whether to show the menu button when tabs overflow, default is false. - pub fn menu(mut self, menu: bool) -> Self { - self.menu = menu; - self - } - /// Track the scroll of the TabBar. pub fn track_scroll(mut self, scroll_handle: &ScrollHandle) -> Self { self.scroll_handle = Some(scroll_handle.clone()); @@ -123,9 +113,6 @@ impl Styled for TabBar { impl RenderOnce for TabBar { fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement { - let mut item_labels = Vec::new(); - let selected_index = self.selected_index; - let on_click = self.on_click.clone(); let segmented = self.segmented; let has_prefix = self.prefix.is_some(); @@ -155,7 +142,6 @@ impl RenderOnce for TabBar { }) .gap_1() .children(self.children.into_iter().enumerate().map(|(ix, child)| { - item_labels.push((child.label.clone(), child.disabled)); let tab_bar_prefix = child.tab_bar_prefix.unwrap_or(true); child .ix(ix) @@ -168,36 +154,10 @@ impl RenderOnce for TabBar { this.on_click(move |_, window, cx| on_click(&ix, window, cx)) }) })) - .when(self.suffix.is_some() || self.menu, |this| { + .when(self.suffix.is_some(), |this| { this.child(self.last_empty_space) }), ) - .when(self.menu, |this| { - this.child( - Button::new("more") - .xsmall() - .ghost() - .icon(IconName::ChevronDown) - .dropdown_menu(move |mut this, _, _| { - this = this.scrollable(true); - for (ix, (label, disabled)) in item_labels.iter().enumerate() { - this = this.item( - PopupMenuItem::new(label.clone().unwrap_or_default()) - .checked(selected_index == Some(ix)) - .disabled(*disabled) - .when_some(on_click.clone(), |this, on_click| { - this.on_click(move |_, window, cx| { - on_click(&ix, window, cx) - }) - }), - ) - } - - this - }) - .anchor(Anchor::TopRight), - ) - }) .when_some(self.suffix, |this, suffix| this.child(suffix)) } } diff --git a/crates/ui/src/window_ext.rs b/crates/ui/src/window_ext.rs index 76faab0c..dc37737d 100644 --- a/crates/ui/src/window_ext.rs +++ b/crates/ui/src/window_ext.rs @@ -1,6 +1,4 @@ -use std::rc::Rc; - -use gpui::{App, ElementId, Entity, Window}; +use gpui::{App, ElementId, Window}; use crate::Root; use crate::dialog::Dialog; @@ -19,9 +17,6 @@ pub trait WindowExtension: Sized { /// Closes all active Dialogs. fn close_all_dialogs(&mut self, cx: &mut App); - /// Returns number of notifications. - fn notifications(&mut self, cx: &mut App) -> Rc>>; - /// Pushes a notification to the notification list. fn push_notification(&mut self, note: T, cx: &mut App) where @@ -102,9 +97,4 @@ impl WindowExtension for Window { root.clear_notifications(window, cx); }) } - - fn notifications(&mut self, cx: &mut App) -> Rc>> { - let entity = Root::read(self, cx).notification.clone(); - Rc::new(entity.read(cx).notifications()) - } } diff --git a/crates/workspace/Cargo.toml b/crates/workspace/Cargo.toml index 018905b9..3735ac7f 100644 --- a/crates/workspace/Cargo.toml +++ b/crates/workspace/Cargo.toml @@ -22,7 +22,6 @@ gpui.workspace = true nostr-sdk.workspace = true instant.workspace = true nostr-connect.workspace = true -browser-signer-proxy = { path = "../browser-signer-proxy" } anyhow.workspace = true serde.workspace = true diff --git a/crates/workspace/src/sidebar/header.rs b/crates/workspace/src/sidebar/header.rs index bc7d8b51..ffbab4a3 100644 --- a/crates/workspace/src/sidebar/header.rs +++ b/crates/workspace/src/sidebar/header.rs @@ -50,24 +50,19 @@ impl Sidebar { .compact() .transparent() .dropdown_menu(move |this, _window, _cx| { - this.min_w(px(256.)) - .menu_with_icon( - "Profile", - IconName::Profile, - Box::new(Command::ShowProfile), - ) - .menu_with_icon( - "Relays", - IconName::Relay, - Box::new(Command::ShowRelayList), - ) - .separator() - .menu_with_icon("Themes", IconName::Sun, Box::new(Command::ToggleTheme)) - .menu_with_icon( - "Settings", - IconName::Settings, - Box::new(Command::ShowSettings), - ) + this.menu_with_icon( + "Profile", + IconName::Profile, + Box::new(Command::ShowProfile), + ) + .menu_with_icon("Relays", IconName::Relay, Box::new(Command::ShowRelayList)) + .separator() + .menu_with_icon("Themes", IconName::Sun, Box::new(Command::ToggleTheme)) + .menu_with_icon( + "Settings", + IconName::Settings, + Box::new(Command::ShowSettings), + ) }), ) .child(div().flex_1()) diff --git a/desktop/Cargo.toml b/desktop/Cargo.toml index a9f13c51..22a6ae87 100644 --- a/desktop/Cargo.toml +++ b/desktop/Cargo.toml @@ -31,7 +31,6 @@ assets = { path = "../crates/assets" } workspace = { path = "../crates/workspace" } ui = { path = "../crates/ui" } theme = { path = "../crates/theme" } -common = { path = "../crates/common" } state = { path = "../crates/state" } nip4e = { path = "../crates/nip4e" } chat = { path = "../crates/chat" } diff --git a/web/Cargo.toml b/web/Cargo.toml index 51482e8b..d2148c39 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -9,10 +9,8 @@ crate-type = ["cdylib", "rlib"] [dependencies] workspace = { path = "../crates/workspace" } -assets = { path = "../crates/assets" } ui = { path = "../crates/ui" } theme = { path = "../crates/theme" } -common = { path = "../crates/common" } state = { path = "../crates/state" } nip4e = { path = "../crates/nip4e" } chat = { path = "../crates/chat" }