Skip to content

Commit

Permalink
add logo
Browse files Browse the repository at this point in the history
fix icons
  • Loading branch information
tsukinaha committed Mar 27, 2024
1 parent 540cad8 commit 984389a
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 23 deletions.
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

9 changes: 9 additions & 0 deletions resources/ui/item.ui
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
</child>
</object>
</child>
<child type="overlay">
<object class="GtkBox" id="logobox">
<property name="margin-start">30</property>
<property name="margin-top">15</property>
<property name="height-request">150</property>
<property name="valign">start</property>
<property name="halign">start</property>
</object>
</child>
</object>
</child>
<child>
Expand Down
9 changes: 9 additions & 0 deletions resources/ui/movie.ui
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
</child>
</object>
</child>
<child type="overlay">
<object class="GtkBox" id="logobox">
<property name="margin-start">30</property>
<property name="margin-top">15</property>
<property name="height-request">150</property>
<property name="valign">start</property>
<property name="halign">start</property>
</object>
</child>
</object>
</child>
<child>
Expand Down
4 changes: 2 additions & 2 deletions resources/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<child type="suffix">
<object class="GtkButton">
<property name="valign">center</property>
<property name="icon-name">object-rotate-left-symbolic</property>
<property name="icon-name">object-rotate-left</property>
<property name="action-name">win.home</property>
<style>
<class name="flat" />
Expand All @@ -146,7 +146,7 @@
<child type="suffix">
<object class="GtkButton">
<property name="valign">center</property>
<property name="icon-name">object-rotate-left-symbolic</property>
<property name="icon-name">object-rotate-left</property>
<property name="action-name">win.search</property>
<style>
<class name="flat" />
Expand Down
49 changes: 35 additions & 14 deletions src/ui/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,40 +248,61 @@ pub fn setimage(id: String,mutex: Arc<Mutex<()>>) -> Revealer {
revealer
}

pub fn setlogoimage(id: String) -> Picture {
pub fn setlogoimage(id: String,mutex: Arc<Mutex<()>>) -> Revealer {
let (sender, receiver) = async_channel::bounded::<String>(1);

let image = gtk::Picture::new();
image.set_halign(gtk::Align::Center);
image.set_halign(gtk::Align::Start);
image.set_valign(gtk::Align::Start);
let revealer = gtk::Revealer::builder()
.transition_type(gtk::RevealerTransitionType::Crossfade)
.child(&image)
.reveal_child(false)
.transition_duration(700)
.build();

let path = format!(
"{}/.local/share/tsukimi/{}.png",
"{}/.local/share/tsukimi/l{}.png",
dirs::home_dir().expect("msg").display(),
id
);
let pathbuf = PathBuf::from(&path);
let idfuture = id.clone();
if pathbuf.exists() {
image.set_file(Some(&gtk::gio::File::for_path(&path)));
if image.file().is_none() {
image.set_file(Some(&gtk::gio::File::for_path(&path)));
revealer.set_reveal_child(true);
}
} else {
crate::ui::network::runtime().spawn(async move {
let id = crate::ui::network::get_image(id.clone())
.await
.expect("msg");
sender
.send(id.clone())
.await
.expect("The channel needs to be open.");
let _lock = mutex.lock().await;
let mut retries = 0;
while retries < 3 {
match crate::ui::network::get_logoimage(id.clone()).await {
Ok(id) => {
sender
.send(id.clone())
.await
.expect("The channel needs to be open.");
break;
}
Err(e) => {
eprintln!("Failed to get image: {}, retrying...", e);
retries += 1;
}
}
}
});
}

glib::spawn_future_local(clone!(@weak image => async move {
glib::spawn_future_local(clone!(@weak image,@weak revealer => async move {
while let Ok(_) = receiver.recv().await {
let path = format!("{}/.local/share/tsukimi/{}.png",dirs::home_dir().expect("msg").display(), idfuture);
let path = format!("{}/.local/share/tsukimi/l{}.png",dirs::home_dir().expect("msg").display(), idfuture);
let file = gtk::gio::File::for_path(&path);
image.set_file(Some(&file));
revealer.set_reveal_child(true);
}
}));

image
revealer
}
39 changes: 39 additions & 0 deletions src/ui/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,42 @@ pub async fn get_backdropimage(id: String) -> Result<String, Error> {
}
}
}

pub async fn get_logoimage(id: String) -> Result<String, Error> {
let server_info = get_server_info();

let result = reqwest::get(&format!(
"{}:{}/emby/Items/{}/Images/Logo",
server_info.domain, server_info.port, id
))
.await;

match result {
Ok(response) => {
let bytes_result = response.bytes().await;
match bytes_result {
Ok(bytes) => {
let path_str = format!("{}/.local/share/tsukimi/", home_dir().expect("msg").display());
let pathbuf = PathBuf::from(path_str);
if pathbuf.exists() {
fs::write(pathbuf.join(format!("l{}.png",id)), &bytes).unwrap();
} else {
fs::create_dir_all(format!("{}/.local/share/tsukimi/", home_dir().expect("msg").display()))
.unwrap();

fs::write(pathbuf.join(format!("l{}.png",id)),&bytes).unwrap();
}
return Ok(id);
}
Err(e) => {
eprintln!("加载错误");
return Err(e.into());
}
}
}
Err(e) => {
eprintln!("加载错误");
return Err(e.into());
}
}
}
6 changes: 5 additions & 1 deletion src/ui/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ overlay > box {
background: linear-gradient(to bottom, rgba(0,0,0,0), rgba(0,0,0,0.8));
border-radius:10px;
}


.logo {
background: rgba(0,0,0,0);
}

overlay box > dropdown > button{
background:rgba(25, 28, 30, 0.4);
}
Expand Down
13 changes: 13 additions & 0 deletions src/ui/widgets/item.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use glib::Object;
use gtk::{gio, glib};
use gtk::prelude::*;
mod imp {
use adw::subclass::prelude::*;
use glib::subclass::InitializingObject;
Expand All @@ -25,6 +26,8 @@ mod imp {
pub osdbox: TemplateChild<gtk::Box>,
#[template_child]
pub itemrevealer: TemplateChild<gtk::Revealer>,
#[template_child]
pub logobox: TemplateChild<gtk::Box>,
pub selection: gtk::SingleSelection,
}

Expand Down Expand Up @@ -144,6 +147,8 @@ mod imp {
});
self.itemlist.set_factory(Some(&factory));
self.itemlist.set_model(Some(&self.selection));
let logobox = self.logobox.get();
obj.logoset(logobox);
let osdbox = self.osdbox.get();
let dropdownspinner = self.dropdownspinner.get();
self.itemlist.connect_activate(move |listview, position| {
Expand Down Expand Up @@ -205,4 +210,12 @@ impl ItemPage {
pub fn new(id: String) -> Self {
Object::builder().property("id", id).build()
}

pub fn logoset(&self, osd: gtk::Box) {
let id = self.id();
let mutex = std::sync::Arc::new(tokio::sync::Mutex::new(()));
let logo = crate::ui::image::setlogoimage(id.clone(), mutex.clone());
osd.append(&logo);
osd.add_css_class("logo");
}
}
13 changes: 13 additions & 0 deletions src/ui/widgets/movie.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use glib::Object;
use gtk::{gio, glib};
use gtk::prelude::*;
mod imp {
use crate::ui::network::{self, runtime, SearchResult};
use adw::subclass::prelude::*;
Expand All @@ -25,6 +26,8 @@ mod imp {
pub itemlist: TemplateChild<gtk::ListView>,
#[template_child]
pub osdbox: TemplateChild<gtk::Box>,
#[template_child]
pub logobox: TemplateChild<gtk::Box>,
pub selection: gtk::SingleSelection,
}

Expand Down Expand Up @@ -90,6 +93,8 @@ mod imp {
backdrop.set_file(Some(&file));
}
});
let logobox = self.logobox.get();
obj.logoset(logobox);
let dropdownspinner = self.dropdownspinner.get();
let osdbox = self.osdbox.get();
dropdownspinner.set_visible(true);
Expand Down Expand Up @@ -138,4 +143,12 @@ impl MoviePage {
pub fn new(id: String,name: String) -> Self {
Object::builder().property("id", id).property("moviename", name).build()
}

pub fn logoset(&self, osd: gtk::Box) {
let id = self.id();
let mutex = std::sync::Arc::new(tokio::sync::Mutex::new(()));
let logo = crate::ui::image::setlogoimage(id.clone(), mutex.clone());
osd.append(&logo);
osd.add_css_class("logo");
}
}

0 comments on commit 984389a

Please sign in to comment.