Skip to content

Commit 400050f

Browse files
committed
Merge remote-tracking branches 'github/pr/877' and 'github/pr/885'
Fernando López Guevara (2): fix(content): handle case where notes are not loaded feat(app_images): add module to manage static app image assets
3 parents 5010d36 + 36667bc + c6dbb0e commit 400050f

File tree

25 files changed

+382
-183
lines changed

25 files changed

+382
-183
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/notedeck/src/note/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub use action::{MediaAction, NoteAction, ZapAction, ZapTargetAmount};
55
pub use context::{BroadcastContext, ContextSelection, NoteContextSelection};
66

77
use crate::JobPool;
8+
use crate::UnknownIds;
89
use crate::{notecache::NoteCache, zaps::Zaps, Images};
910
use enostr::{NoteId, RelayPool};
1011
use nostrdb::{Ndb, Note, NoteKey, QueryResult, Transaction};
@@ -21,6 +22,7 @@ pub struct NoteContext<'d> {
2122
pub zaps: &'d mut Zaps,
2223
pub pool: &'d mut RelayPool,
2324
pub job_pool: &'d mut JobPool,
25+
pub unknown_ids: &'d mut UnknownIds,
2426
pub current_account_has_wallet: bool,
2527
}
2628

crates/notedeck/src/unknowns.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ impl UnknownIds {
201201
return;
202202
}
203203

204-
self.ids.entry(UnknownId::Pubkey(*pubkey)).or_default();
204+
let unknown_id = UnknownId::Pubkey(*pubkey);
205+
if self.ids.contains_key(&unknown_id) {
206+
return;
207+
}
208+
self.ids.entry(unknown_id).or_default();
205209
self.mark_updated();
206210
}
207211

@@ -211,9 +215,11 @@ impl UnknownIds {
211215
return;
212216
}
213217

214-
self.ids
215-
.entry(UnknownId::Id(NoteId::new(*note_id)))
216-
.or_default();
218+
let unknown_id = UnknownId::Id(NoteId::new(*note_id));
219+
if self.ids.contains_key(&unknown_id) {
220+
return;
221+
}
222+
self.ids.entry(unknown_id).or_default();
217223
self.mark_updated();
218224
}
219225
}

crates/notedeck_chrome/src/chrome.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use notedeck::{
1212
use notedeck_columns::{timeline::kind::ListKind, timeline::TimelineKind, Damus};
1313

1414
use notedeck_dave::{Dave, DaveAvatar};
15-
use notedeck_ui::{AnimationHelper, ProfilePic};
15+
use notedeck_ui::{app_images, AnimationHelper, ProfilePic};
1616

1717
static ICON_WIDTH: f32 = 40.0;
1818
pub static ICON_EXPANSION_MULTIPLE: f32 = 1.2;
@@ -438,8 +438,7 @@ fn milestone_name() -> impl Widget {
438438
fn expand_side_panel_button() -> impl Widget {
439439
|ui: &mut egui::Ui| -> egui::Response {
440440
let img_size = 40.0;
441-
let img_data = egui::include_image!("../../../assets/damus_rounded_80.png");
442-
let img = egui::Image::new(img_data)
441+
let img = app_images::damus_image()
443442
.max_width(img_size)
444443
.sense(egui::Sense::click());
445444

@@ -450,17 +449,16 @@ fn expand_side_panel_button() -> impl Widget {
450449
fn expanding_button(
451450
name: &'static str,
452451
img_size: f32,
453-
light_img: &egui::ImageSource,
454-
dark_img: &egui::ImageSource,
452+
light_img: egui::Image,
453+
dark_img: egui::Image,
455454
ui: &mut egui::Ui,
456455
) -> egui::Response {
457456
let max_size = ICON_WIDTH * ICON_EXPANSION_MULTIPLE; // max size of the widget
458-
let img_data = if ui.visuals().dark_mode {
457+
let img = if ui.visuals().dark_mode {
459458
dark_img
460459
} else {
461460
light_img
462461
};
463-
let img = egui::Image::new(img_data.clone()).max_width(img_size);
464462

465463
let helper = AnimationHelper::new(ui, name, egui::vec2(max_size, max_size));
466464

@@ -479,8 +477,8 @@ fn support_button(ui: &mut egui::Ui) -> egui::Response {
479477
expanding_button(
480478
"help-button",
481479
16.0,
482-
&egui::include_image!("../../../assets/icons/help_icon_inverted_4x.png"),
483-
&egui::include_image!("../../../assets/icons/help_icon_dark_4x.png"),
480+
app_images::help_light_image(),
481+
app_images::help_dark_image(),
484482
ui,
485483
)
486484
}
@@ -489,8 +487,8 @@ fn settings_button(ui: &mut egui::Ui) -> egui::Response {
489487
expanding_button(
490488
"settings-button",
491489
32.0,
492-
&egui::include_image!("../../../assets/icons/settings_light_4x.png"),
493-
&egui::include_image!("../../../assets/icons/settings_dark_4x.png"),
490+
app_images::settings_light_image(),
491+
app_images::settings_dark_image(),
494492
ui,
495493
)
496494
}
@@ -499,8 +497,8 @@ fn notifications_button(ui: &mut egui::Ui) -> egui::Response {
499497
expanding_button(
500498
"notifications-button",
501499
24.0,
502-
&egui::include_image!("../../../assets/icons/notifications_dark_4x.png"),
503-
&egui::include_image!("../../../assets/icons/notifications_dark_4x.png"),
500+
app_images::notifications_button_image(),
501+
app_images::notifications_button_image(),
504502
ui,
505503
)
506504
}
@@ -509,15 +507,20 @@ fn home_button(ui: &mut egui::Ui) -> egui::Response {
509507
expanding_button(
510508
"home-button",
511509
24.0,
512-
&egui::include_image!("../../../assets/icons/home-toolbar.png"),
513-
&egui::include_image!("../../../assets/icons/home-toolbar.png"),
510+
app_images::home_button_image(),
511+
app_images::home_button_image(),
514512
ui,
515513
)
516514
}
517515

518516
fn columns_button(ui: &mut egui::Ui) -> egui::Response {
519-
let btn = egui::include_image!("../../../assets/icons/columns_80.png");
520-
expanding_button("columns-button", 40.0, &btn, &btn, ui)
517+
expanding_button(
518+
"columns-button",
519+
40.0,
520+
app_images::columns_image(),
521+
app_images::columns_image(),
522+
ui,
523+
)
521524
}
522525

523526
fn dave_sidebar_rect(ui: &mut egui::Ui) -> Rect {
@@ -574,9 +577,8 @@ fn wallet_button() -> impl Widget {
574577
let img_size = 24.0;
575578

576579
let max_size = img_size * ICON_EXPANSION_MULTIPLE;
577-
let img_data = egui::include_image!("../../../assets/icons/wallet-icon.svg");
578580

579-
let mut img = egui::Image::new(img_data).max_width(img_size);
581+
let mut img = app_images::wallet_image().max_width(img_size);
580582

581583
if !ui.visuals().dark_mode {
582584
img = img.tint(egui::Color32::BLACK);

crates/notedeck_chrome/src/setup.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{fonts, theme};
33
use eframe::NativeOptions;
44
use egui::ThemePreference;
55
use notedeck::{AppSizeHandler, DataPath};
6+
use notedeck_ui::app_images;
67
use tracing::info;
78

89
pub fn setup_chrome(ctx: &egui::Context, args: &notedeck::Args, theme: ThemePreference) {
@@ -53,9 +54,7 @@ pub fn generate_native_options(paths: DataPath) -> NativeOptions {
5354
.with_fullsize_content_view(true)
5455
.with_titlebar_shown(false)
5556
.with_title_shown(false)
56-
.with_icon(std::sync::Arc::new(
57-
eframe::icon_data::from_png_bytes(app_icon()).expect("icon"),
58-
));
57+
.with_icon(std::sync::Arc::new(app_images::app_icon()));
5958

6059
if let Some(window_size) = AppSizeHandler::new(&paths).get_app_size() {
6160
builder.with_inner_size(window_size)
@@ -68,9 +67,8 @@ pub fn generate_native_options(paths: DataPath) -> NativeOptions {
6867
// for 3d widgets
6968
depth_buffer: 24,
7069
window_builder: Some(window_builder),
71-
viewport: egui::ViewportBuilder::default().with_icon(std::sync::Arc::new(
72-
eframe::icon_data::from_png_bytes(app_icon()).expect("icon"),
73-
)),
70+
viewport: egui::ViewportBuilder::default()
71+
.with_icon(std::sync::Arc::new(app_images::app_icon())),
7472
..Default::default()
7573
}
7674
}
@@ -89,17 +87,13 @@ fn generate_native_options_with_builder_modifiers(
8987
}
9088
}
9189

92-
pub fn app_icon() -> &'static [u8; 271986] {
93-
std::include_bytes!("../../../assets/damus-app-icon.png")
94-
}
95-
9690
pub fn generate_mobile_emulator_native_options() -> eframe::NativeOptions {
9791
generate_native_options_with_builder_modifiers(|builder| {
9892
builder
9993
.with_fullsize_content_view(true)
10094
.with_titlebar_shown(false)
10195
.with_title_shown(false)
10296
.with_inner_size([405.0, 915.0])
103-
.with_icon(eframe::icon_data::from_png_bytes(app_icon()).expect("icon"))
97+
.with_icon(app_images::app_icon())
10498
})
10599
}

crates/notedeck_columns/src/nav.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ fn render_nav_body(
420420
zaps: ctx.zaps,
421421
pool: ctx.pool,
422422
job_pool: ctx.job_pool,
423+
unknown_ids: ctx.unknown_ids,
423424
current_account_has_wallet: get_current_wallet(ctx.accounts, ctx.global_wallet).is_some(),
424425
};
425426
match top {
426427
Route::Timeline(kind) => render_timeline_route(
427-
ctx.unknown_ids,
428428
&mut app.timeline_cache,
429429
ctx.accounts,
430430
kind,
@@ -436,7 +436,6 @@ fn render_nav_body(
436436
&mut app.jobs,
437437
),
438438
Route::Thread(selection) => render_thread_route(
439-
ctx.unknown_ids,
440439
&mut app.threads,
441440
ctx.accounts,
442441
selection,

crates/notedeck_columns/src/timeline/route.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ use crate::{
66
};
77

88
use enostr::Pubkey;
9-
use notedeck::{Accounts, MuteFun, NoteContext, UnknownIds};
9+
use notedeck::{Accounts, MuteFun, NoteContext};
1010
use notedeck_ui::{jobs::JobsCache, NoteOptions};
1111

1212
#[allow(clippy::too_many_arguments)]
1313
pub fn render_timeline_route(
14-
unknown_ids: &mut UnknownIds,
1514
timeline_cache: &mut TimelineCache,
1615
accounts: &mut Accounts,
1716
kind: &TimelineKind,
@@ -50,7 +49,6 @@ pub fn render_timeline_route(
5049
pubkey,
5150
accounts,
5251
timeline_cache,
53-
unknown_ids,
5452
col,
5553
ui,
5654
&accounts.mutefun(),
@@ -79,7 +77,6 @@ pub fn render_timeline_route(
7977

8078
#[allow(clippy::too_many_arguments)]
8179
pub fn render_thread_route(
82-
unknown_ids: &mut UnknownIds,
8380
threads: &mut Threads,
8481
accounts: &mut Accounts,
8582
selection: &ThreadSelection,
@@ -95,7 +92,6 @@ pub fn render_thread_route(
9592

9693
ui::ThreadView::new(
9794
threads,
98-
unknown_ids,
9995
selection.selected_or_root(),
10096
note_options,
10197
&accounts.mutefun(),
@@ -113,7 +109,6 @@ pub fn render_profile_route(
113109
pubkey: &Pubkey,
114110
accounts: &Accounts,
115111
timeline_cache: &mut TimelineCache,
116-
unknown_ids: &mut UnknownIds,
117112
col: usize,
118113
ui: &mut egui::Ui,
119114
is_muted: &MuteFun,
@@ -127,7 +122,6 @@ pub fn render_profile_route(
127122
col,
128123
timeline_cache,
129124
note_options,
130-
unknown_ids,
131125
is_muted,
132126
note_context,
133127
jobs,

crates/notedeck_columns/src/ui/account_login_view.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use crate::login_manager::AcquireKeyState;
22
use crate::ui::{Preview, PreviewConfig};
33
use egui::{
4-
Align, Button, Color32, Frame, Image, InnerResponse, Margin, RichText, TextBuffer, Vec2,
4+
Align, Button, Color32, Frame, InnerResponse, Layout, Margin, RichText, TextBuffer, TextEdit,
5+
Vec2,
56
};
6-
use egui::{Layout, TextEdit};
77
use egui_winit::clipboard::Clipboard;
88
use enostr::Keypair;
99
use notedeck::{fonts::get_font_size, AppAction, NotedeckTextStyle};
10-
use notedeck_ui::context_menu::{input_context, PasteBehavior};
10+
use notedeck_ui::{
11+
app_images,
12+
context_menu::{input_context, PasteBehavior},
13+
};
1114

1215
pub struct AccountLoginView<'a> {
1316
manager: &'a mut AcquireKeyState,
@@ -138,15 +141,15 @@ fn login_textedit(manager: &mut AcquireKeyState) -> TextEdit {
138141

139142
fn eye_button(ui: &mut egui::Ui, is_visible: bool) -> egui::Response {
140143
let is_dark_mode = ui.visuals().dark_mode;
141-
let icon = Image::new(if is_visible && is_dark_mode {
142-
egui::include_image!("../../../../assets/icons/eye-dark.png")
144+
let icon = if is_visible && is_dark_mode {
145+
app_images::eye_dark_image()
143146
} else if is_visible {
144-
egui::include_image!("../../../../assets/icons/eye-light.png")
147+
app_images::eye_light_image()
145148
} else if is_dark_mode {
146-
egui::include_image!("../../../../assets/icons/eye-slash-dark.png")
149+
app_images::eye_slash_dark_image()
147150
} else {
148-
egui::include_image!("../../../../assets/icons/eye-slash-light.png")
149-
});
151+
app_images::eye_slash_light_image()
152+
};
150153
ui.add(Button::image(icon).frame(false))
151154
}
152155

crates/notedeck_columns/src/ui/accounts.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use egui::{
2-
Align, Button, Frame, Image, InnerResponse, Layout, RichText, ScrollArea, Ui, UiBuilder, Vec2,
2+
Align, Button, Frame, InnerResponse, Layout, RichText, ScrollArea, Ui, UiBuilder, Vec2,
33
};
44
use nostrdb::{Ndb, Transaction};
55
use notedeck::{Accounts, Images};
66
use notedeck_ui::colors::PINK;
77

8+
use notedeck_ui::app_images;
89
use notedeck_ui::profile::preview::SimpleProfilePreview;
910

1011
pub struct AccountsView<'a> {
@@ -175,10 +176,8 @@ fn scroll_area() -> ScrollArea {
175176
}
176177

177178
fn add_account_button() -> Button<'static> {
178-
let img_data = egui::include_image!("../../../../assets/icons/add_account_icon_4x.png");
179-
let img = Image::new(img_data).fit_to_exact_size(Vec2::new(48.0, 48.0));
180179
Button::image_and_text(
181-
img,
180+
app_images::add_account_image().fit_to_exact_size(Vec2::new(48.0, 48.0)),
182181
RichText::new(" Add account")
183182
.size(16.0)
184183
// TODO: this color should not be hard coded. Find some way to add it to the visuals

0 commit comments

Comments
 (0)