mirror of
https://github.com/danbulant/despot
synced 2026-06-19 22:31:16 +00:00
add cache, improve code
This commit is contained in:
parent
3f0dde272c
commit
6114b8a25a
5 changed files with 33 additions and 15 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
|||
target
|
||||
result
|
||||
http-cacache
|
||||
refresh_token.txt
|
||||
/cache
|
||||
refresh_token.txt
|
||||
|
|
|
|||
|
|
@ -13,13 +13,11 @@ use cushy::{
|
|||
|
||||
static FONT: OnceLock<LoadedFont> = OnceLock::new();
|
||||
|
||||
pub fn load_fonts() -> FontCollection {
|
||||
let fonts = FontCollection::default();
|
||||
let font = fonts.push_unloadable(
|
||||
pub fn load_fonts(col: &FontCollection) {
|
||||
let font = col.push_unloadable(
|
||||
include_bytes!("../fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf").into(),
|
||||
);
|
||||
FONT.set(font).map_err(|_| ()).unwrap();
|
||||
fonts
|
||||
}
|
||||
|
||||
fn font_component() -> DynamicComponent {
|
||||
|
|
|
|||
32
src/main.rs
32
src/main.rs
|
|
@ -13,7 +13,7 @@ use librespot_connect::{
|
|||
spirc::{Spirc, SpircLoadCommand},
|
||||
state::ConnectStateConfig,
|
||||
};
|
||||
use librespot_core::{authentication::Credentials, Session, SessionConfig};
|
||||
use librespot_core::{authentication::Credentials, cache::Cache, Session, SessionConfig};
|
||||
use librespot_playback::{
|
||||
audio_backend,
|
||||
config::{AudioFormat, PlayerConfig},
|
||||
|
|
@ -40,21 +40,41 @@ mod widgets;
|
|||
fn main() -> cushy::Result {
|
||||
let args = Args::parse();
|
||||
let app = PendingApp::new(TokioRuntime::default());
|
||||
// doesn't load fonts correctly yet, cushy bug
|
||||
// load_fonts(app.cushy().fonts());
|
||||
|
||||
let token = get_token().unwrap();
|
||||
|
||||
let cache = match Cache::new(None, Some("./cache/volume"), Some("./cache/audio"), None) {
|
||||
Ok(cache) => Some(cache),
|
||||
Err(e) => {
|
||||
eprintln!("Failed to create cache: {}", e);
|
||||
None
|
||||
}
|
||||
};
|
||||
let session_config = SessionConfig::default();
|
||||
let player_config = PlayerConfig::default();
|
||||
let audio_format = AudioFormat::default();
|
||||
let credentials = Credentials::with_access_token(&token.access_token);
|
||||
let connect_config = ConnectStateConfig::default();
|
||||
let default_connect_config = ConnectStateConfig::default();
|
||||
let connect_config = ConnectStateConfig {
|
||||
name: "Despot".to_string(),
|
||||
device_type: librespot_core::config::DeviceType::Computer,
|
||||
volume_steps: 256,
|
||||
initial_volume: cache
|
||||
.as_ref()
|
||||
.and_then(Cache::volume)
|
||||
.map(Into::into)
|
||||
.unwrap_or(default_connect_config.initial_volume),
|
||||
..Default::default()
|
||||
};
|
||||
let backend = audio_backend::find(None).unwrap();
|
||||
|
||||
let session;
|
||||
|
||||
{
|
||||
let guard = app.cushy().enter_runtime();
|
||||
session = Session::new(session_config, None);
|
||||
session = Session::new(session_config, cache);
|
||||
|
||||
dbg!(session.user_data());
|
||||
|
||||
|
|
@ -88,13 +108,12 @@ fn main() -> cushy::Result {
|
|||
tokio::join!(spirc_task, dynplayer2.run(), async move {
|
||||
let user = context.current_user().await.unwrap();
|
||||
dbg!(&user);
|
||||
// let userid = user.id;
|
||||
|
||||
let playlists = context.current_user_playlists(None, None).await.unwrap();
|
||||
|
||||
let selected_page = Dynamic::new(ActivePage::default());
|
||||
|
||||
let mut win = playlists_widget(playlists.items, selected_page)
|
||||
let win = playlists_widget(playlists.items, selected_page)
|
||||
.and(LikedSongsPage::new(context.clone()).into_widget())
|
||||
.into_columns()
|
||||
.expand()
|
||||
|
|
@ -102,8 +121,7 @@ fn main() -> cushy::Result {
|
|||
.into_rows()
|
||||
.expand()
|
||||
.into_window();
|
||||
let fonts = load_fonts(/*app.cushy()*/);
|
||||
win.fonts = fonts;
|
||||
load_fonts(&win.fonts);
|
||||
win.open(&mut app).unwrap();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -33,7 +33,9 @@ static CLIENT: LazyLock<ClientWithMiddleware> = LazyLock::new(|| {
|
|||
ClientBuilder::new(Client::new())
|
||||
.with(Cache(HttpCache {
|
||||
mode: CacheMode::Default,
|
||||
manager: CACacheManager::default(),
|
||||
manager: CACacheManager {
|
||||
path: "./cache/http-cacache".into(),
|
||||
},
|
||||
options: HttpCacheOptions::default(),
|
||||
}))
|
||||
.build()
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ impl LikedSongsPage {
|
|||
.to_string()
|
||||
.align_right()
|
||||
.size(Size {
|
||||
width: Dimension::Lp(Lp::points(20)).into(),
|
||||
width: Dimension::Lp(Lp::points(30)).into(),
|
||||
height: DimensionRange::default(),
|
||||
})
|
||||
.and({
|
||||
|
|
|
|||
Loading…
Reference in a new issue