Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
⚡ Bulk Piped feed loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmiddiii committed Oct 2, 2022
1 parent b5c3d5a commit dd7c1b8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
*~*
src/config.rs
data/resources/ui/about.ui
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ gettext-rs = "0.7.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

tf_core = "0.1.2"
tf_join = "0.1.4"
tf_core = "0.1.3"
tf_join = "0.1.5"
tf_filter = "0.1.2"
tf_observer = "0.1.2"
tf_playlist = "0.1.3"
tf_yt = { package = "tf_platform_youtube", version = "0.1.4" }
tf_pt = { package = "tf_platform_peertube", version = "0.1.1" }
tf_lbry = { package = "tf_platform_lbry", version = "0.1.1" }
tf_yt = { package = "tf_platform_youtube", version = "0.1.5" }
tf_pt = { package = "tf_platform_peertube", version = "0.1.2" }
tf_lbry = { package = "tf_platform_lbry", version = "0.1.2" }
16 changes: 0 additions & 16 deletions data/resources/ui/about.ui

This file was deleted.

1 change: 1 addition & 0 deletions src/csv_file_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl TryFrom<SubscriptionEvent> for CsvEvent<AnySubscription> {
match e {
SubscriptionEvent::Add(i) => Ok(CsvEvent::Add(i)),
SubscriptionEvent::Remove(i) => Ok(CsvEvent::Remove(i)),
SubscriptionEvent::Update(i) => Ok(CsvEvent::Add(i)),
}
}
}
Expand Down
45 changes: 8 additions & 37 deletions src/gui/subscription/subscription_item_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use std::cell::RefCell;

use gdk::glib::Object;
use gdk::subclass::prelude::ObjectSubclassIsExt;
use gdk_pixbuf::prelude::ObjectExt;
use tf_core::Subscription;
use tf_join::AnySubscription;

macro_rules! str_prop {
Expand Down Expand Up @@ -73,13 +75,16 @@ impl SubscriptionObject {
])
.expect("Failed to create `SubscriptionObject`.");
s.imp().subscription.swap(&RefCell::new(Some(subscription)));
s.imp().setup_name(&s);
s
}

pub fn subscription(&self) -> Option<AnySubscription> {
self.imp().subscription.borrow().clone()
}

pub fn update_name(&self, sub: &AnySubscription) {
self.set_property("name", sub.name());
}
}

mod imp {
Expand All @@ -88,10 +93,8 @@ mod imp {
use tf_join::AnySubscription;

use gdk::{
glib::{
clone, MainContext, ParamFlags, ParamSpec, ParamSpecString, Value, PRIORITY_DEFAULT,
},
prelude::{Continue, ObjectExt, ToValue},
glib::{ParamFlags, ParamSpec, ParamSpecString, Value},
prelude::ToValue,
subclass::prelude::{ObjectImpl, ObjectSubclass},
};
use once_cell::sync::Lazy;
Expand All @@ -104,38 +107,6 @@ mod imp {
pub(super) subscription: RefCell<Option<AnySubscription>>,
}

impl SubscriptionObject {
pub(super) fn setup_name(&self, obj: &super::SubscriptionObject) {
let sub_clone = self
.subscription
.borrow()
.clone()
.expect("Subscription for the item should be set up");

let (sender, receiver) = MainContext::channel(PRIORITY_DEFAULT);

tokio::spawn(async move {
let client = reqwest::Client::new();
let name = match &sub_clone {
AnySubscription::Youtube(sub) => sub.update_name(&client).await,
AnySubscription::Peertube(sub) => sub.update_name(&client).await,
AnySubscription::Lbry(sub) => sub.update_name(&client).await,
};
if name.is_some() {
let _ = sender.send(name);
}
});

receiver.attach(
None,
clone!(@strong obj => move |name| {
obj.set_property("name", name.to_value());
Continue(true)
}),
);
}
}

#[glib::object_subclass]
impl ObjectSubclass for SubscriptionObject {
const NAME: &'static str = "TFSubscriptionObject";
Expand Down
22 changes: 19 additions & 3 deletions src/gui/subscription/subscription_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use gdk::{
subclass::prelude::ObjectSubclassIsExt,
};
use gtk::{traits::SorterExt, SorterChange};
use tf_join::AnySubscriptionList;
use tf_join::{AnySubscription, AnySubscriptionList};

use super::subscription_item_object::SubscriptionObject;

Expand Down Expand Up @@ -70,6 +70,21 @@ impl SubscriptionList {
}
}

pub fn update(&self, sub: AnySubscription) {
let imp = self.imp();
let model = imp.model.borrow();

model
.snapshot()
.into_iter()
.map(|i| {
i.downcast::<SubscriptionObject>()
.expect("Items should be of type SubscriptionObject")
})
.filter(|i| i.subscription().as_ref() == Some(&sub))
.for_each(|i| i.update_name(&sub))
}

pub fn set_subscription_list(&self, subscription_list: AnySubscriptionList) {
self.imp()
.any_subscription_list
Expand Down Expand Up @@ -160,6 +175,9 @@ pub mod imp {
let subscription = SubscriptionObject::new(s);
obj.remove(subscription);
}
SubscriptionEvent::Update(s) => {
obj.update(s);
}
}
Continue(true)
}),
Expand All @@ -186,7 +204,6 @@ pub mod imp {
.unwrap_or_else(|| "".to_string())
.to_lowercase();

log::trace!("Re-sorting");
name_1.cmp(&name_2).into()
});

Expand Down Expand Up @@ -223,7 +240,6 @@ pub mod imp {
let item: Option<SubscriptionObject> = s.property("subscription");
if let Some(item) = item {
item.connect_notify_local(Some("name"), clone!(@strong sorter => move |_, _| {
log::trace!("Got a name change");
sorter.changed(SorterChange::Different);
}));
}
Expand Down

0 comments on commit dd7c1b8

Please sign in to comment.