Add init function
This commit is contained in:
parent
5a42ddfbdb
commit
d1bd0adf4f
|
|
@ -2,8 +2,8 @@ mod rpc;
|
||||||
|
|
||||||
use crabidy_core::proto::crabidy::{
|
use crabidy_core::proto::crabidy::{
|
||||||
crabidy_service_client::CrabidyServiceClient,
|
crabidy_service_client::CrabidyServiceClient,
|
||||||
get_update_stream_response::Update as StreamUpdate, GetLibraryNodeRequest, LibraryNode,
|
get_update_stream_response::Update as StreamUpdate, GetLibraryNodeRequest,
|
||||||
PlayState, Queue, QueueTrack, Track, TrackPosition,
|
InitResponse as InitialData, LibraryNode, PlayState, Queue, QueueTrack, Track, TrackPosition,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
|
|
@ -385,6 +385,7 @@ impl App {
|
||||||
|
|
||||||
// FIXME: Rename this
|
// FIXME: Rename this
|
||||||
enum MessageToUi {
|
enum MessageToUi {
|
||||||
|
Init(InitialData),
|
||||||
ReplaceLibraryNode(LibraryNode),
|
ReplaceLibraryNode(LibraryNode),
|
||||||
Update(StreamUpdate),
|
Update(StreamUpdate),
|
||||||
}
|
}
|
||||||
|
|
@ -449,6 +450,9 @@ async fn orchestrate<'a>(
|
||||||
tx.send(MessageToUi::ReplaceLibraryNode(root_node.clone()));
|
tx.send(MessageToUi::ReplaceLibraryNode(root_node.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let init_data = rpc_client.init().await?;
|
||||||
|
tx.send_async(MessageToUi::Init(init_data)).await?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
poll(&mut rpc_client, &rx, &tx).await.ok();
|
poll(&mut rpc_client, &rx, &tx).await.ok();
|
||||||
}
|
}
|
||||||
|
|
@ -489,6 +493,18 @@ fn run_ui(tx: Sender<MessageFromUi>, rx: Receiver<MessageToUi>) {
|
||||||
MessageToUi::ReplaceLibraryNode(node) => {
|
MessageToUi::ReplaceLibraryNode(node) => {
|
||||||
app.library.update(node);
|
app.library.update(node);
|
||||||
}
|
}
|
||||||
|
MessageToUi::Init(init_data) => {
|
||||||
|
if let Some(queue) = init_data.queue {
|
||||||
|
app.queue.update(queue);
|
||||||
|
}
|
||||||
|
if let Some(track) = init_data.queue_track {
|
||||||
|
app.now_playing.update_track(track.track);
|
||||||
|
app.queue.update_position(track.queue_position as usize);
|
||||||
|
}
|
||||||
|
if let Some(ps) = PlayState::from_i32(init_data.play_state) {
|
||||||
|
app.now_playing.update_play_state(ps);
|
||||||
|
}
|
||||||
|
}
|
||||||
MessageToUi::Update(update) => match update {
|
MessageToUi::Update(update) => match update {
|
||||||
StreamUpdate::Queue(queue) => {
|
StreamUpdate::Queue(queue) => {
|
||||||
app.queue.update(queue);
|
app.queue.update(queue);
|
||||||
|
|
@ -697,6 +713,10 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
||||||
PlayState::Playing => "♫",
|
PlayState::Playing => "♫",
|
||||||
_ => "",
|
_ => "",
|
||||||
};
|
};
|
||||||
|
let album_text = match &track.album {
|
||||||
|
Some(album) => album.title.to_string(),
|
||||||
|
None => "No album".to_string(),
|
||||||
|
};
|
||||||
vec![
|
vec![
|
||||||
Spans::from(Span::raw("")),
|
Spans::from(Span::raw("")),
|
||||||
Spans::from(Span::raw(play_text)),
|
Spans::from(Span::raw(play_text)),
|
||||||
|
|
@ -711,7 +731,7 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
||||||
Style::default().add_modifier(Modifier::BOLD),
|
Style::default().add_modifier(Modifier::BOLD),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
Spans::from(Span::raw("Album missing")),
|
Spans::from(Span::raw(album_text)),
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
vec![
|
vec![
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use crabidy_core::proto::crabidy::{
|
||||||
crabidy_service_client::CrabidyServiceClient, get_update_stream_response::Update,
|
crabidy_service_client::CrabidyServiceClient, get_update_stream_response::Update,
|
||||||
GetLibraryNodeRequest, GetLibraryNodeResponse, GetUpdateStreamRequest, GetUpdateStreamResponse,
|
GetLibraryNodeRequest, GetLibraryNodeResponse, GetUpdateStreamRequest, GetUpdateStreamResponse,
|
||||||
LibraryNode, ReplaceRequest, SetCurrentRequest, SetCurrentResponse, TogglePlayRequest,
|
LibraryNode, ReplaceRequest, SetCurrentRequest, SetCurrentResponse, TogglePlayRequest,
|
||||||
TogglePlayResponse,
|
TogglePlayResponse, InitRequest, InitResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
|
@ -74,6 +74,12 @@ impl RpcClient {
|
||||||
mem::replace(&mut self.update_stream, update_stream);
|
mem::replace(&mut self.update_stream, update_stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn init(&mut self) -> Result<InitResponse, Box<dyn Error>> {
|
||||||
|
let init_request = Request::new(InitRequest {});
|
||||||
|
let response = self.client.init(init_request).await?;
|
||||||
|
Ok(response.into_inner())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_library_node(
|
pub async fn get_library_node(
|
||||||
&mut self,
|
&mut self,
|
||||||
uuid: &str,
|
uuid: &str,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue