From 117968bd17294f8a3c65604541cca0267acdb568 Mon Sep 17 00:00:00 2001 From: kieran Date: Thu, 17 Oct 2024 22:05:53 +0100 Subject: [PATCH] fix: various bugs for android --- .gitignore | 3 +-- android.sh | 26 +++++++++++++------------- src/services/image_cache.rs | 4 ++++ src/services/ndb_wrapper.rs | 10 +++++++++- src/services/query.rs | 14 ++++++++++++-- src/widgets/avatar.rs | 14 +++++++------- src/widgets/chat_message.rs | 5 +---- src/widgets/header.rs | 4 ++-- src/widgets/stream_player.rs | 2 +- src/widgets/stream_tile.rs | 6 +++--- 10 files changed, 53 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 92b2d8d..8e9985b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ /target -/lock.mdb -/data.mdb +/ndb /.idea /cache /ffmpeg-kit \ No newline at end of file diff --git a/android.sh b/android.sh index 43483eb..73f6e0e 100755 --- a/android.sh +++ b/android.sh @@ -2,27 +2,27 @@ git clone https://github.com/v0l/ffmpeg-kit.git export ANDROID_SDK_ROOT=$ANDROID_HOME -#cd ffmpeg-kit && ./android.sh \ -# --disable-x86 \ -# --disable-x86-64 \ -# --disable-arm-v7a \ -# --disable-arm-v7a-neon \ -# --no-ffmpeg-kit-protocols \ -# --no-archive - -if [[ $? -ne 0 ]]; then - exit 1; -fi +cd ffmpeg-kit && ./android.sh \ + --disable-x86 \ + --disable-x86-64 \ + --disable-arm-v7a \ + --disable-arm-v7a-neon \ + --enable-openssl \ + --api-level=28 \ + --no-ffmpeg-kit-protocols \ + --no-archive NDK_VER="28.0.12433566" ARCH="arm64" PLATFORM="android" TRIPLET="aarch64-linux-android" -export PKG_CONFIG_SYSROOT_DIR="/" export FFMPEG_DIR="$(pwd)/ffmpeg-kit/prebuilt/$PLATFORM-$ARCH/ffmpeg" +export PKG_CONFIG_SYSROOT_DIR="$(pwd)/ffmpeg-kit/prebuilt/$PLATFORM-$ARCH/pkgconfig" # DIRTY HACK !! cp "$ANDROID_HOME/ndk/$NDK_VER/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/$TRIPLET/35/libcamera2ndk.so" \ ./target/x/debug/android/$ARCH/cargo/$TRIPLET/debug/deps +cp "$ANDROID_HOME/ndk/$NDK_VER/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/$TRIPLET/35/libcamera2ndk.so" \ + ./target/x/release/android/$ARCH/cargo/$TRIPLET/release/deps -x build --arch $ARCH --platform $PLATFORM --verbose +x build --arch $ARCH --platform $PLATFORM --verbose --release diff --git a/src/services/image_cache.rs b/src/services/image_cache.rs index 983df15..1719bf9 100644 --- a/src/services/image_cache.rs +++ b/src/services/image_cache.rs @@ -58,6 +58,10 @@ impl ImageCache { if let Err(e) = tokio::fs::write(path, data.bytes().await.unwrap()).await { error!("Failed to write file: {}", e); } + // forget cached url + for t in ctx.loaders().texture.lock().iter() { + t.forget(&u); + } ctx.request_repaint(); } } diff --git a/src/services/ndb_wrapper.rs b/src/services/ndb_wrapper.rs index 42cb95b..1993c11 100644 --- a/src/services/ndb_wrapper.rs +++ b/src/services/ndb_wrapper.rs @@ -2,7 +2,7 @@ use crate::services::query::QueryManager; use egui::CursorIcon::Default; use log::{info, warn}; use nostr_sdk::secp256k1::Context; -use nostr_sdk::{Client, JsonUtil, Kind, RelayPoolNotification}; +use nostr_sdk::{nostr, Client, JsonUtil, Kind, PublicKey, RelayPoolNotification}; use nostrdb::{ Error, Filter, Ndb, NdbProfile, Note, NoteKey, ProfileRecord, QueryResult, Subscription, Transaction, @@ -142,6 +142,14 @@ impl NDBWrapper { .get_profile_by_pubkey(tx, pubkey) .map_or(None, |p| p.record().profile()); + // TODO: fix this shit + if p.is_none() { + self.query_manager.queue_query("profile", &[ + nostr::Filter::new() + .kinds([Kind::Metadata]) + .authors([PublicKey::from_slice(pubkey).unwrap()]) + ]) + } let sub = None; (p, sub) } diff --git a/src/services/query.rs b/src/services/query.rs index b8b3d59..2cb9137 100644 --- a/src/services/query.rs +++ b/src/services/query.rs @@ -3,7 +3,7 @@ use chrono::Utc; use log::{error, info}; use nostr_sdk::prelude::StreamExt; use nostr_sdk::Kind::Metadata; -use nostr_sdk::{Client, Filter, SubscriptionId}; +use nostr_sdk::{Client, Filter, SubscribeAutoCloseOptions, SubscriptionId}; use std::collections::{HashMap, HashSet, VecDeque}; use std::sync::Arc; use std::time::Duration; @@ -75,6 +75,16 @@ impl Query { .authors(next.iter().flat_map(|f| f.authors.as_ref().unwrap().clone())) ] } + + // remove filters already sent + next = next + .into_iter() + .filter(|f| !self.traces.iter().all(|y| y.filters.iter().any(|z| z.eq(f)))) + .collect(); + + if next.len() == 0 { + return None; + } Some(QueryTrace { id, filters: next, @@ -168,7 +178,7 @@ where #[async_trait::async_trait] impl QueryClient for Client { async fn subscribe(&self, id: &str, filters: &[QueryFilter]) -> Result<(), Error> { - self.subscribe_with_id(SubscriptionId::new(id), filters.into(), None) + self.subscribe_with_id(SubscriptionId::new(id), filters.into(), Some(SubscribeAutoCloseOptions::default())) .await?; Ok(()) } diff --git a/src/widgets/avatar.rs b/src/widgets/avatar.rs index 8a84842..f651591 100644 --- a/src/widgets/avatar.rs +++ b/src/widgets/avatar.rs @@ -1,6 +1,7 @@ -use crate::route::RouteServices; +use crate::services::image_cache::ImageCache; use crate::services::ndb_wrapper::SubWrapper; use egui::{Color32, Image, Pos2, Response, Rounding, Sense, Ui, Vec2, Widget}; +use nostrdb::NdbProfile; pub struct Avatar<'a> { image: Option>, @@ -25,13 +26,12 @@ impl<'a> Avatar<'a> { } } - pub fn pubkey(pk: &[u8; 32], svc: &RouteServices<'a>) -> Self { - let (img, sub) = svc.ndb.fetch_profile(svc.tx, pk); + pub fn from_profile(p: Option>, svc: &'a ImageCache) -> Self { + let img = p + .map_or(None, |f| f.picture().map(|f| svc.load(f))); Self { - image: img - .map_or(None, |p| p.picture()) - .map(|p| svc.img_cache.load(p)), - sub, + image: img, + sub: None, size: None, } } diff --git a/src/widgets/chat_message.rs b/src/widgets/chat_message.rs index abd41f8..e5149c2 100644 --- a/src/widgets/chat_message.rs +++ b/src/widgets/chat_message.rs @@ -30,9 +30,6 @@ impl<'a> Widget for ChatMessage<'a> { let name = self .profile.0 .map_or("Nostrich", |f| f.name().map_or("Nostrich", |f| f)); - let img = self - .profile.0 - .map_or(None, |f| f.picture().map(|f| self.services.img_cache.load(f))); let name_color = if is_host { PRIMARY @@ -49,7 +46,7 @@ impl<'a> Widget for ChatMessage<'a> { format.color = Color32::WHITE; job.append(self.ev.content(), 5.0, format.clone()); - ui.add(Avatar::new_optional(img).size(24.)); + ui.add(Avatar::from_profile(self.profile.0, self.services.img_cache).size(24.)); ui.add(Label::new(job) .wrap_mode(TextWrapMode::Wrap) ); diff --git a/src/widgets/header.rs b/src/widgets/header.rs index eafb506..1a86421 100644 --- a/src/widgets/header.rs +++ b/src/widgets/header.rs @@ -25,7 +25,7 @@ impl NostrWidget for Header { |ui| { ui.style_mut().spacing.item_spacing.x = 16.; if Image::from_bytes("logo.svg", logo_bytes) - .max_height(22.62) + .max_height(24.) .sense(Sense::click()) .ui(ui) .clicked() @@ -33,7 +33,7 @@ impl NostrWidget for Header { services.navigate(Routes::HomePage); } if let Some(pk) = services.login { - ui.add(Avatar::pubkey(pk, services)); + //ui.add(Avatar::pubkey(pk, services)); } }, ) diff --git a/src/widgets/stream_player.rs b/src/widgets/stream_player.rs index 10d48ef..2568058 100644 --- a/src/widgets/stream_player.rs +++ b/src/widgets/stream_player.rs @@ -12,6 +12,7 @@ impl StreamPlayer { let mut audio = AudioDevice::new().unwrap(); Self { player: Player::new(ctx, url).map_or(None, |mut f| { + f.add_audio(&mut audio).expect("Failed to add audio"); f.start(); Some(f) }), @@ -27,7 +28,6 @@ impl Widget for &mut StreamPlayer { let size = Vec2::new(w, h); if let Some(mut p) = self.player.as_mut() { - p.add_audio(&mut self.audio).expect("Failed to add audio to stream player"); p.ui(ui, size) } else { VideoPlaceholder.ui(ui) diff --git a/src/widgets/stream_tile.rs b/src/widgets/stream_tile.rs index 3ec2cfb..b682a44 100644 --- a/src/widgets/stream_tile.rs +++ b/src/widgets/stream_tile.rs @@ -1,12 +1,12 @@ use crate::link::NostrLink; use crate::note_util::NoteUtil; use crate::route::{RouteServices, Routes}; +use crate::stream_info::StreamInfo; use crate::widgets::avatar::Avatar; use crate::widgets::VideoPlaceholder; use eframe::epaint::Vec2; use egui::{Color32, Image, Label, Response, RichText, Rounding, Sense, TextWrapMode, Ui, Widget}; -use nostrdb::{NdbStrVariant, Note}; -use crate::stream_info::StreamInfo; +use nostrdb::{NdbProfile, Note}; pub struct StreamEvent<'a> { event: &'a Note<'a>, @@ -56,7 +56,7 @@ impl Widget for StreamEvent<'_> { }); } ui.horizontal(|ui| { - ui.add(Avatar::pubkey(&host, self.services).size(40.)); + ui.add(Avatar::from_profile(None, self.services.img_cache).size(40.)); let title = RichText::new(self.event.title().unwrap_or("Untitled")) .size(16.) .color(Color32::WHITE);