Compare commits
11 Commits
v1.0.0-bet
...
7b27a7e864
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b27a7e864 | ||
|
|
cc4174a695 | ||
|
|
ecd25d04da | ||
|
|
0403d0e4ec | ||
|
|
707533c145 | ||
|
|
163865eb46 | ||
|
|
fbc9883680 | ||
|
|
d1f0373916 | ||
|
|
216c877ebf | ||
|
|
1b4aa02cc0 | ||
|
|
b547776263 |
10
.github/workflows/release.yml
vendored
@@ -45,7 +45,7 @@ jobs:
|
|||||||
# Windows and macOS builds using cargo-packager
|
# Windows and macOS builds using cargo-packager
|
||||||
- name: Build with cargo-packager (Windows/macOS)
|
- name: Build with cargo-packager (Windows/macOS)
|
||||||
if: runner.os != 'Linux'
|
if: runner.os != 'Linux'
|
||||||
working-directory: desktop
|
working-directory: crates/coop
|
||||||
run: |
|
run: |
|
||||||
cargo install cargo-packager --locked
|
cargo install cargo-packager --locked
|
||||||
cargo packager --release
|
cargo packager --release
|
||||||
@@ -154,13 +154,13 @@ jobs:
|
|||||||
|
|
||||||
- name: Create draft release
|
- name: Create draft release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: akkuman/gitea-release-action@v1
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
server_url: "https://git.reya.su/"
|
tag_name: ${{ steps.version.outputs.tag }}
|
||||||
repository: "reya/coop"
|
name: ${{ steps.version.outputs.tag }}
|
||||||
token: ${{ secrets.GITEA_TOKEN }}
|
|
||||||
draft: true
|
draft: true
|
||||||
prerelease: false
|
prerelease: false
|
||||||
|
generate_release_notes: true
|
||||||
files: |
|
files: |
|
||||||
artifacts/**/*
|
artifacts/**/*
|
||||||
|
|
||||||
|
|||||||
710
Cargo.lock
generated
@@ -1,10 +1,10 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = ["crates/*", "desktop", "web"]
|
members = ["crates/*"]
|
||||||
default-members = ["desktop"]
|
default-members = ["crates/coop"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "1.0.0-beta4"
|
version = "1.0.0-beta2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ gpui_platform = { git = "https://github.com/zed-industries/zed", features = ["fo
|
|||||||
gpui_linux = { git = "https://github.com/zed-industries/zed" }
|
gpui_linux = { git = "https://github.com/zed-industries/zed" }
|
||||||
gpui_windows = { git = "https://github.com/zed-industries/zed" }
|
gpui_windows = { git = "https://github.com/zed-industries/zed" }
|
||||||
gpui_macos = { git = "https://github.com/zed-industries/zed" }
|
gpui_macos = { git = "https://github.com/zed-industries/zed" }
|
||||||
|
gpui_web = { git = "https://github.com/zed-industries/zed" }
|
||||||
gpui_tokio = { git = "https://github.com/zed-industries/zed" }
|
gpui_tokio = { git = "https://github.com/zed-industries/zed" }
|
||||||
reqwest_client = { git = "https://github.com/zed-industries/zed" }
|
reqwest_client = { git = "https://github.com/zed-industries/zed" }
|
||||||
|
|
||||||
@@ -42,7 +43,6 @@ smallvec = "1.14.0"
|
|||||||
smol = "2"
|
smol = "2"
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
webbrowser = "1.0.4"
|
webbrowser = "1.0.4"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true
|
strip = true
|
||||||
|
|||||||
16
README.md
@@ -1,12 +1,12 @@
|
|||||||

|

|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a href="https://github.com/reyakov/coop/actions/workflows/rust.yml">
|
<a href="https://github.com/lumehq/coop/actions/workflows/rust.yml">
|
||||||
<img alt="Actions" src="https://github.com/reyakov/coop/actions/workflows/rust.yml/badge.svg">
|
<img alt="Actions" src="https://github.com/lumehq/coop/actions/workflows/rust.yml/badge.svg">
|
||||||
</a>
|
</a>
|
||||||
<img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/reyakov/coop">
|
<img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/lumehq/coop">
|
||||||
<img alt="GitHub issues" src="https://img.shields.io/github/issues-raw/reyakov/coop">
|
<img alt="GitHub issues" src="https://img.shields.io/github/issues-raw/lumehq/coop">
|
||||||
<img alt="GitHub pull requests" src="https://img.shields.io/github/issues-pr/reyakov/coop">
|
<img alt="GitHub pull requests" src="https://img.shields.io/github/issues-pr/lumehq/coop">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
Coop is a simple, fast, and reliable nostr client for secure messaging across all platforms.
|
Coop is a simple, fast, and reliable nostr client for secure messaging across all platforms.
|
||||||
@@ -36,7 +36,7 @@ To install Coop, follow these steps:
|
|||||||
|
|
||||||
1. **Download the Latest Release**:
|
1. **Download the Latest Release**:
|
||||||
|
|
||||||
- Visit the [Coop Releases page on GitHub](https://github.com/reyakov/coop/releases).
|
- Visit the [Coop Releases page on GitHub](https://github.com/lumehq/coop/releases).
|
||||||
- Download the package that matches your operating system (Windows, macOS, or Linux).
|
- Download the package that matches your operating system (Windows, macOS, or Linux).
|
||||||
|
|
||||||
2. **Install**:
|
2. **Install**:
|
||||||
@@ -65,7 +65,7 @@ Coop is built using Rust and GPUI. All Nostr related stuffs handled by [Rust Nos
|
|||||||
1. Clone the repository:
|
1. Clone the repository:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/reyakov/coop.git
|
git clone https://github.com/lumehq/coop.git
|
||||||
cd coop
|
cd coop
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ For more information, see the [Contributing](#contributing) section.
|
|||||||
- [Rust Nostr](https://github.com/rust-nostr/nostr/)
|
- [Rust Nostr](https://github.com/rust-nostr/nostr/)
|
||||||
- [GPUI](https://www.gpui.rs/)
|
- [GPUI](https://www.gpui.rs/)
|
||||||
- [GPUI Components](https://github.com/longbridge/gpui-component/)
|
- [GPUI Components](https://github.com/longbridge/gpui-component/)
|
||||||
- [Coop Issue Tracker](https://github.com/reyakov/coop/issues/)
|
- [Coop Issue Tracker](https://github.com/lumehq/coop/issues/)
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
|
|||||||
@@ -253,13 +253,6 @@ impl ChatRegistry {
|
|||||||
event_map.insert(rumor.id.unwrap(), (event.id, dekey));
|
event_map.insert(rumor.id.unwrap(), (event.id, dekey));
|
||||||
}
|
}
|
||||||
|
|
||||||
if rumor.kind != Kind::PrivateDirectMessage
|
|
||||||
|| rumor.kind != Kind::Custom(15)
|
|
||||||
{
|
|
||||||
log::info!("Rumor is not releated to NIP17");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the rumor has a recipient
|
// Check if the rumor has a recipient
|
||||||
if rumor.tags.is_empty() {
|
if rumor.tags.is_empty() {
|
||||||
let signal =
|
let signal =
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
use common::{EventExt, NostrParser, extract_and_remove_media_urls};
|
use common::{EventExt, NostrParser};
|
||||||
use gpui::{SharedString, SharedUri};
|
use gpui::SharedString;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
/// New message.
|
/// New message.
|
||||||
@@ -132,8 +132,6 @@ pub struct RenderedMessage {
|
|||||||
pub author: PublicKey,
|
pub author: PublicKey,
|
||||||
/// The content/text of the message
|
/// The content/text of the message
|
||||||
pub content: String,
|
pub content: String,
|
||||||
/// List of media URLs in the message
|
|
||||||
pub media: Vec<SharedUri>,
|
|
||||||
/// Message created time as unix timestamp
|
/// Message created time as unix timestamp
|
||||||
pub created_at: Timestamp,
|
pub created_at: Timestamp,
|
||||||
/// List of mentioned public keys in the message
|
/// List of mentioned public keys in the message
|
||||||
@@ -146,13 +144,11 @@ impl From<&Event> for RenderedMessage {
|
|||||||
fn from(val: &Event) -> Self {
|
fn from(val: &Event) -> Self {
|
||||||
let mentions = extract_mentions(&val.content);
|
let mentions = extract_mentions(&val.content);
|
||||||
let replies_to = extract_reply_ids(&val.tags);
|
let replies_to = extract_reply_ids(&val.tags);
|
||||||
let (media, string) = extract_and_remove_media_urls(&val.content);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id: val.id,
|
id: val.id,
|
||||||
author: val.pubkey,
|
author: val.pubkey,
|
||||||
content: string,
|
content: val.content.clone(),
|
||||||
media,
|
|
||||||
created_at: val.created_at,
|
created_at: val.created_at,
|
||||||
mentions,
|
mentions,
|
||||||
replies_to,
|
replies_to,
|
||||||
@@ -164,14 +160,12 @@ impl From<&UnsignedEvent> for RenderedMessage {
|
|||||||
fn from(val: &UnsignedEvent) -> Self {
|
fn from(val: &UnsignedEvent) -> Self {
|
||||||
let mentions = extract_mentions(&val.content);
|
let mentions = extract_mentions(&val.content);
|
||||||
let replies_to = extract_reply_ids(&val.tags);
|
let replies_to = extract_reply_ids(&val.tags);
|
||||||
let (media, string) = extract_and_remove_media_urls(&val.content);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
// Event ID must be known
|
// Event ID must be known
|
||||||
id: val.id.unwrap(),
|
id: val.id.unwrap(),
|
||||||
author: val.pubkey,
|
author: val.pubkey,
|
||||||
content: string,
|
content: val.content.clone(),
|
||||||
media,
|
|
||||||
created_at: val.created_at,
|
created_at: val.created_at,
|
||||||
mentions,
|
mentions,
|
||||||
replies_to,
|
replies_to,
|
||||||
@@ -183,14 +177,12 @@ impl From<&NewMessage> for RenderedMessage {
|
|||||||
fn from(val: &NewMessage) -> Self {
|
fn from(val: &NewMessage) -> Self {
|
||||||
let mentions = extract_mentions(&val.rumor.content);
|
let mentions = extract_mentions(&val.rumor.content);
|
||||||
let replies_to = extract_reply_ids(&val.rumor.tags);
|
let replies_to = extract_reply_ids(&val.rumor.tags);
|
||||||
let (media, string) = extract_and_remove_media_urls(&val.rumor.content);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
// Event ID must be known
|
// Event ID must be known
|
||||||
id: val.rumor.id.unwrap(),
|
id: val.rumor.id.unwrap(),
|
||||||
author: val.rumor.pubkey,
|
author: val.rumor.pubkey,
|
||||||
content: string,
|
content: val.rumor.content.clone(),
|
||||||
media,
|
|
||||||
created_at: val.rumor.created_at,
|
created_at: val.rumor.created_at,
|
||||||
mentions,
|
mentions,
|
||||||
replies_to,
|
replies_to,
|
||||||
|
|||||||
@@ -400,10 +400,6 @@ impl Room {
|
|||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|event| UnsignedEvent::from_json(&event.content).ok())
|
.filter_map(|event| UnsignedEvent::from_json(&event.content).ok())
|
||||||
.filter(|event| {
|
|
||||||
// Only process private direct messages and file messages
|
|
||||||
event.kind == Kind::PrivateDirectMessage || event.kind == Kind::Custom(15)
|
|
||||||
})
|
|
||||||
.sorted_by_key(|message| message.created_at)
|
.sorted_by_key(|message| message.created_at)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -602,8 +598,7 @@ async fn send_gift_wrap<T>(
|
|||||||
where
|
where
|
||||||
T: NostrSigner + 'static,
|
T: NostrSigner + 'static,
|
||||||
{
|
{
|
||||||
let k_tag = Tag::custom(TagKind::k(), vec!["14"]);
|
let mut extra_tags = vec![];
|
||||||
let mut extra_tags = vec![k_tag];
|
|
||||||
|
|
||||||
// Determine the receiver public key based on the config
|
// Determine the receiver public key based on the config
|
||||||
let receiver = match config {
|
let receiver = match config {
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ use std::sync::Arc;
|
|||||||
pub use actions::*;
|
pub use actions::*;
|
||||||
use anyhow::{Context as AnyhowContext, Error};
|
use anyhow::{Context as AnyhowContext, Error};
|
||||||
use chat::{ChatRegistry, Message, RenderedMessage, Room, RoomEvent, SendReport, SendStatus};
|
use chat::{ChatRegistry, Message, RenderedMessage, Room, RoomEvent, SendReport, SendStatus};
|
||||||
use common::{TimestampExt, coop_cache};
|
use common::TimestampExt;
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle,
|
AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle,
|
||||||
Focusable, InteractiveElement, IntoElement, ListAlignment, ListOffset, ListState, MouseButton,
|
Focusable, InteractiveElement, IntoElement, ListAlignment, ListOffset, ListState, MouseButton,
|
||||||
ObjectFit, ParentElement, PathPromptOptions, Render, SharedString, SharedUri,
|
ObjectFit, ParentElement, PathPromptOptions, Render, SharedString, StatefulInteractiveElement,
|
||||||
StatefulInteractiveElement, Styled, StyledImage, Subscription, Task, WeakEntity, Window,
|
Styled, StyledImage, Subscription, Task, WeakEntity, Window, deferred, div, img, list, px, red,
|
||||||
deferred, div, img, list, px, red, relative, svg, white,
|
relative, svg, white,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
@@ -914,8 +914,7 @@ impl ChatPanel {
|
|||||||
.when(has_replies, |this| {
|
.when(has_replies, |this| {
|
||||||
this.children(self.render_message_replies(replies, cx))
|
this.children(self.render_message_replies(replies, cx))
|
||||||
})
|
})
|
||||||
.child(rendered_text)
|
.child(rendered_text),
|
||||||
.child(self.render_media(&message.media, cx)),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -942,55 +941,6 @@ impl ChatPanel {
|
|||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_media(&self, media: &[SharedUri], cx: &Context<Self>) -> impl IntoElement {
|
|
||||||
// No media: return empty div
|
|
||||||
if media.is_empty() {
|
|
||||||
return div();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Single media item: render full-width image
|
|
||||||
if media.len() == 1 {
|
|
||||||
return div().child(
|
|
||||||
img(media[0].clone())
|
|
||||||
.border_1()
|
|
||||||
.border_color(cx.theme().border_variant)
|
|
||||||
.h(px(250.))
|
|
||||||
.object_fit(ObjectFit::Cover)
|
|
||||||
.rounded(cx.theme().radius),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Multiple media items: render in a row
|
|
||||||
div()
|
|
||||||
.w_full()
|
|
||||||
.flex_1()
|
|
||||||
.flex()
|
|
||||||
.flex_row()
|
|
||||||
.flex_wrap()
|
|
||||||
.gap_2()
|
|
||||||
.children({
|
|
||||||
let mut items = vec![];
|
|
||||||
|
|
||||||
for (ix, item) in media.iter().enumerate() {
|
|
||||||
items.push(
|
|
||||||
div()
|
|
||||||
.id(format!("media-{ix}"))
|
|
||||||
.flex_grow_0()
|
|
||||||
.flex_shrink_0()
|
|
||||||
.child(
|
|
||||||
img(item.clone())
|
|
||||||
.h_32()
|
|
||||||
.border_1()
|
|
||||||
.border_color(cx.theme().border_variant)
|
|
||||||
.rounded(cx.theme().radius),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
items
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_message_replies(
|
fn render_message_replies(
|
||||||
&self,
|
&self,
|
||||||
replies: &[EventId],
|
replies: &[EventId],
|
||||||
@@ -1421,7 +1371,7 @@ impl ChatPanel {
|
|||||||
.icon(IconName::Emoji)
|
.icon(IconName::Emoji)
|
||||||
.ghost()
|
.ghost()
|
||||||
.large()
|
.large()
|
||||||
.dropdown_menu_with_anchor(gpui::Anchor::BottomLeft, move |this, _window, _cx| {
|
.dropdown_menu_with_anchor(gpui::Corner::BottomLeft, move |this, _window, _cx| {
|
||||||
this.horizontal()
|
this.horizontal()
|
||||||
.menu("👍", Box::new(Command::Insert("👍")))
|
.menu("👍", Box::new(Command::Insert("👍")))
|
||||||
.menu("👎", Box::new(Command::Insert("👎")))
|
.menu("👎", Box::new(Command::Insert("👎")))
|
||||||
@@ -1485,7 +1435,6 @@ impl Focusable for ChatPanel {
|
|||||||
impl Render for ChatPanel {
|
impl Render for ChatPanel {
|
||||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
v_flex()
|
v_flex()
|
||||||
.image_cache(coop_cache(self.id.clone(), 100))
|
|
||||||
.on_action(cx.listener(Self::on_command))
|
.on_action(cx.listener(Self::on_command))
|
||||||
.size_full()
|
.size_full()
|
||||||
.when(*self.subject_bar.read(cx), |this| {
|
.when(*self.subject_bar.read(cx), |this| {
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ impl RenderedText {
|
|||||||
|
|
||||||
pub fn element(&self, id: ElementId, window: &Window, cx: &App) -> AnyElement {
|
pub fn element(&self, id: ElementId, window: &Window, cx: &App) -> AnyElement {
|
||||||
let code_background = cx.theme().elevated_surface_background;
|
let code_background = cx.theme().elevated_surface_background;
|
||||||
let color = cx.theme().text_accent;
|
|
||||||
|
|
||||||
InteractiveText::new(
|
InteractiveText::new(
|
||||||
id,
|
id,
|
||||||
@@ -101,7 +100,6 @@ impl RenderedText {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Highlight::Mention => HighlightStyle {
|
Highlight::Mention => HighlightStyle {
|
||||||
color: Some(color),
|
|
||||||
underline: Some(UnderlineStyle {
|
underline: Some(UnderlineStyle {
|
||||||
thickness: 1.0.into(),
|
thickness: 1.0.into(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|||||||
@@ -20,4 +20,3 @@ log.workspace = true
|
|||||||
dirs = "5.0"
|
dirs = "5.0"
|
||||||
qrcode = "0.14.1"
|
qrcode = "0.14.1"
|
||||||
bech32 = "0.11.1"
|
bech32 = "0.11.1"
|
||||||
regex = "1.10"
|
|
||||||
|
|||||||
@@ -1,135 +0,0 @@
|
|||||||
use std::collections::{HashMap, VecDeque};
|
|
||||||
use std::mem::take;
|
|
||||||
|
|
||||||
use futures::FutureExt;
|
|
||||||
use gpui::{
|
|
||||||
App, AppContext, Asset, AssetLogger, ElementId, Entity, ImageAssetLoader, ImageCache,
|
|
||||||
ImageCacheItem, ImageCacheProvider, ImageSource, Resource, hash,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn coop_cache(id: impl Into<ElementId>, max_items: usize) -> CoopImageCacheProvider {
|
|
||||||
CoopImageCacheProvider {
|
|
||||||
id: id.into(),
|
|
||||||
max_items,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CoopImageCacheProvider {
|
|
||||||
id: ElementId,
|
|
||||||
max_items: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ImageCacheProvider for CoopImageCacheProvider {
|
|
||||||
fn provide(&mut self, window: &mut gpui::Window, cx: &mut App) -> gpui::AnyImageCache {
|
|
||||||
window
|
|
||||||
.with_global_id(self.id.clone(), |id, window| {
|
|
||||||
window.with_element_state(id, |cache, _| {
|
|
||||||
let cache = cache.unwrap_or_else(|| CoopImageCache::new(self.max_items, cx));
|
|
||||||
(cache.clone(), cache)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CoopImageCache {
|
|
||||||
max_items: usize,
|
|
||||||
usage_list: VecDeque<u64>,
|
|
||||||
cache: HashMap<u64, (ImageCacheItem, Resource)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CoopImageCache {
|
|
||||||
pub fn new(max_items: usize, cx: &mut App) -> Entity<Self> {
|
|
||||||
cx.new(|cx| {
|
|
||||||
log::info!("Creating CoopImageCache");
|
|
||||||
cx.on_release(|this: &mut Self, cx| {
|
|
||||||
for (ix, (mut image, resource)) in take(&mut this.cache) {
|
|
||||||
if let Some(Ok(image)) = image.get() {
|
|
||||||
log::info!("Dropping image {ix}");
|
|
||||||
cx.drop_image(image, None);
|
|
||||||
}
|
|
||||||
ImageSource::Resource(resource).remove_asset(cx);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
|
|
||||||
CoopImageCache {
|
|
||||||
max_items,
|
|
||||||
usage_list: VecDeque::with_capacity(max_items),
|
|
||||||
cache: HashMap::with_capacity(max_items),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ImageCache for CoopImageCache {
|
|
||||||
fn load(
|
|
||||||
&mut self,
|
|
||||||
resource: &Resource,
|
|
||||||
window: &mut gpui::Window,
|
|
||||||
cx: &mut gpui::App,
|
|
||||||
) -> Option<Result<std::sync::Arc<gpui::RenderImage>, gpui::ImageCacheError>> {
|
|
||||||
let hash = hash(resource);
|
|
||||||
|
|
||||||
if let Some(item) = self.cache.get_mut(&hash) {
|
|
||||||
let current_idx = self
|
|
||||||
.usage_list
|
|
||||||
.iter()
|
|
||||||
.position(|item| *item == hash)
|
|
||||||
.expect("cache has an item usage_list doesn't");
|
|
||||||
|
|
||||||
self.usage_list.remove(current_idx);
|
|
||||||
self.usage_list.push_front(hash);
|
|
||||||
|
|
||||||
return item.0.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
let load_future = AssetLogger::<ImageAssetLoader>::load(resource.clone(), cx);
|
|
||||||
let task = cx.background_executor().spawn(load_future).shared();
|
|
||||||
|
|
||||||
if self.usage_list.len() >= self.max_items {
|
|
||||||
log::info!("Image cache is full, evicting oldest item");
|
|
||||||
|
|
||||||
if let Some(oldest) = self.usage_list.pop_back() {
|
|
||||||
let mut image = self
|
|
||||||
.cache
|
|
||||||
.remove(&oldest)
|
|
||||||
.expect("usage_list has an item cache doesn't");
|
|
||||||
|
|
||||||
if let Some(Ok(image)) = image.0.get() {
|
|
||||||
log::info!("requesting image to be dropped");
|
|
||||||
cx.drop_image(image, Some(window));
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageSource::Resource(image.1).remove_asset(cx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.cache.insert(
|
|
||||||
hash,
|
|
||||||
(
|
|
||||||
gpui::ImageCacheItem::Loading(task.clone()),
|
|
||||||
resource.clone(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
self.usage_list.push_front(hash);
|
|
||||||
|
|
||||||
let entity = window.current_view();
|
|
||||||
|
|
||||||
window
|
|
||||||
.spawn(cx, async move |cx| {
|
|
||||||
let result = task.await;
|
|
||||||
|
|
||||||
if let Err(err) = result {
|
|
||||||
log::error!("error loading image into cache: {:?}", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
cx.on_next_frame(move |_, cx| {
|
|
||||||
cx.notify(entity);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +1,13 @@
|
|||||||
pub use caching::*;
|
|
||||||
pub use debounced_delay::*;
|
pub use debounced_delay::*;
|
||||||
pub use display::*;
|
pub use display::*;
|
||||||
pub use event::*;
|
pub use event::*;
|
||||||
pub use media_extractor::*;
|
|
||||||
pub use parser::*;
|
pub use parser::*;
|
||||||
pub use paths::*;
|
pub use paths::*;
|
||||||
pub use range::*;
|
pub use range::*;
|
||||||
|
|
||||||
mod caching;
|
|
||||||
mod debounced_delay;
|
mod debounced_delay;
|
||||||
mod display;
|
mod display;
|
||||||
mod event;
|
mod event;
|
||||||
mod media_extractor;
|
|
||||||
mod parser;
|
mod parser;
|
||||||
mod paths;
|
mod paths;
|
||||||
mod range;
|
mod range;
|
||||||
|
|||||||
@@ -1,117 +0,0 @@
|
|||||||
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 {
|
|
||||||
image_regex: Regex,
|
|
||||||
video_regex: Regex,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MediaExtractor {
|
|
||||||
/// Creates a new MediaExtractor with compiled regex patterns
|
|
||||||
pub 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<SharedUri> {
|
|
||||||
let mut urls = Vec::new();
|
|
||||||
|
|
||||||
// Extract image URLs
|
|
||||||
for capture in self.image_regex.find_iter(text) {
|
|
||||||
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 {
|
|
||||||
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<SharedUri>, String) {
|
|
||||||
let urls = self.extract_media_urls(text);
|
|
||||||
let cleaned_text = self.remove_media_urls(text);
|
|
||||||
(urls, cleaned_text)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper function to clean up text after URL removal
|
|
||||||
fn cleanup_text(&self, text: &str) -> String {
|
|
||||||
let text = text.trim();
|
|
||||||
|
|
||||||
// Remove multiple consecutive spaces
|
|
||||||
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<SharedUri>, Vec<SharedUri>) {
|
|
||||||
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
|
|
||||||
pub fn extract_and_remove_media_urls(text: &str) -> (Vec<SharedUri>, 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<SharedUri> {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
@@ -14,8 +14,8 @@ product-name = "Coop"
|
|||||||
description = "Chat Freely, Stay Private on Nostr"
|
description = "Chat Freely, Stay Private on Nostr"
|
||||||
identifier = "su.reya.coop"
|
identifier = "su.reya.coop"
|
||||||
category = "SocialNetworking"
|
category = "SocialNetworking"
|
||||||
version = "1.0.0-beta4"
|
version = "1.0.0-beta2"
|
||||||
out-dir = "../dist"
|
out-dir = "../../dist"
|
||||||
before-packaging-command = "cargo build --release"
|
before-packaging-command = "cargo build --release"
|
||||||
resources = ["Cargo.toml", "src"]
|
resources = ["Cargo.toml", "src"]
|
||||||
icons = [
|
icons = [
|
||||||
@@ -27,19 +27,19 @@ icons = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
assets = { path = "../crates/assets" }
|
assets = { path = "../assets" }
|
||||||
ui = { path = "../crates/ui" }
|
ui = { path = "../ui" }
|
||||||
title_bar = { path = "../crates/title_bar" }
|
title_bar = { path = "../title_bar" }
|
||||||
theme = { path = "../crates/theme" }
|
theme = { path = "../theme" }
|
||||||
common = { path = "../crates/common" }
|
common = { path = "../common" }
|
||||||
state = { path = "../crates/state" }
|
state = { path = "../state" }
|
||||||
device = { path = "../crates/device" }
|
device = { path = "../device" }
|
||||||
chat = { path = "../crates/chat" }
|
chat = { path = "../chat" }
|
||||||
chat_ui = { path = "../crates/chat_ui" }
|
chat_ui = { path = "../chat_ui" }
|
||||||
settings = { path = "../crates/settings" }
|
settings = { path = "../settings" }
|
||||||
auto_update = { path = "../crates/auto_update" }
|
auto_update = { path = "../auto_update" }
|
||||||
person = { path = "../crates/person" }
|
person = { path = "../person" }
|
||||||
relay_auth = { path = "../crates/relay_auth" }
|
relay_auth = { path = "../relay_auth" }
|
||||||
|
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
gpui_platform.workspace = true
|
gpui_platform.workspace = true
|
||||||
@@ -62,9 +62,9 @@ smol.workspace = true
|
|||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
oneshot.workspace = true
|
oneshot.workspace = true
|
||||||
webbrowser.workspace = true
|
webbrowser.workspace = true
|
||||||
tracing-subscriber.workspace = true
|
|
||||||
|
|
||||||
indexset = "0.12.3"
|
indexset = "0.12.3"
|
||||||
|
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies]
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
# Temporary workaround https://github.com/zed-industries/zed/issues/47168
|
# Temporary workaround https://github.com/zed-industries/zed/issues/47168
|
||||||
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
@@ -50,7 +50,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "dir",
|
"type": "dir",
|
||||||
"path": "./desktop/resources"
|
"path": "./crates/coop/resources"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
@@ -4,18 +4,18 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use anyhow::{Context as AnyhowContext, Error};
|
use anyhow::{Context as AnyhowContext, Error};
|
||||||
use chat::{ChatEvent, ChatRegistry, Room, RoomKind};
|
use chat::{ChatEvent, ChatRegistry, Room, RoomKind};
|
||||||
use common::{DebouncedDelay, TimestampExt, coop_cache};
|
use common::{DebouncedDelay, TimestampExt};
|
||||||
use entry::RoomEntry;
|
use entry::RoomEntry;
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable, IntoElement,
|
App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable, IntoElement,
|
||||||
ParentElement, Render, SharedString, Styled, Subscription, Task, UniformListScrollHandle,
|
ParentElement, Render, RetainAllImageCache, SharedString, Styled, Subscription, Task,
|
||||||
Window, div, uniform_list,
|
UniformListScrollHandle, Window, div, uniform_list,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use person::PersonRegistry;
|
use person::PersonRegistry;
|
||||||
use smallvec::{SmallVec, smallvec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use state::{FIND_DELAY, IMAGE_CACHE_SIZE, NostrRegistry};
|
use state::{FIND_DELAY, NostrRegistry};
|
||||||
use theme::{ActiveTheme, SIDEBAR_WIDTH, TABBAR_HEIGHT};
|
use theme::{ActiveTheme, SIDEBAR_WIDTH, TABBAR_HEIGHT};
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::dock::{Panel, PanelEvent};
|
use ui::dock::{Panel, PanelEvent};
|
||||||
@@ -39,6 +39,9 @@ pub struct Sidebar {
|
|||||||
focus_handle: FocusHandle,
|
focus_handle: FocusHandle,
|
||||||
scroll_handle: UniformListScrollHandle,
|
scroll_handle: UniformListScrollHandle,
|
||||||
|
|
||||||
|
/// Image cache
|
||||||
|
image_cache: Entity<RetainAllImageCache>,
|
||||||
|
|
||||||
/// Find input state
|
/// Find input state
|
||||||
find_input: Entity<InputState>,
|
find_input: Entity<InputState>,
|
||||||
|
|
||||||
@@ -138,6 +141,7 @@ impl Sidebar {
|
|||||||
name: "Sidebar".into(),
|
name: "Sidebar".into(),
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
scroll_handle: UniformListScrollHandle::new(),
|
scroll_handle: UniformListScrollHandle::new(),
|
||||||
|
image_cache: RetainAllImageCache::new(cx),
|
||||||
find_input,
|
find_input,
|
||||||
find_debouncer: DebouncedDelay::new(),
|
find_debouncer: DebouncedDelay::new(),
|
||||||
find_results,
|
find_results,
|
||||||
@@ -503,7 +507,7 @@ impl Render for Sidebar {
|
|||||||
};
|
};
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.image_cache(coop_cache("sidebar", IMAGE_CACHE_SIZE))
|
.image_cache(self.image_cache.clone())
|
||||||
.size_full()
|
.size_full()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.child(
|
.child(
|
||||||
@@ -2,19 +2,19 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use ::settings::AppSettings;
|
use ::settings::AppSettings;
|
||||||
use chat::{ChatEvent, ChatRegistry};
|
use chat::{ChatEvent, ChatRegistry};
|
||||||
use common::{CoopImageCache, download_dir};
|
use common::download_dir;
|
||||||
use device::{DeviceEvent, DeviceRegistry};
|
use device::{DeviceEvent, DeviceRegistry};
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Action, App, AppContext, Axis, Context, Entity, InteractiveElement, IntoElement, ParentElement,
|
Action, App, AppContext, Axis, Context, Entity, InteractiveElement, IntoElement, ParentElement,
|
||||||
Render, SharedString, StatefulInteractiveElement, Styled, Subscription, Window, div,
|
Render, SharedString, StatefulInteractiveElement, Styled, Subscription, Window, div, px,
|
||||||
image_cache, px, relative,
|
relative,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use person::{PersonRegistry, shorten_pubkey};
|
use person::{PersonRegistry, shorten_pubkey};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use smallvec::{SmallVec, smallvec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use state::{IMAGE_CACHE_SIZE, NostrRegistry, StateEvent};
|
use state::{NostrRegistry, StateEvent};
|
||||||
use theme::{ActiveTheme, SIDEBAR_WIDTH, Theme, ThemeRegistry};
|
use theme::{ActiveTheme, SIDEBAR_WIDTH, Theme, ThemeRegistry};
|
||||||
use title_bar::TitleBar;
|
use title_bar::TitleBar;
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
@@ -70,9 +70,6 @@ pub struct Workspace {
|
|||||||
/// App's Dock Area
|
/// App's Dock Area
|
||||||
dock: Entity<DockArea>,
|
dock: Entity<DockArea>,
|
||||||
|
|
||||||
/// App's Image Cache
|
|
||||||
image_cache: Entity<CoopImageCache>,
|
|
||||||
|
|
||||||
/// Event subscriptions
|
/// Event subscriptions
|
||||||
_subscriptions: SmallVec<[Subscription; 5]>,
|
_subscriptions: SmallVec<[Subscription; 5]>,
|
||||||
}
|
}
|
||||||
@@ -85,7 +82,6 @@ impl Workspace {
|
|||||||
|
|
||||||
let titlebar = cx.new(|_| TitleBar::new());
|
let titlebar = cx.new(|_| TitleBar::new());
|
||||||
let dock = cx.new(|cx| DockArea::new(window, cx));
|
let dock = cx.new(|cx| DockArea::new(window, cx));
|
||||||
let image_cache = CoopImageCache::new(IMAGE_CACHE_SIZE, cx);
|
|
||||||
|
|
||||||
let mut subscriptions = smallvec![];
|
let mut subscriptions = smallvec![];
|
||||||
|
|
||||||
@@ -235,7 +231,6 @@ impl Workspace {
|
|||||||
Self {
|
Self {
|
||||||
titlebar,
|
titlebar,
|
||||||
dock,
|
dock,
|
||||||
image_cache,
|
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -853,17 +848,13 @@ impl Render for Workspace {
|
|||||||
.relative()
|
.relative()
|
||||||
.size_full()
|
.size_full()
|
||||||
.child(
|
.child(
|
||||||
image_cache(self.image_cache.clone())
|
v_flex()
|
||||||
.relative()
|
.relative()
|
||||||
.size_full()
|
.size_full()
|
||||||
.child(
|
// Title Bar
|
||||||
v_flex()
|
.child(self.titlebar.clone())
|
||||||
.size_full()
|
// Dock
|
||||||
// Title Bar
|
.child(self.dock.clone()),
|
||||||
.child(self.titlebar.clone())
|
|
||||||
// Dock
|
|
||||||
.child(self.dock.clone()),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
// Notifications
|
// Notifications
|
||||||
.children(notification_layer)
|
.children(notification_layer)
|
||||||
@@ -5,21 +5,22 @@ edition.workspace = true
|
|||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
assets = { path = "../crates/assets" }
|
assets = { path = "../assets" }
|
||||||
ui = { path = "../crates/ui" }
|
ui = { path = "../ui" }
|
||||||
theme = { path = "../crates/theme" }
|
theme = { path = "../theme" }
|
||||||
common = { path = "../crates/common" }
|
common = { path = "../common" }
|
||||||
state = { path = "../crates/state" }
|
state = { path = "../state" }
|
||||||
device = { path = "../crates/device" }
|
device = { path = "../device" }
|
||||||
chat = { path = "../crates/chat" }
|
chat = { path = "../chat" }
|
||||||
settings = { path = "../crates/settings" }
|
chat_ui = { path = "../chat_ui" }
|
||||||
person = { path = "../crates/person" }
|
settings = { path = "../settings" }
|
||||||
relay_auth = { path = "../crates/relay_auth" }
|
person = { path = "../person" }
|
||||||
|
relay_auth = { path = "../relay_auth" }
|
||||||
|
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
|
gpui_web.workspace = true
|
||||||
gpui_platform.workspace = true
|
gpui_platform.workspace = true
|
||||||
gpui_tokio.workspace = true
|
gpui_tokio.workspace = true
|
||||||
gpui_web = { git = "https://github.com/zed-industries/zed" }
|
|
||||||
|
|
||||||
nostr-connect.workspace = true
|
nostr-connect.workspace = true
|
||||||
nostr-sdk.workspace = true
|
nostr-sdk.workspace = true
|
||||||
@@ -34,8 +35,8 @@ smol.workspace = true
|
|||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
oneshot.workspace = true
|
oneshot.workspace = true
|
||||||
webbrowser.workspace = true
|
webbrowser.workspace = true
|
||||||
tracing-subscriber.workspace = true
|
|
||||||
|
|
||||||
|
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
|
||||||
console_error_panic_hook = "0.1"
|
console_error_panic_hook = "0.1"
|
||||||
tracing-wasm = "0.2"
|
tracing-wasm = "0.2"
|
||||||
console_log = "1.0"
|
console_log = "1.0"
|
||||||
@@ -11,7 +11,7 @@ use gpui::{
|
|||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use person::PersonRegistry;
|
use person::PersonRegistry;
|
||||||
use state::{Announcement, CLIENT_NAME, NostrRegistry, StateEvent, TIMEOUT};
|
use state::{Announcement, NostrRegistry, StateEvent, TIMEOUT, app_name};
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
use ui::button::Button;
|
use ui::button::Button;
|
||||||
@@ -301,7 +301,7 @@ impl DeviceRegistry {
|
|||||||
// Construct an announcement event
|
// Construct an announcement event
|
||||||
let builder = EventBuilder::new(Kind::Custom(10044), "").tags(vec![
|
let builder = EventBuilder::new(Kind::Custom(10044), "").tags(vec![
|
||||||
Tag::custom(TagKind::custom("n"), vec![n]),
|
Tag::custom(TagKind::custom("n"), vec![n]),
|
||||||
Tag::client(CLIENT_NAME),
|
Tag::client(app_name()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Sign the event with user's signer
|
// Sign the event with user's signer
|
||||||
@@ -406,7 +406,7 @@ impl DeviceRegistry {
|
|||||||
// Construct an event for device key request
|
// Construct an event for device key request
|
||||||
let builder = EventBuilder::new(Kind::Custom(4454), "").tags(vec![
|
let builder = EventBuilder::new(Kind::Custom(4454), "").tags(vec![
|
||||||
Tag::custom(TagKind::custom("P"), vec![app_pubkey]),
|
Tag::custom(TagKind::custom("P"), vec![app_pubkey]),
|
||||||
Tag::client(CLIENT_NAME),
|
Tag::client(app_name()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Sign the event with user's signer
|
// Sign the event with user's signer
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
/// Client name (Application name)
|
/// Client name (Application name)
|
||||||
pub const CLIENT_NAME: &str = "Coop";
|
pub const CLIENT_NAME: &str = "Coop";
|
||||||
|
|
||||||
@@ -13,9 +15,6 @@ pub const KEYRING: &str = "Coop Safe Storage";
|
|||||||
/// Default timeout for subscription
|
/// Default timeout for subscription
|
||||||
pub const TIMEOUT: u64 = 2;
|
pub const TIMEOUT: u64 = 2;
|
||||||
|
|
||||||
/// Default image cache size
|
|
||||||
pub const IMAGE_CACHE_SIZE: usize = 20;
|
|
||||||
|
|
||||||
/// Default delay for searching
|
/// Default delay for searching
|
||||||
pub const FIND_DELAY: u64 = 600;
|
pub const FIND_DELAY: u64 = 600;
|
||||||
|
|
||||||
@@ -49,3 +48,15 @@ pub const BOOTSTRAP_RELAYS: [&str; 3] = [
|
|||||||
"wss://relay.primal.net",
|
"wss://relay.primal.net",
|
||||||
"wss://user.kindpag.es",
|
"wss://user.kindpag.es",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
static APP_NAME: OnceLock<String> = OnceLock::new();
|
||||||
|
|
||||||
|
/// Get the app name
|
||||||
|
pub fn app_name() -> &'static String {
|
||||||
|
APP_NAME.get_or_init(|| {
|
||||||
|
let devicename = whoami::devicename();
|
||||||
|
let platform = whoami::platform();
|
||||||
|
|
||||||
|
format!("{CLIENT_NAME} on {platform} ({devicename})")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -133,12 +133,6 @@ impl NostrRegistry {
|
|||||||
.signer(signer.clone())
|
.signer(signer.clone())
|
||||||
.database(lmdb)
|
.database(lmdb)
|
||||||
.gossip(NostrGossipMemory::unbounded())
|
.gossip(NostrGossipMemory::unbounded())
|
||||||
.gossip_config(
|
|
||||||
GossipConfig::default()
|
|
||||||
.sync_initial_timeout(Duration::from_millis(100))
|
|
||||||
.sync_idle_timeout(Duration::from_millis(100))
|
|
||||||
.no_background_refresh(),
|
|
||||||
)
|
|
||||||
.automatic_authentication(false)
|
.automatic_authentication(false)
|
||||||
.connect_timeout(Duration::from_secs(10))
|
.connect_timeout(Duration::from_secs(10))
|
||||||
.sleep_when_idle(SleepWhenIdle::Enabled {
|
.sleep_when_idle(SleepWhenIdle::Enabled {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::fmt::{self, Debug, Display, Formatter};
|
use std::fmt::{self, Debug, Display, Formatter};
|
||||||
|
|
||||||
use gpui::{AbsoluteLength, Axis, Length, Pixels};
|
use gpui::{AbsoluteLength, Axis, Corner, Length, Pixels};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A enum for defining the placement of the element.
|
/// A enum for defining the placement of the element.
|
||||||
@@ -49,6 +49,141 @@ impl Placement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The anchor position of an element.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||||
|
pub enum Anchor {
|
||||||
|
#[default]
|
||||||
|
#[serde(rename = "top-left")]
|
||||||
|
TopLeft,
|
||||||
|
#[serde(rename = "top-center")]
|
||||||
|
TopCenter,
|
||||||
|
#[serde(rename = "top-right")]
|
||||||
|
TopRight,
|
||||||
|
#[serde(rename = "bottom-left")]
|
||||||
|
BottomLeft,
|
||||||
|
#[serde(rename = "bottom-center")]
|
||||||
|
BottomCenter,
|
||||||
|
#[serde(rename = "bottom-right")]
|
||||||
|
BottomRight,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Anchor {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Anchor::TopLeft => write!(f, "TopLeft"),
|
||||||
|
Anchor::TopCenter => write!(f, "TopCenter"),
|
||||||
|
Anchor::TopRight => write!(f, "TopRight"),
|
||||||
|
Anchor::BottomLeft => write!(f, "BottomLeft"),
|
||||||
|
Anchor::BottomCenter => write!(f, "BottomCenter"),
|
||||||
|
Anchor::BottomRight => write!(f, "BottomRight"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Anchor {
|
||||||
|
/// Returns true if the anchor is at the top.
|
||||||
|
#[inline]
|
||||||
|
pub fn is_top(&self) -> bool {
|
||||||
|
matches!(self, Self::TopLeft | Self::TopCenter | Self::TopRight)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if the anchor is at the bottom.
|
||||||
|
#[inline]
|
||||||
|
pub fn is_bottom(&self) -> bool {
|
||||||
|
matches!(
|
||||||
|
self,
|
||||||
|
Self::BottomLeft | Self::BottomCenter | Self::BottomRight
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if the anchor is at the left.
|
||||||
|
#[inline]
|
||||||
|
pub fn is_left(&self) -> bool {
|
||||||
|
matches!(self, Self::TopLeft | Self::BottomLeft)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if the anchor is at the right.
|
||||||
|
#[inline]
|
||||||
|
pub fn is_right(&self) -> bool {
|
||||||
|
matches!(self, Self::TopRight | Self::BottomRight)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if the anchor is at the center.
|
||||||
|
#[inline]
|
||||||
|
pub fn is_center(&self) -> bool {
|
||||||
|
matches!(self, Self::TopCenter | Self::BottomCenter)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Swaps the vertical position of the anchor.
|
||||||
|
pub fn swap_vertical(&self) -> Self {
|
||||||
|
match self {
|
||||||
|
Anchor::TopLeft => Anchor::BottomLeft,
|
||||||
|
Anchor::TopCenter => Anchor::BottomCenter,
|
||||||
|
Anchor::TopRight => Anchor::BottomRight,
|
||||||
|
Anchor::BottomLeft => Anchor::TopLeft,
|
||||||
|
Anchor::BottomCenter => Anchor::TopCenter,
|
||||||
|
Anchor::BottomRight => Anchor::TopRight,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Swaps the horizontal position of the anchor.
|
||||||
|
pub fn swap_horizontal(&self) -> Self {
|
||||||
|
match self {
|
||||||
|
Anchor::TopLeft => Anchor::TopRight,
|
||||||
|
Anchor::TopCenter => Anchor::TopCenter,
|
||||||
|
Anchor::TopRight => Anchor::TopLeft,
|
||||||
|
Anchor::BottomLeft => Anchor::BottomRight,
|
||||||
|
Anchor::BottomCenter => Anchor::BottomCenter,
|
||||||
|
Anchor::BottomRight => Anchor::BottomLeft,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn other_side_corner_along(&self, axis: Axis) -> Anchor {
|
||||||
|
match axis {
|
||||||
|
Axis::Vertical => match self {
|
||||||
|
Self::TopLeft => Self::BottomLeft,
|
||||||
|
Self::TopCenter => Self::BottomCenter,
|
||||||
|
Self::TopRight => Self::BottomRight,
|
||||||
|
Self::BottomLeft => Self::TopLeft,
|
||||||
|
Self::BottomCenter => Self::TopCenter,
|
||||||
|
Self::BottomRight => Self::TopRight,
|
||||||
|
},
|
||||||
|
Axis::Horizontal => match self {
|
||||||
|
Self::TopLeft => Self::TopRight,
|
||||||
|
Self::TopCenter => Self::TopCenter,
|
||||||
|
Self::TopRight => Self::TopLeft,
|
||||||
|
Self::BottomLeft => Self::BottomRight,
|
||||||
|
Self::BottomCenter => Self::BottomCenter,
|
||||||
|
Self::BottomRight => Self::BottomLeft,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Corner> for Anchor {
|
||||||
|
fn from(corner: Corner) -> Self {
|
||||||
|
match corner {
|
||||||
|
Corner::TopLeft => Anchor::TopLeft,
|
||||||
|
Corner::TopRight => Anchor::TopRight,
|
||||||
|
Corner::BottomLeft => Anchor::BottomLeft,
|
||||||
|
Corner::BottomRight => Anchor::BottomRight,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Anchor> for Corner {
|
||||||
|
fn from(anchor: Anchor) -> Self {
|
||||||
|
match anchor {
|
||||||
|
Anchor::TopLeft => Corner::TopLeft,
|
||||||
|
Anchor::TopRight => Corner::TopRight,
|
||||||
|
Anchor::BottomLeft => Corner::BottomLeft,
|
||||||
|
Anchor::BottomRight => Corner::BottomRight,
|
||||||
|
Anchor::TopCenter => Corner::TopLeft,
|
||||||
|
Anchor::BottomCenter => Corner::BottomLeft,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A enum for defining the side of the element.
|
/// A enum for defining the side of the element.
|
||||||
///
|
///
|
||||||
/// See also: [`Placement`] if you need to define the 4 edges.
|
/// See also: [`Placement`] if you need to define the 4 edges.
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use gpui::{Anchor, Pixels, px};
|
use gpui::{Pixels, px};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{Edges, TITLEBAR_HEIGHT};
|
use crate::{Anchor, Edges, TITLEBAR_HEIGHT};
|
||||||
|
|
||||||
/// The settings for notifications.
|
/// The settings for notifications.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct NotificationSettings {
|
pub struct NotificationSettings {
|
||||||
/// The placement of the notification, default: [`Anchor::TopRight`]
|
/// The placement of the notification, default: [`Anchor::TopRight`]
|
||||||
pub placement: Anchor,
|
pub placement: Anchor,
|
||||||
|
|||||||
332
crates/ui/src/anchored.rs
Normal file
@@ -0,0 +1,332 @@
|
|||||||
|
//! This is a fork of gpui's anchored element that adds support for offsetting
|
||||||
|
//! https://github.com/zed-industries/zed/blob/b06f4088a3565c5e30663106ff79c1ced645d87a/crates/gpui/src/elements/anchored.rs
|
||||||
|
use gpui::{
|
||||||
|
AnyElement, App, Axis, Bounds, Display, Edges, Element, GlobalElementId, Half,
|
||||||
|
InspectorElementId, IntoElement, LayoutId, ParentElement, Pixels, Point, Position, Size, Style,
|
||||||
|
Window, point, px,
|
||||||
|
};
|
||||||
|
use smallvec::SmallVec;
|
||||||
|
use theme::Anchor;
|
||||||
|
|
||||||
|
/// The state that the anchored element element uses to track its children.
|
||||||
|
pub struct AnchoredState {
|
||||||
|
child_layout_ids: SmallVec<[LayoutId; 4]>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An anchored element that can be used to display UI that
|
||||||
|
/// will avoid overflowing the window bounds.
|
||||||
|
pub(crate) struct Anchored {
|
||||||
|
children: SmallVec<[AnyElement; 2]>,
|
||||||
|
anchor_corner: Anchor,
|
||||||
|
fit_mode: AnchoredFitMode,
|
||||||
|
anchor_position: Option<Point<Pixels>>,
|
||||||
|
position_mode: AnchoredPositionMode,
|
||||||
|
offset: Option<Point<Pixels>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// anchored gives you an element that will avoid overflowing the window bounds.
|
||||||
|
/// Its children should have no margin to avoid measurement issues.
|
||||||
|
pub(crate) fn anchored() -> Anchored {
|
||||||
|
Anchored {
|
||||||
|
children: SmallVec::new(),
|
||||||
|
anchor_corner: Anchor::TopLeft,
|
||||||
|
fit_mode: AnchoredFitMode::SwitchAnchor,
|
||||||
|
anchor_position: None,
|
||||||
|
position_mode: AnchoredPositionMode::Window,
|
||||||
|
offset: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
impl Anchored {
|
||||||
|
/// Sets which corner of the anchored element should be anchored to the current position.
|
||||||
|
pub fn anchor(mut self, anchor: Anchor) -> Self {
|
||||||
|
self.anchor_corner = anchor;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the position in window coordinates
|
||||||
|
/// (otherwise the location the anchored element is rendered is used)
|
||||||
|
pub fn position(mut self, anchor: Point<Pixels>) -> Self {
|
||||||
|
self.anchor_position = Some(anchor);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Offset the final position by this amount.
|
||||||
|
/// Useful when you want to anchor to an element but offset from it, such as in PopoverMenu.
|
||||||
|
pub fn offset(mut self, offset: Point<Pixels>) -> Self {
|
||||||
|
self.offset = Some(offset);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the position mode for this anchored element. Local will have this
|
||||||
|
/// interpret its [`Anchored::position`] as relative to the parent element.
|
||||||
|
/// While Window will have it interpret the position as relative to the window.
|
||||||
|
pub fn position_mode(mut self, mode: AnchoredPositionMode) -> Self {
|
||||||
|
self.position_mode = mode;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Snap to window edge instead of switching anchor corner when an overflow would occur.
|
||||||
|
pub fn snap_to_window(mut self) -> Self {
|
||||||
|
self.fit_mode = AnchoredFitMode::SnapToWindow;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Snap to window edge and leave some margins.
|
||||||
|
pub fn snap_to_window_with_margin(mut self, edges: impl Into<Edges<Pixels>>) -> Self {
|
||||||
|
self.fit_mode = AnchoredFitMode::SnapToWindowWithMargin(edges.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ParentElement for Anchored {
|
||||||
|
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
|
||||||
|
self.children.extend(elements)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Element for Anchored {
|
||||||
|
type PrepaintState = ();
|
||||||
|
type RequestLayoutState = AnchoredState;
|
||||||
|
|
||||||
|
fn id(&self) -> Option<gpui::ElementId> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn source_location(&self) -> Option<&'static core::panic::Location<'static>> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn request_layout(
|
||||||
|
&mut self,
|
||||||
|
_id: Option<&GlobalElementId>,
|
||||||
|
_inspector_id: Option<&InspectorElementId>,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) -> (gpui::LayoutId, Self::RequestLayoutState) {
|
||||||
|
let child_layout_ids = self
|
||||||
|
.children
|
||||||
|
.iter_mut()
|
||||||
|
.map(|child| child.request_layout(window, cx))
|
||||||
|
.collect::<SmallVec<_>>();
|
||||||
|
|
||||||
|
let anchored_style = Style {
|
||||||
|
position: Position::Absolute,
|
||||||
|
display: Display::Flex,
|
||||||
|
..Style::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let layout_id = window.request_layout(anchored_style, child_layout_ids.iter().copied(), cx);
|
||||||
|
|
||||||
|
(layout_id, AnchoredState { child_layout_ids })
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prepaint(
|
||||||
|
&mut self,
|
||||||
|
_id: Option<&GlobalElementId>,
|
||||||
|
_inspector_id: Option<&InspectorElementId>,
|
||||||
|
bounds: Bounds<Pixels>,
|
||||||
|
request_layout: &mut Self::RequestLayoutState,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) {
|
||||||
|
if request_layout.child_layout_ids.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut child_min = point(Pixels::MAX, Pixels::MAX);
|
||||||
|
let mut child_max = Point::default();
|
||||||
|
for child_layout_id in &request_layout.child_layout_ids {
|
||||||
|
let child_bounds = window.layout_bounds(*child_layout_id);
|
||||||
|
child_min = child_min.min(&child_bounds.origin);
|
||||||
|
child_max = child_max.max(&child_bounds.bottom_right());
|
||||||
|
}
|
||||||
|
let size: Size<Pixels> = (child_max - child_min).into();
|
||||||
|
|
||||||
|
let (origin, mut desired) = self.position_mode.get_position_and_bounds(
|
||||||
|
self.anchor_position,
|
||||||
|
self.anchor_corner,
|
||||||
|
size,
|
||||||
|
bounds,
|
||||||
|
self.offset,
|
||||||
|
);
|
||||||
|
|
||||||
|
let limits = Bounds {
|
||||||
|
origin: Point::default(),
|
||||||
|
size: window.viewport_size(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if self.fit_mode == AnchoredFitMode::SwitchAnchor {
|
||||||
|
let mut anchor_corner = self.anchor_corner;
|
||||||
|
|
||||||
|
if desired.left() < limits.left() || desired.right() > limits.right() {
|
||||||
|
let switched = Bounds::from_corner_and_size(
|
||||||
|
anchor_corner
|
||||||
|
.other_side_corner_along(Axis::Horizontal)
|
||||||
|
.into(),
|
||||||
|
origin,
|
||||||
|
size,
|
||||||
|
);
|
||||||
|
if !(switched.left() < limits.left() || switched.right() > limits.right()) {
|
||||||
|
anchor_corner = anchor_corner.other_side_corner_along(Axis::Horizontal);
|
||||||
|
desired = switched
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if desired.top() < limits.top() || desired.bottom() > limits.bottom() {
|
||||||
|
let switched = Bounds::from_corner_and_size(
|
||||||
|
anchor_corner.other_side_corner_along(Axis::Vertical).into(),
|
||||||
|
origin,
|
||||||
|
size,
|
||||||
|
);
|
||||||
|
if !(switched.top() < limits.top() || switched.bottom() > limits.bottom()) {
|
||||||
|
desired = switched;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let client_inset = window.client_inset().unwrap_or(px(0.));
|
||||||
|
let edges = match self.fit_mode {
|
||||||
|
AnchoredFitMode::SnapToWindowWithMargin(edges) => edges,
|
||||||
|
_ => Edges::default(),
|
||||||
|
}
|
||||||
|
.map(|edge| *edge + client_inset);
|
||||||
|
|
||||||
|
// Snap the horizontal edges of the anchored element to the horizontal edges of the window if
|
||||||
|
// its horizontal bounds overflow, aligning to the left if it is wider than the limits.
|
||||||
|
if desired.right() > limits.right() {
|
||||||
|
desired.origin.x -= desired.right() - limits.right() + edges.right;
|
||||||
|
}
|
||||||
|
if desired.left() < limits.left() {
|
||||||
|
desired.origin.x = limits.origin.x + edges.left;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Snap the vertical edges of the anchored element to the vertical edges of the window if
|
||||||
|
// its vertical bounds overflow, aligning to the top if it is taller than the limits.
|
||||||
|
if desired.bottom() > limits.bottom() {
|
||||||
|
desired.origin.y -= desired.bottom() - limits.bottom() + edges.bottom;
|
||||||
|
}
|
||||||
|
if desired.top() < limits.top() {
|
||||||
|
desired.origin.y = limits.origin.y + edges.top;
|
||||||
|
}
|
||||||
|
|
||||||
|
let offset = desired.origin - bounds.origin;
|
||||||
|
let offset = point(offset.x.round(), offset.y.round());
|
||||||
|
|
||||||
|
window.with_element_offset(offset, |window| {
|
||||||
|
for child in &mut self.children {
|
||||||
|
child.prepaint(window, cx);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn paint(
|
||||||
|
&mut self,
|
||||||
|
_id: Option<&GlobalElementId>,
|
||||||
|
_inspector_id: Option<&InspectorElementId>,
|
||||||
|
_bounds: Bounds<Pixels>,
|
||||||
|
_request_layout: &mut Self::RequestLayoutState,
|
||||||
|
_prepaint: &mut Self::PrepaintState,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) {
|
||||||
|
for child in &mut self.children {
|
||||||
|
child.paint(window, cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoElement for Anchored {
|
||||||
|
type Element = Self;
|
||||||
|
|
||||||
|
fn into_element(self) -> Self::Element {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Which algorithm to use when fitting the anchored element to be inside the window.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
|
pub enum AnchoredFitMode {
|
||||||
|
/// Snap the anchored element to the window edge.
|
||||||
|
SnapToWindow,
|
||||||
|
/// Snap to window edge and leave some margins.
|
||||||
|
SnapToWindowWithMargin(Edges<Pixels>),
|
||||||
|
/// Switch which corner anchor this anchored element is attached to.
|
||||||
|
SwitchAnchor,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Which algorithm to use when positioning the anchored element.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
|
pub enum AnchoredPositionMode {
|
||||||
|
/// Position the anchored element relative to the window.
|
||||||
|
Window,
|
||||||
|
/// Position the anchored element relative to its parent.
|
||||||
|
Local,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AnchoredPositionMode {
|
||||||
|
fn get_position_and_bounds(
|
||||||
|
&self,
|
||||||
|
anchor_position: Option<Point<Pixels>>,
|
||||||
|
anchor_corner: Anchor,
|
||||||
|
size: Size<Pixels>,
|
||||||
|
bounds: Bounds<Pixels>,
|
||||||
|
offset: Option<Point<Pixels>>,
|
||||||
|
) -> (Point<Pixels>, Bounds<Pixels>) {
|
||||||
|
let offset = offset.unwrap_or_default();
|
||||||
|
|
||||||
|
match self {
|
||||||
|
AnchoredPositionMode::Window => {
|
||||||
|
let anchor_position = anchor_position.unwrap_or(bounds.origin);
|
||||||
|
let bounds =
|
||||||
|
Self::from_corner_and_size(anchor_corner, anchor_position + offset, size);
|
||||||
|
(anchor_position, bounds)
|
||||||
|
}
|
||||||
|
AnchoredPositionMode::Local => {
|
||||||
|
let anchor_position = anchor_position.unwrap_or_default();
|
||||||
|
let bounds = Self::from_corner_and_size(
|
||||||
|
anchor_corner,
|
||||||
|
bounds.origin + anchor_position + offset,
|
||||||
|
size,
|
||||||
|
);
|
||||||
|
(anchor_position, bounds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref https://github.com/zed-industries/zed/blob/b06f4088a3565c5e30663106ff79c1ced645d87a/crates/gpui/src/geometry.rs#L863
|
||||||
|
fn from_corner_and_size(
|
||||||
|
anchor: Anchor,
|
||||||
|
origin: Point<Pixels>,
|
||||||
|
size: Size<Pixels>,
|
||||||
|
) -> Bounds<Pixels> {
|
||||||
|
let origin = match anchor {
|
||||||
|
Anchor::TopLeft => origin,
|
||||||
|
Anchor::TopCenter => Point {
|
||||||
|
x: origin.x - size.width.half(),
|
||||||
|
y: origin.y,
|
||||||
|
},
|
||||||
|
Anchor::TopRight => Point {
|
||||||
|
x: origin.x - size.width,
|
||||||
|
y: origin.y,
|
||||||
|
},
|
||||||
|
Anchor::BottomLeft => Point {
|
||||||
|
x: origin.x,
|
||||||
|
y: origin.y - size.height,
|
||||||
|
},
|
||||||
|
Anchor::BottomCenter => Point {
|
||||||
|
x: origin.x - size.width.half(),
|
||||||
|
y: origin.y - size.height,
|
||||||
|
},
|
||||||
|
Anchor::BottomRight => Point {
|
||||||
|
x: origin.x - size.width,
|
||||||
|
y: origin.y - size.height,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Bounds { origin, size }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Anchor, App, AppContext, Context, DefiniteLength, DismissEvent, DragMoveEvent, Empty, Entity,
|
App, AppContext, Context, Corner, DefiniteLength, DismissEvent, DragMoveEvent, Empty, Entity,
|
||||||
EventEmitter, FocusHandle, Focusable, InteractiveElement as _, IntoElement, MouseButton,
|
EventEmitter, FocusHandle, Focusable, InteractiveElement as _, IntoElement, MouseButton,
|
||||||
ParentElement, Pixels, Render, ScrollHandle, SharedString, StatefulInteractiveElement, Styled,
|
ParentElement, Pixels, Render, ScrollHandle, SharedString, StatefulInteractiveElement, Styled,
|
||||||
WeakEntity, Window, div, px, rems,
|
WeakEntity, Window, div, px, rems,
|
||||||
@@ -460,7 +460,7 @@ impl TabPanel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.anchor(Anchor::TopRight),
|
.anchor(Corner::TopRight),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub use anchored::*;
|
||||||
pub use element_ext::ElementExt;
|
pub use element_ext::ElementExt;
|
||||||
pub use event::InteractiveElementExt;
|
pub use event::InteractiveElementExt;
|
||||||
pub use focusable::FocusableCycle;
|
pub use focusable::FocusableCycle;
|
||||||
@@ -33,6 +34,7 @@ pub mod switch;
|
|||||||
pub mod tab;
|
pub mod tab;
|
||||||
pub mod tooltip;
|
pub mod tooltip;
|
||||||
|
|
||||||
|
mod anchored;
|
||||||
mod element_ext;
|
mod element_ext;
|
||||||
mod event;
|
mod event;
|
||||||
mod focusable;
|
mod focusable;
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
App, AppContext as _, ClickEvent, Context, DismissEvent, Entity, Focusable,
|
anchored, deferred, div, px, App, AppContext as _, ClickEvent, Context, DismissEvent, Entity,
|
||||||
InteractiveElement as _, IntoElement, KeyBinding, MouseButton, OwnedMenu, ParentElement,
|
Focusable, InteractiveElement as _, IntoElement, KeyBinding, MouseButton, OwnedMenu,
|
||||||
Render, SharedString, StatefulInteractiveElement, Styled, Subscription, Window, anchored,
|
ParentElement, Render, SharedString, StatefulInteractiveElement, Styled, Subscription, Window,
|
||||||
deferred, div, px,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::actions::{Cancel, SelectLeft, SelectRight};
|
use crate::actions::{Cancel, SelectLeft, SelectRight};
|
||||||
use crate::button::{Button, ButtonVariants};
|
use crate::button::{Button, ButtonVariants};
|
||||||
use crate::menu::PopupMenu;
|
use crate::menu::PopupMenu;
|
||||||
use crate::{Selectable, Sizable, h_flex};
|
use crate::{h_flex, Selectable, Sizable};
|
||||||
|
|
||||||
const CONTEXT: &str = "AppMenuBar";
|
const CONTEXT: &str = "AppMenuBar";
|
||||||
|
|
||||||
@@ -242,7 +241,7 @@ impl Render for AppMenu {
|
|||||||
.when(is_selected, |this| {
|
.when(is_selected, |this| {
|
||||||
this.child(deferred(
|
this.child(deferred(
|
||||||
anchored()
|
anchored()
|
||||||
.anchor(gpui::Anchor::TopLeft)
|
.anchor(gpui::Corner::TopLeft)
|
||||||
.snap_to_window_with_margin(px(8.))
|
.snap_to_window_with_margin(px(8.))
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Anchor, AnyElement, App, Context, DismissEvent, Element, ElementId, Entity, Focusable,
|
anchored, deferred, div, px, AnyElement, App, Context, Corner, DismissEvent, Element,
|
||||||
GlobalElementId, Hitbox, HitboxBehavior, InspectorElementId, InteractiveElement, IntoElement,
|
ElementId, Entity, Focusable, GlobalElementId, Hitbox, HitboxBehavior, InspectorElementId,
|
||||||
MouseButton, MouseDownEvent, ParentElement, Pixels, Point, StyleRefinement, Styled,
|
InteractiveElement, IntoElement, MouseButton, MouseDownEvent, ParentElement, Pixels, Point,
|
||||||
Subscription, Window, anchored, deferred, div, px,
|
StyleRefinement, Styled, Subscription, Window,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::menu::PopupMenu;
|
use crate::menu::PopupMenu;
|
||||||
@@ -41,7 +41,7 @@ pub struct ContextMenu<E: ParentElement + Styled + Sized> {
|
|||||||
menu: Option<Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>>,
|
menu: Option<Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>>,
|
||||||
// This is not in use, just for style refinement forwarding.
|
// This is not in use, just for style refinement forwarding.
|
||||||
_ignore_style: StyleRefinement,
|
_ignore_style: StyleRefinement,
|
||||||
anchor: Anchor,
|
anchor: Corner,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: ParentElement + Styled> ContextMenu<E> {
|
impl<E: ParentElement + Styled> ContextMenu<E> {
|
||||||
@@ -51,7 +51,7 @@ impl<E: ParentElement + Styled> ContextMenu<E> {
|
|||||||
id: id.into(),
|
id: id.into(),
|
||||||
element: Some(element),
|
element: Some(element),
|
||||||
menu: None,
|
menu: None,
|
||||||
anchor: Anchor::TopLeft,
|
anchor: Corner::TopLeft,
|
||||||
_ignore_style: StyleRefinement::default(),
|
_ignore_style: StyleRefinement::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Anchor, Context, DismissEvent, ElementId, Entity, Focusable, InteractiveElement, IntoElement,
|
Context, Corner, DismissEvent, ElementId, Entity, Focusable, InteractiveElement, IntoElement,
|
||||||
RenderOnce, SharedString, StyleRefinement, Styled, Window,
|
RenderOnce, SharedString, StyleRefinement, Styled, Window,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -18,13 +18,13 @@ pub trait DropdownMenu: Styled + Selectable + InteractiveElement + IntoElement +
|
|||||||
self,
|
self,
|
||||||
f: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
f: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
||||||
) -> DropdownMenuPopover<Self> {
|
) -> DropdownMenuPopover<Self> {
|
||||||
self.dropdown_menu_with_anchor(Anchor::TopLeft, f)
|
self.dropdown_menu_with_anchor(Corner::TopLeft, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a dropdown menu with the given items, anchored to the given corner
|
/// Create a dropdown menu with the given items, anchored to the given corner
|
||||||
fn dropdown_menu_with_anchor(
|
fn dropdown_menu_with_anchor(
|
||||||
mut self,
|
mut self,
|
||||||
anchor: impl Into<Anchor>,
|
anchor: impl Into<Corner>,
|
||||||
f: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
f: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
||||||
) -> DropdownMenuPopover<Self> {
|
) -> DropdownMenuPopover<Self> {
|
||||||
let style = self.style().clone();
|
let style = self.style().clone();
|
||||||
@@ -42,7 +42,7 @@ impl DropdownMenu for Avatar {}
|
|||||||
pub struct DropdownMenuPopover<T: Selectable + IntoElement + 'static> {
|
pub struct DropdownMenuPopover<T: Selectable + IntoElement + 'static> {
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
style: StyleRefinement,
|
style: StyleRefinement,
|
||||||
anchor: Anchor,
|
anchor: Corner,
|
||||||
trigger: T,
|
trigger: T,
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
builder: Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>,
|
builder: Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>,
|
||||||
@@ -54,7 +54,7 @@ where
|
|||||||
{
|
{
|
||||||
fn new(
|
fn new(
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
anchor: impl Into<Anchor>,
|
anchor: impl Into<Corner>,
|
||||||
trigger: T,
|
trigger: T,
|
||||||
builder: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
builder: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -68,7 +68,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the anchor corner for the dropdown menu popover.
|
/// Set the anchor corner for the dropdown menu popover.
|
||||||
pub fn anchor(mut self, anchor: impl Into<Anchor>) -> Self {
|
pub fn anchor(mut self, anchor: impl Into<Corner>) -> Self {
|
||||||
self.anchor = anchor.into();
|
self.anchor = anchor.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Action, Anchor, AnyElement, App, AppContext, Axis, Bounds, ClickEvent, Context, DismissEvent,
|
Action, AnyElement, App, AppContext, Axis, Bounds, ClickEvent, Context, Corner, DismissEvent,
|
||||||
Edges, Entity, EventEmitter, FocusHandle, Focusable, Half, InteractiveElement, IntoElement,
|
Edges, Entity, EventEmitter, FocusHandle, Focusable, Half, InteractiveElement, IntoElement,
|
||||||
KeyBinding, MouseDownEvent, OwnedMenuItem, ParentElement, Pixels, Point, Render, ScrollHandle,
|
KeyBinding, MouseDownEvent, OwnedMenuItem, ParentElement, Pixels, Point, Render, ScrollHandle,
|
||||||
SharedString, StatefulInteractiveElement, Styled, Subscription, WeakEntity, Window, anchored,
|
SharedString, StatefulInteractiveElement, Styled, Subscription, WeakEntity, Window, anchored,
|
||||||
@@ -299,7 +299,7 @@ pub struct PopupMenu {
|
|||||||
scroll_handle: ScrollHandle,
|
scroll_handle: ScrollHandle,
|
||||||
|
|
||||||
/// This will update on render
|
/// This will update on render
|
||||||
submenu_anchor: (Anchor, Pixels),
|
submenu_anchor: (Corner, Pixels),
|
||||||
|
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
@@ -322,7 +322,7 @@ impl PopupMenu {
|
|||||||
scroll_handle: ScrollHandle::default(),
|
scroll_handle: ScrollHandle::default(),
|
||||||
external_link_icon: true,
|
external_link_icon: true,
|
||||||
size: Size::default(),
|
size: Size::default(),
|
||||||
submenu_anchor: (Anchor::TopLeft, Pixels::ZERO),
|
submenu_anchor: (Corner::TopLeft, Pixels::ZERO),
|
||||||
_subscriptions: vec![],
|
_subscriptions: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -840,7 +840,7 @@ impl PopupMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn select_left(&mut self, _: &SelectLeft, window: &mut Window, cx: &mut Context<Self>) {
|
fn select_left(&mut self, _: &SelectLeft, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let handled = if matches!(self.submenu_anchor.0, Anchor::TopLeft | Anchor::BottomLeft) {
|
let handled = if matches!(self.submenu_anchor.0, Corner::TopLeft | Corner::BottomLeft) {
|
||||||
self._unselect_submenu(window, cx)
|
self._unselect_submenu(window, cx)
|
||||||
} else {
|
} else {
|
||||||
self._select_submenu(window, cx)
|
self._select_submenu(window, cx)
|
||||||
@@ -861,7 +861,7 @@ impl PopupMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn select_right(&mut self, _: &SelectRight, window: &mut Window, cx: &mut Context<Self>) {
|
fn select_right(&mut self, _: &SelectRight, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let handled = if matches!(self.submenu_anchor.0, Anchor::TopLeft | Anchor::BottomLeft) {
|
let handled = if matches!(self.submenu_anchor.0, Corner::TopLeft | Corner::BottomLeft) {
|
||||||
self._select_submenu(window, cx)
|
self._select_submenu(window, cx)
|
||||||
} else {
|
} else {
|
||||||
self._unselect_submenu(window, cx)
|
self._unselect_submenu(window, cx)
|
||||||
@@ -930,9 +930,8 @@ impl PopupMenu {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match parent.read(cx).submenu_anchor.0 {
|
match parent.read(cx).submenu_anchor.0 {
|
||||||
Anchor::TopLeft | Anchor::BottomLeft => Side::Left,
|
Corner::TopLeft | Corner::BottomLeft => Side::Left,
|
||||||
Anchor::TopRight | Anchor::BottomRight => Side::Right,
|
Corner::TopRight | Corner::BottomRight => Side::Right,
|
||||||
_ => Side::Left,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1042,14 +1041,14 @@ impl PopupMenu {
|
|||||||
let bounds = self.bounds;
|
let bounds = self.bounds;
|
||||||
let max_width = self.max_width();
|
let max_width = self.max_width();
|
||||||
let (anchor, left) = if max_width + bounds.origin.x > window.bounds().size.width {
|
let (anchor, left) = if max_width + bounds.origin.x > window.bounds().size.width {
|
||||||
(Anchor::TopRight, -px(16.))
|
(Corner::TopRight, -px(16.))
|
||||||
} else {
|
} else {
|
||||||
(Anchor::TopLeft, bounds.size.width - px(8.))
|
(Corner::TopLeft, bounds.size.width - px(8.))
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_bottom_pos = bounds.origin.y + bounds.size.height > window.bounds().size.height;
|
let is_bottom_pos = bounds.origin.y + bounds.size.height > window.bounds().size.height;
|
||||||
self.submenu_anchor = if is_bottom_pos {
|
self.submenu_anchor = if is_bottom_pos {
|
||||||
(anchor.other_side_along(gpui::Axis::Vertical), left)
|
(anchor.other_side_corner_along(gpui::Axis::Vertical), left)
|
||||||
} else {
|
} else {
|
||||||
(anchor, left)
|
(anchor, left)
|
||||||
};
|
};
|
||||||
@@ -1231,7 +1230,7 @@ impl PopupMenu {
|
|||||||
this.child({
|
this.child({
|
||||||
let (anchor, left) = self.submenu_anchor;
|
let (anchor, left) = self.submenu_anchor;
|
||||||
let is_bottom_pos =
|
let is_bottom_pos =
|
||||||
matches!(anchor, Anchor::BottomLeft | Anchor::BottomRight);
|
matches!(anchor, Corner::BottomLeft | Corner::BottomRight);
|
||||||
anchored()
|
anchored()
|
||||||
.anchor(anchor)
|
.anchor(anchor)
|
||||||
.child(
|
.child(
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Anchor, Animation, AnimationExt, AnyElement, App, AppContext, ClickEvent, Context,
|
Animation, AnimationExt, AnyElement, App, AppContext, ClickEvent, Context, DismissEvent,
|
||||||
DismissEvent, ElementId, Entity, EventEmitter, InteractiveElement as _, IntoElement,
|
ElementId, Entity, EventEmitter, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||||
ParentElement as _, Render, SharedString, StatefulInteractiveElement, StyleRefinement, Styled,
|
Render, SharedString, StatefulInteractiveElement, StyleRefinement, Styled, Subscription,
|
||||||
Subscription, Window, div, px, relative,
|
Window, div, px, relative,
|
||||||
};
|
};
|
||||||
use theme::ActiveTheme;
|
use theme::{ActiveTheme, Anchor};
|
||||||
|
|
||||||
use crate::animation::cubic_bezier;
|
use crate::animation::cubic_bezier;
|
||||||
use crate::button::{Button, ButtonVariants as _};
|
use crate::button::{Button, ButtonVariants as _};
|
||||||
@@ -288,7 +288,6 @@ impl Styled for Notification {
|
|||||||
&mut self.style
|
&mut self.style
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for Notification {
|
impl Render for Notification {
|
||||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let content = self
|
let content = self
|
||||||
@@ -424,17 +423,12 @@ impl Render for Notification {
|
|||||||
let y_offset = px(0.) + delta * px(45.);
|
let y_offset = px(0.) + delta * px(45.);
|
||||||
that.top(px(0.) + y_offset)
|
that.top(px(0.) + y_offset)
|
||||||
}
|
}
|
||||||
_ => that,
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let opacity = delta;
|
let opacity = delta;
|
||||||
let y_offset = match placement {
|
let y_offset = match placement {
|
||||||
Anchor::TopLeft | Anchor::TopRight | Anchor::TopCenter => {
|
placement if placement.is_top() => px(-45.) + delta * px(45.),
|
||||||
px(-45.) + delta * px(45.)
|
placement if placement.is_bottom() => px(45.) - delta * px(45.),
|
||||||
}
|
|
||||||
Anchor::BottomLeft | Anchor::BottomRight | Anchor::BottomCenter => {
|
|
||||||
px(45.) - delta * px(45.)
|
|
||||||
}
|
|
||||||
_ => px(0.),
|
_ => px(0.),
|
||||||
};
|
};
|
||||||
this.top(px(0.) + y_offset)
|
this.top(px(0.) + y_offset)
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Anchor, AnyElement, App, Bounds, Context, Deferred, DismissEvent, Div, ElementId, EventEmitter,
|
AnyElement, App, Bounds, Context, Deferred, DismissEvent, Div, ElementId, EventEmitter,
|
||||||
FocusHandle, Focusable, InteractiveElement as _, IntoElement, KeyBinding, MouseButton,
|
FocusHandle, Focusable, Half, InteractiveElement as _, IntoElement, KeyBinding, MouseButton,
|
||||||
ParentElement, Pixels, Point, Render, RenderOnce, Stateful, StyleRefinement, Styled,
|
ParentElement, Pixels, Point, Render, RenderOnce, Stateful, StyleRefinement, Styled,
|
||||||
Subscription, Window, anchored, deferred, div, px,
|
Subscription, Window, deferred, div, px,
|
||||||
};
|
};
|
||||||
|
use theme::Anchor;
|
||||||
|
|
||||||
use crate::actions::Cancel;
|
use crate::actions::Cancel;
|
||||||
use crate::{ElementExt, Selectable, StyledExt as _, v_flex};
|
use crate::{ElementExt, Selectable, StyledExt as _, anchored, v_flex};
|
||||||
|
|
||||||
const CONTEXT: &str = "Popover";
|
const CONTEXT: &str = "Popover";
|
||||||
|
|
||||||
@@ -174,26 +175,19 @@ impl Popover {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn resolved_corner(anchor: Anchor, trigger_bounds: Bounds<Pixels>) -> Point<Pixels> {
|
fn resolved_corner(anchor: Anchor, trigger_bounds: Bounds<Pixels>) -> Point<Pixels> {
|
||||||
match anchor {
|
let offset = if anchor.is_center() {
|
||||||
Anchor::TopLeft => trigger_bounds.origin,
|
gpui::point(trigger_bounds.size.width.half(), px(0.))
|
||||||
Anchor::TopCenter => trigger_bounds.top_center(),
|
} else {
|
||||||
Anchor::TopRight => trigger_bounds.top_right(),
|
Point::default()
|
||||||
Anchor::BottomLeft => Point {
|
};
|
||||||
x: trigger_bounds.origin.x,
|
|
||||||
y: trigger_bounds.origin.y - trigger_bounds.size.height,
|
trigger_bounds.corner(anchor.swap_vertical().into())
|
||||||
},
|
+ offset
|
||||||
Anchor::BottomCenter => Point {
|
+ Point {
|
||||||
x: trigger_bounds.top_center().x,
|
x: px(0.),
|
||||||
y: trigger_bounds.origin.y - trigger_bounds.size.height,
|
y: -trigger_bounds.size.height,
|
||||||
},
|
}
|
||||||
Anchor::BottomRight => Point {
|
|
||||||
x: trigger_bounds.top_right().x,
|
|
||||||
y: trigger_bounds.origin.y - trigger_bounds.size.height,
|
|
||||||
},
|
|
||||||
// Fallback for LeftCenter/RightCenter – adjust as needed.
|
|
||||||
_ => trigger_bounds.origin,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +330,6 @@ impl Popover {
|
|||||||
.map(|this| match anchor {
|
.map(|this| match anchor {
|
||||||
Anchor::TopLeft | Anchor::TopCenter | Anchor::TopRight => this.top_1(),
|
Anchor::TopLeft | Anchor::TopCenter | Anchor::TopRight => this.top_1(),
|
||||||
Anchor::BottomLeft | Anchor::BottomCenter | Anchor::BottomRight => this.bottom_1(),
|
Anchor::BottomLeft | Anchor::BottomCenter | Anchor::BottomRight => this.bottom_1(),
|
||||||
Anchor::LeftCenter | Anchor::RightCenter => this.top_1(), // Fallback for centered
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::rc::Rc;
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Anchor, App, Axis, BorderStyle, Bounds, ContentMask, CursorStyle, Edges, Element, ElementId,
|
App, Axis, BorderStyle, Bounds, ContentMask, Corner, CursorStyle, Edges, Element, ElementId,
|
||||||
GlobalElementId, Hitbox, HitboxBehavior, Hsla, InspectorElementId, IntoElement, IsZero,
|
GlobalElementId, Hitbox, HitboxBehavior, Hsla, InspectorElementId, IntoElement, IsZero,
|
||||||
LayoutId, ListState, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PaintQuad, Pixels, Point,
|
LayoutId, ListState, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PaintQuad, Pixels, Point,
|
||||||
Position, ScrollHandle, ScrollWheelEvent, Size, Style, UniformListScrollHandle, Window, fill,
|
Position, ScrollHandle, ScrollWheelEvent, Size, Style, UniformListScrollHandle, Window, fill,
|
||||||
@@ -648,14 +648,14 @@ impl Element for Scrollbar {
|
|||||||
// The clickable area of the thumb
|
// The clickable area of the thumb
|
||||||
let thumb_length = thumb_end - thumb_start - inset * 2;
|
let thumb_length = thumb_end - thumb_start - inset * 2;
|
||||||
let thumb_bounds = if is_vertical {
|
let thumb_bounds = if is_vertical {
|
||||||
Bounds::from_anchor_and_size(
|
Bounds::from_corner_and_size(
|
||||||
Anchor::TopRight,
|
Corner::TopRight,
|
||||||
bounds.top_right() + point(-inset, inset + thumb_start),
|
bounds.top_right() + point(-inset, inset + thumb_start),
|
||||||
size(WIDTH, thumb_length),
|
size(WIDTH, thumb_length),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Bounds::from_anchor_and_size(
|
Bounds::from_corner_and_size(
|
||||||
Anchor::BottomLeft,
|
Corner::BottomLeft,
|
||||||
bounds.bottom_left() + point(inset + thumb_start, -inset),
|
bounds.bottom_left() + point(inset + thumb_start, -inset),
|
||||||
size(thumb_length, WIDTH),
|
size(thumb_length, WIDTH),
|
||||||
)
|
)
|
||||||
@@ -663,14 +663,14 @@ impl Element for Scrollbar {
|
|||||||
|
|
||||||
// The actual render area of the thumb
|
// The actual render area of the thumb
|
||||||
let thumb_fill_bounds = if is_vertical {
|
let thumb_fill_bounds = if is_vertical {
|
||||||
Bounds::from_anchor_and_size(
|
Bounds::from_corner_and_size(
|
||||||
Anchor::TopRight,
|
Corner::TopRight,
|
||||||
bounds.top_right() + point(-inset, inset + thumb_start),
|
bounds.top_right() + point(-inset, inset + thumb_start),
|
||||||
size(thumb_width, thumb_length),
|
size(thumb_width, thumb_length),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Bounds::from_anchor_and_size(
|
Bounds::from_corner_and_size(
|
||||||
Anchor::BottomLeft,
|
Corner::BottomLeft,
|
||||||
bounds.bottom_left() + point(inset + thumb_start, -inset),
|
bounds.bottom_left() + point(inset + thumb_start, -inset),
|
||||||
size(thumb_length, thumb_width),
|
size(thumb_length, thumb_width),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Anchor, AnyElement, App, Div, Edges, ElementId, InteractiveElement, IntoElement, ParentElement,
|
AnyElement, App, Corner, Div, Edges, ElementId, InteractiveElement, IntoElement, ParentElement,
|
||||||
RenderOnce, ScrollHandle, Stateful, StatefulInteractiveElement as _, StyleRefinement, Styled,
|
RenderOnce, ScrollHandle, Stateful, StatefulInteractiveElement as _, StyleRefinement, Styled,
|
||||||
Window, div, px,
|
Window, div, px,
|
||||||
};
|
};
|
||||||
@@ -282,7 +282,7 @@ impl RenderOnce for TabBar {
|
|||||||
|
|
||||||
this
|
this
|
||||||
})
|
})
|
||||||
.anchor(Anchor::TopRight),
|
.anchor(Corner::TopRight),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.when_some(self.suffix, |this, suffix| this.child(suffix))
|
.when_some(self.suffix, |this, suffix| this.child(suffix))
|
||||||
|
|||||||
@@ -8,7 +8,5 @@ targets = [
|
|||||||
"x86_64-unknown-linux-gnu",
|
"x86_64-unknown-linux-gnu",
|
||||||
"x86_64-pc-windows-msvc",
|
"x86_64-pc-windows-msvc",
|
||||||
"aarch64-pc-windows-msvc",
|
"aarch64-pc-windows-msvc",
|
||||||
"aarch64-apple-ios",
|
|
||||||
"aarch64-linux-android",
|
|
||||||
"wasm32-unknown-unknown"
|
"wasm32-unknown-unknown"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -98,9 +98,9 @@ cp $(find_libs) "${coop_dir}/lib"
|
|||||||
|
|
||||||
# Icons
|
# Icons
|
||||||
mkdir -p "${coop_dir}/share/icons/hicolor/512x512/apps"
|
mkdir -p "${coop_dir}/share/icons/hicolor/512x512/apps"
|
||||||
cp "desktop/resources/icon.png" "${coop_dir}/share/icons/hicolor/512x512/apps/coop.png"
|
cp "crates/coop/resources/icon.png" "${coop_dir}/share/icons/hicolor/512x512/apps/coop.png"
|
||||||
mkdir -p "${coop_dir}/share/icons/hicolor/1024x1024/apps"
|
mkdir -p "${coop_dir}/share/icons/hicolor/1024x1024/apps"
|
||||||
cp "desktop/resources/icon@2x.png" "${coop_dir}/share/icons/hicolor/1024x1024/apps/coop.png"
|
cp "crates/coop/resources/icon@2x.png" "${coop_dir}/share/icons/hicolor/1024x1024/apps/coop.png"
|
||||||
|
|
||||||
# .desktop
|
# .desktop
|
||||||
export DO_STARTUP_NOTIFY="true"
|
export DO_STARTUP_NOTIFY="true"
|
||||||
@@ -110,7 +110,7 @@ export APP_ARGS="%U"
|
|||||||
export APP_NAME="Coop"
|
export APP_NAME="Coop"
|
||||||
|
|
||||||
mkdir -p "${coop_dir}/share/applications"
|
mkdir -p "${coop_dir}/share/applications"
|
||||||
envsubst < "desktop/resources/coop.desktop.in" > "${coop_dir}/share/applications/coop.desktop"
|
envsubst < "crates/coop/resources/coop.desktop.in" > "${coop_dir}/share/applications/coop.desktop"
|
||||||
|
|
||||||
# Create archive out of everything that's in the temp directory
|
# Create archive out of everything that's in the temp directory
|
||||||
arch=$(uname -m)
|
arch=$(uname -m)
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ export DO_STARTUP_NOTIFY="true"
|
|||||||
export APP_NAME="Coop"
|
export APP_NAME="Coop"
|
||||||
export APP_ICON="\${SNAP}/meta/gui/coop.png"
|
export APP_ICON="\${SNAP}/meta/gui/coop.png"
|
||||||
export APP_ARGS="%U"
|
export APP_ARGS="%U"
|
||||||
envsubst < "desktop/resources/coop.desktop.in" > "snap/gui/coop.desktop"
|
envsubst < "crates/coop/resources/coop.desktop.in" > "snap/gui/coop.desktop"
|
||||||
cp "desktop/resources/icon.png" "snap/gui/coop.png"
|
cp "crates/coop/resources/icon.png" "snap/gui/coop.png"
|
||||||
|
|
||||||
# Generate snapcraft.yaml with version and architecture
|
# Generate snapcraft.yaml with version and architecture
|
||||||
RELEASE_VERSION="$1" ARCH_SUFFIX="$ARCH_SUFFIX" envsubst < desktop/resources/snap/snapcraft.yaml.in > snap/snapcraft.yaml
|
RELEASE_VERSION="$1" ARCH_SUFFIX="$ARCH_SUFFIX" envsubst < crates/coop/resources/snap/snapcraft.yaml.in > snap/snapcraft.yaml
|
||||||
|
|
||||||
# Clean previous builds
|
# Clean previous builds
|
||||||
snapcraft clean
|
snapcraft clean
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export ICON_FILE="icon"
|
|||||||
export CHANNEL="stable"
|
export CHANNEL="stable"
|
||||||
|
|
||||||
# Generate manifest
|
# Generate manifest
|
||||||
envsubst < "desktop/resources/flatpak/manifest-template.json" > "$APP_ID.json"
|
envsubst < "crates/coop/resources/flatpak/manifest-template.json" > "$APP_ID.json"
|
||||||
|
|
||||||
# Build Flatpak
|
# Build Flatpak
|
||||||
flatpak-builder --user --install --force-clean build "$APP_ID.json"
|
flatpak-builder --user --install --force-clean build "$APP_ID.json"
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ echo " Created flathub/release-info.xml"
|
|||||||
# Step 4: Generate the metainfo file with release info
|
# Step 4: Generate the metainfo file with release info
|
||||||
echo "[4/5] Generating metainfo.xml..."
|
echo "[4/5] Generating metainfo.xml..."
|
||||||
export APP_ID APP_NAME BRANDING_LIGHT BRANDING_DARK
|
export APP_ID APP_NAME BRANDING_LIGHT BRANDING_DARK
|
||||||
cat desktop/resources/flatpak/coop.metainfo.xml.in | \
|
cat crates/coop/resources/flatpak/coop.metainfo.xml.in | \
|
||||||
sed -e "/@release_info@/r flathub/release-info.xml" -e '/@release_info@/d' \
|
sed -e "/@release_info@/r flathub/release-info.xml" -e '/@release_info@/d' \
|
||||||
> flathub/${APP_ID}.metainfo.xml
|
> flathub/${APP_ID}.metainfo.xml
|
||||||
echo " Created flathub/${APP_ID}.metainfo.xml"
|
echo " Created flathub/${APP_ID}.metainfo.xml"
|
||||||
@@ -153,8 +153,8 @@ modules:
|
|||||||
- install -Dm755 target/release/coop /app/bin/coop
|
- install -Dm755 target/release/coop /app/bin/coop
|
||||||
|
|
||||||
# Install icons
|
# Install icons
|
||||||
- install -Dm644 desktop/resources/icon.png /app/share/icons/hicolor/512x512/apps/su.reya.coop.png
|
- install -Dm644 crates/coop/resources/icon.png /app/share/icons/hicolor/512x512/apps/su.reya.coop.png
|
||||||
- install -Dm644 desktop/resources/icon@2x.png /app/share/icons/hicolor/1024x1024/apps/su.reya.coop.png
|
- install -Dm644 crates/coop/resources/icon@2x.png /app/share/icons/hicolor/1024x1024/apps/su.reya.coop.png
|
||||||
|
|
||||||
# Install desktop file
|
# Install desktop file
|
||||||
- |
|
- |
|
||||||
@@ -164,7 +164,7 @@ modules:
|
|||||||
export APP_CLI="coop"
|
export APP_CLI="coop"
|
||||||
export APP_ARGS="%U"
|
export APP_ARGS="%U"
|
||||||
export DO_STARTUP_NOTIFY="true"
|
export DO_STARTUP_NOTIFY="true"
|
||||||
envsubst < desktop/resources/coop.desktop.in > coop.desktop
|
envsubst < crates/coop/resources/coop.desktop.in > coop.desktop
|
||||||
install -Dm644 coop.desktop /app/share/applications/su.reya.coop.desktop
|
install -Dm644 coop.desktop /app/share/applications/su.reya.coop.desktop
|
||||||
|
|
||||||
# Install metainfo (use pre-generated one with release info)
|
# Install metainfo (use pre-generated one with release info)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ fi
|
|||||||
|
|
||||||
NEW_VERSION="$1"
|
NEW_VERSION="$1"
|
||||||
WORKSPACE_CARGO="Cargo.toml"
|
WORKSPACE_CARGO="Cargo.toml"
|
||||||
CRATE_CARGO="desktop/Cargo.toml"
|
CRATE_CARGO="crates/coop/Cargo.toml"
|
||||||
|
|
||||||
# Check if both Cargo.toml files exist
|
# Check if both Cargo.toml files exist
|
||||||
if [ ! -f "$WORKSPACE_CARGO" ]; then
|
if [ ! -f "$WORKSPACE_CARGO" ]; then
|
||||||
|
|||||||