Introducing Damus Notedeck: a nostr browser

This splits notedeck into:

- notedeck
- notedeck_chrome
- notedeck_columns

The `notedeck` crate is the library that `notedeck_chrome` and
`notedeck_columns`, use. It contains common functionality related to
notedeck apps such as the NoteCache, ImageCache, etc.

The `notedeck_chrome` crate is the binary and ui chrome. It is
responsible for managing themes, user accounts, signing, data paths,
nostrdb, image caches etc. It will eventually have its own ui which has
yet to be determined.  For now it just manages the browser data, which
is passed to apps via a new struct called `AppContext`.

`notedeck_columns` is our columns app, with less responsibility now that
more things are handled by `notedeck_chrome`

There is still much work left to do before this is a proper browser:

- process isolation
- sandboxing
- etc

This is the beginning of a new era! We're just getting started.

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-12-11 04:22:05 -08:00
parent aa14fb092d
commit ec755493d9
146 changed files with 2820 additions and 2794 deletions

View File

@@ -1,14 +1,14 @@
use crate::actionbar::NoteAction;
use crate::images::ImageType;
use crate::imgcache::ImageCache;
use crate::notecache::NoteCache;
use crate::ui;
use crate::ui::note::{NoteOptions, NoteResponse};
use crate::ui::ProfilePic;
use crate::{colors, ui};
use egui::{Color32, Hyperlink, Image, RichText};
use nostrdb::{BlockType, Mention, Ndb, Note, NoteKey, Transaction};
use tracing::warn;
use notedeck::{ImageCache, NoteCache};
pub struct NoteContents<'a> {
ndb: &'a Ndb,
img_cache: &'a mut ImageCache,
@@ -94,8 +94,8 @@ pub fn render_note_preview(
return ui
.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.colored_label(colors::PURPLE, "@");
ui.colored_label(colors::PURPLE, &id_str[4..16]);
ui.colored_label(link_color, "@");
ui.colored_label(link_color, &id_str[4..16]);
})
.response;
*/
@@ -145,6 +145,7 @@ fn render_note_contents(
let mut images: Vec<String> = vec![];
let mut inline_note: Option<(&[u8; 32], &str)> = None;
let hide_media = options.has_hide_media();
let link_color = ui.visuals().hyperlink_color;
let response = ui.horizontal_wrapped(|ui| {
let blocks = if let Ok(blocks) = ndb.get_blocks_by_key(txn, note_key) {
@@ -177,14 +178,14 @@ fn render_note_contents(
}
_ => {
ui.colored_label(colors::PURPLE, format!("@{}", &block.as_str()[4..16]));
ui.colored_label(link_color, format!("@{}", &block.as_str()[4..16]));
}
},
BlockType::Hashtag => {
#[cfg(feature = "profiling")]
puffin::profile_scope!("hashtag contents");
ui.colored_label(colors::PURPLE, format!("#{}", block.as_str()));
ui.colored_label(link_color, format!("#{}", block.as_str()));
}
BlockType::Url => {
@@ -195,7 +196,7 @@ fn render_note_contents(
#[cfg(feature = "profiling")]
puffin::profile_scope!("url contents");
ui.add(Hyperlink::from_label_and_url(
RichText::new(block.as_str()).color(colors::PURPLE),
RichText::new(block.as_str()).color(link_color),
block.as_str(),
));
}
@@ -208,7 +209,7 @@ fn render_note_contents(
}
_ => {
ui.colored_label(colors::PURPLE, block.as_str());
ui.colored_label(link_color, block.as_str());
}
}
}

View File

@@ -1,4 +1,3 @@
use crate::colors;
use egui::{Rect, Vec2};
use enostr::{NoteId, Pubkey};
use nostrdb::{Note, NoteKey};
@@ -136,7 +135,7 @@ impl NoteContextButton {
let translated_radius = (cur_radius - 1.0) / 2.0;
// This works in both themes
let color = colors::GRAY_SECONDARY;
let color = ui.style().visuals.noninteractive().fg_stroke.color;
// Draw circles
let painter = ui.painter_at(put_at);

View File

@@ -14,16 +14,14 @@ pub use reply::PostReplyView;
use crate::{
actionbar::NoteAction,
app_style::NotedeckTextStyle,
colors,
imgcache::ImageCache,
notecache::{CachedNote, NoteCache},
ui::{self, View},
};
use egui::emath::{pos2, Vec2};
use egui::{Id, Label, Pos2, Rect, Response, RichText, Sense};
use enostr::{NoteId, Pubkey};
use nostrdb::{Ndb, Note, NoteKey, NoteReply, Transaction};
use notedeck::{CachedNote, ImageCache, NoteCache, NotedeckTextStyle};
use super::profile::preview::{get_display_name, one_line_display_name_widget};
@@ -80,15 +78,9 @@ fn reply_desc(
let size = 10.0;
let selectable = false;
let color = ui.style().visuals.noninteractive().fg_stroke.color;
ui.add(
Label::new(
RichText::new("replying to")
.size(size)
.color(colors::GRAY_SECONDARY),
)
.selectable(selectable),
);
ui.add(Label::new(RichText::new("replying to").size(size).color(color)).selectable(selectable));
let reply = if let Some(reply) = note_reply.reply() {
reply
@@ -99,14 +91,7 @@ fn reply_desc(
let reply_note = if let Ok(reply_note) = ndb.get_note_by_id(txn, reply.id) {
reply_note
} else {
ui.add(
Label::new(
RichText::new("a note")
.size(size)
.color(colors::GRAY_SECONDARY),
)
.selectable(selectable),
);
ui.add(Label::new(RichText::new("a note").size(size).color(color)).selectable(selectable));
return;
};
@@ -117,14 +102,7 @@ fn reply_desc(
.size(size)
.selectable(selectable),
);
ui.add(
Label::new(
RichText::new("'s note")
.size(size)
.color(colors::GRAY_SECONDARY),
)
.selectable(selectable),
);
ui.add(Label::new(RichText::new("'s note").size(size).color(color)).selectable(selectable));
} else if let Some(root) = note_reply.root() {
// replying to another post in a thread, not the root
@@ -137,12 +115,8 @@ fn reply_desc(
.selectable(selectable),
);
ui.add(
Label::new(
RichText::new("'s note")
.size(size)
.color(colors::GRAY_SECONDARY),
)
.selectable(selectable),
Label::new(RichText::new("'s note").size(size).color(color))
.selectable(selectable),
);
} else {
// replying to bob in alice's thread
@@ -153,8 +127,7 @@ fn reply_desc(
.selectable(selectable),
);
ui.add(
Label::new(RichText::new("in").size(size).color(colors::GRAY_SECONDARY))
.selectable(selectable),
Label::new(RichText::new("in").size(size).color(color)).selectable(selectable),
);
ui.add(
ui::Mention::new(ndb, img_cache, txn, root_note.pubkey())
@@ -162,12 +135,8 @@ fn reply_desc(
.selectable(selectable),
);
ui.add(
Label::new(
RichText::new("'s thread")
.size(size)
.color(colors::GRAY_SECONDARY),
)
.selectable(selectable),
Label::new(RichText::new("'s thread").size(size).color(color))
.selectable(selectable),
);
}
} else {
@@ -177,12 +146,8 @@ fn reply_desc(
.selectable(selectable),
);
ui.add(
Label::new(
RichText::new("in someone's thread")
.size(size)
.color(colors::GRAY_SECONDARY),
)
.selectable(selectable),
Label::new(RichText::new("in someone's thread").size(size).color(color))
.selectable(selectable),
);
}
}
@@ -382,6 +347,7 @@ impl<'a> NoteView<'a> {
});
ui.add_space(6.0);
let resp = ui.add(one_line_display_name_widget(
ui.visuals(),
get_display_name(profile.as_ref().ok()),
style,
));
@@ -391,10 +357,11 @@ impl<'a> NoteView<'a> {
ui.add(ui::ProfilePreview::new(rec, self.img_cache));
});
}
let color = ui.style().visuals.noninteractive().fg_stroke.color;
ui.add_space(4.0);
ui.label(
RichText::new("Reposted")
.color(colors::GRAY_SECONDARY)
.color(color)
.text_style(style.text_style()),
);
});
@@ -690,9 +657,8 @@ fn render_note_actionbar(
}
fn secondary_label(ui: &mut egui::Ui, s: impl Into<String>) {
ui.add(Label::new(
RichText::new(s).size(10.0).color(colors::GRAY_SECONDARY),
));
let color = ui.style().visuals.noninteractive().fg_stroke.color;
ui.add(Label::new(RichText::new(s).size(10.0).color(color)));
}
fn render_reltime(
@@ -718,9 +684,9 @@ fn render_reltime(
fn reply_button(ui: &mut egui::Ui, note_key: NoteKey) -> egui::Response {
let img_data = if ui.style().visuals.dark_mode {
egui::include_image!("../../../assets/icons/reply.png")
egui::include_image!("../../../../../assets/icons/reply.png")
} else {
egui::include_image!("../../../assets/icons/reply-dark.png")
egui::include_image!("../../../../../assets/icons/reply-dark.png")
};
let (rect, size, resp) =
@@ -737,9 +703,9 @@ fn reply_button(ui: &mut egui::Ui, note_key: NoteKey) -> egui::Response {
fn repost_icon(dark_mode: bool) -> egui::Image<'static> {
let img_data = if dark_mode {
egui::include_image!("../../../assets/icons/repost_icon_4x.png")
egui::include_image!("../../../../../assets/icons/repost_icon_4x.png")
} else {
egui::include_image!("../../../assets/icons/repost_light_4x.png")
egui::include_image!("../../../../../assets/icons/repost_light_4x.png")
};
egui::Image::new(img_data)
}

View File

@@ -1,6 +1,4 @@
use crate::draft::{Draft, Drafts};
use crate::imgcache::ImageCache;
use crate::notecache::NoteCache;
use crate::post::NewPost;
use crate::ui::{self, Preview, PreviewConfig, View};
use crate::Result;
@@ -10,6 +8,8 @@ use enostr::{FilledKeypair, FullKeypair, NoteId, RelayPool};
use nostrdb::{Config, Ndb, Transaction};
use tracing::info;
use notedeck::{ImageCache, NoteCache};
use super::contents::render_note_preview;
pub struct PostView<'a> {

View File

@@ -1,7 +1,8 @@
use enostr::{FilledKeypair, NoteId};
use nostrdb::Ndb;
use notedeck::{ImageCache, NoteCache};
use crate::{draft::Draft, imgcache::ImageCache, notecache::NoteCache, ui};
use crate::{draft::Draft, ui};
use super::{PostResponse, PostType};

View File

@@ -1,11 +1,11 @@
use crate::draft::Draft;
use crate::imgcache::ImageCache;
use crate::notecache::NoteCache;
use crate::ui;
use crate::ui::note::{PostResponse, PostType};
use enostr::{FilledKeypair, NoteId};
use nostrdb::Ndb;
use notedeck::{ImageCache, NoteCache};
pub struct PostReplyView<'a> {
ndb: &'a Ndb,
poster: FilledKeypair<'a>,