fix: various bugs for android

This commit is contained in:
kieran 2024-10-17 22:05:53 +01:00
parent 91f0baf75c
commit 117968bd17
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
10 changed files with 53 additions and 35 deletions

3
.gitignore vendored
View File

@ -1,6 +1,5 @@
/target
/lock.mdb
/data.mdb
/ndb
/.idea
/cache
/ffmpeg-kit

View File

@ -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

View File

@ -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();
}
}

View File

@ -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)
}

View File

@ -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(())
}

View File

@ -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<Image<'a>>,
@ -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<NdbProfile<'a>>, 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,
}
}

View File

@ -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)
);

View File

@ -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));
}
},
)

View File

@ -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)

View File

@ -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);