Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 49d5c166 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

AMADEUS: Add comments...

parent f5991721
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
use crate::{action, buttons::queue_control, client, AmadeusConfig}; use crate::{action, client, queue_control, AmadeusConfig};
use iced::{ use iced::{
executor, subscription, executor, subscription,
widget::{column, row}, widget::{column, row},
Alignment, Application, Command, Element, Event, Subscription, Theme, Alignment, Application, Command, Element, Event, Subscription, Theme,
}; };
/// The Amadeus application state.
#[derive(Debug)] #[derive(Debug)]
pub struct Amadeus { pub struct Amadeus {
client: client::Client, client: client::Client,
...@@ -14,12 +15,27 @@ pub struct Amadeus { ...@@ -14,12 +15,27 @@ pub struct Amadeus {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Message { pub enum Message {
/// Do nothing.
None, None,
/// Ask for a deconexion.
Disconnect, Disconnect,
/// Got an event from iced.
Event(Event), Event(Event),
/// Lektord send a notification.
Notification(action::Action), Notification(action::Action),
/// Send a command, perform the action.
Action(action::Action), Action(action::Action),
/// The client sent a message / the message must be dispatched to the
/// client for handling it.
Client(client::Message), Client(client::Message),
/// The queue controler sent a message / the message must be dispatched to
/// the queue controller (update its status).
QueueControl(queue_control::Message), QueueControl(queue_control::Message),
} }
...@@ -29,6 +45,8 @@ impl Application for Amadeus { ...@@ -29,6 +45,8 @@ impl Application for Amadeus {
type Theme = Theme; type Theme = Theme;
type Flags = AmadeusConfig; type Flags = AmadeusConfig;
/// Create a new application from the flags that were stored in the config
/// file (~/.config/amadeus/amadeus.toml).
fn new(flags: Self::Flags) -> (Self, Command<Self::Message>) { fn new(flags: Self::Flags) -> (Self, Command<Self::Message>) {
( (
Self { Self {
...@@ -40,10 +58,13 @@ impl Application for Amadeus { ...@@ -40,10 +58,13 @@ impl Application for Amadeus {
) )
} }
/// Get the title of the application, `Amadeus - {x}` where `x` is the
/// status, the playing file, etc.
fn title(&self) -> String { fn title(&self) -> String {
String::from("Amadeus") String::from("Amadeus")
} }
/// Update the state of the application, handling the passed message.
fn update(&mut self, message: Self::Message) -> Command<Self::Message> { fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
match message { match message {
Message::None => Command::none(), Message::None => Command::none(),
...@@ -64,8 +85,10 @@ impl Application for Amadeus { ...@@ -64,8 +85,10 @@ impl Application for Amadeus {
Command::none() Command::none()
} }
// We ignore events from iced for now.
Message::Event(_) => Command::none(), Message::Event(_) => Command::none(),
// Dispatch to the queue controler, re-dispatch any returned message.
Message::QueueControl(message) => { Message::QueueControl(message) => {
self.queue_control self.queue_control
.update(message) .update(message)
...@@ -76,6 +99,7 @@ impl Application for Amadeus { ...@@ -76,6 +99,7 @@ impl Application for Amadeus {
}) })
} }
// Dispatch to the client, re-dispatch any returned message.
Message::Client(message) => { Message::Client(message) => {
self.client self.client
.update(&self.flags, message) .update(&self.flags, message)
...@@ -89,19 +113,22 @@ impl Application for Amadeus { ...@@ -89,19 +113,22 @@ impl Application for Amadeus {
}) })
} }
// On notifications we update the queue controler. // On notifications we update only the queue controler for now, in
// the future we may update something else.
Message::Notification(message) => self.update(Message::QueueControl( Message::Notification(message) => self.update(Message::QueueControl(
queue_control::Message::Action(message), queue_control::Message::Action(message),
)), )),
// On an action, we ask the client to perform it, it will return a // On an action, we ask the client to perform it, it will return a
// notification latter. // notification latter. In the future we may want to send that
// action to another component.
Message::Action(message) => { Message::Action(message) => {
self.update(Message::Client(client::Message::Action(message))) self.update(Message::Client(client::Message::Action(message)))
} }
} }
} }
/// Display the whole application.
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<Self::Message> {
column![row![ column![row![
self.queue_control.view().map(Message::QueueControl), self.queue_control.view().map(Message::QueueControl),
...@@ -112,10 +139,12 @@ impl Application for Amadeus { ...@@ -112,10 +139,12 @@ impl Application for Amadeus {
.into() .into()
} }
/// Our theme.
fn theme(&self) -> Theme { fn theme(&self) -> Theme {
Theme::Dark Theme::Dark
} }
/// Get all the subscriptions, from iced and the client.
fn subscription(&self) -> Subscription<Self::Message> { fn subscription(&self) -> Subscription<Self::Message> {
Subscription::batch([ Subscription::batch([
subscription::events().map(Message::Event), subscription::events().map(Message::Event),
......
pub mod queue_control;
...@@ -9,11 +9,14 @@ use iced::{ ...@@ -9,11 +9,14 @@ use iced::{
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::sync::Arc; use std::sync::Arc;
/// The address of the lektord deamon.
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", content = "socket")] #[serde(tag = "type", content = "socket")]
pub enum Address { pub enum Address {
/// Connect over TCP/IP
TCP(String, i16), TCP(String, i16),
/// Connect over UNIX domain socket.
#[cfg(unix)] #[cfg(unix)]
UNIX(String), UNIX(String),
} }
...@@ -29,8 +32,13 @@ impl std::fmt::Display for Address { ...@@ -29,8 +32,13 @@ impl std::fmt::Display for Address {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Message { pub enum Message {
/// Nothing to do...
None, None,
/// We ask for a connexion
Connect, Connect,
/// We are connected.
Connected(Arc<Mutex<amalib::AmaClient>>), Connected(Arc<Mutex<amalib::AmaClient>>),
/// Got an error... /// Got an error...
...@@ -52,16 +60,26 @@ pub enum Message { ...@@ -52,16 +60,26 @@ pub enum Message {
Multiple(Vec<Message>), Multiple(Vec<Message>),
} }
/// The state of the coposent that communicate with lektord.
#[derive(Debug)] #[derive(Debug)]
enum State { enum State {
/// We are offline.
Offline, Offline,
/// We are online.
Online(Arc<Mutex<amalib::AmaClient>>), Online(Arc<Mutex<amalib::AmaClient>>),
/// We are asking to connect to an address.
AskConnection(Address), AskConnection(Address),
} }
/// The private state of a worker.
#[derive(Debug)] #[derive(Debug)]
struct WorkerState(Arc<Mutex<amalib::AmaClient>>); struct WorkerState(Arc<Mutex<amalib::AmaClient>>);
/// The client thing in amadeus. Responsible to poll notifications and perform
/// actions when needed. We add a view for that thing to print some statuses
/// somewhere in the window.
#[derive(Debug)] #[derive(Debug)]
pub struct Client { pub struct Client {
state: State, state: State,
......
...@@ -6,10 +6,8 @@ use serde::{Deserialize, Serialize}; ...@@ -6,10 +6,8 @@ use serde::{Deserialize, Serialize};
mod action; mod action;
mod amadeus; mod amadeus;
mod buttons;
mod client; mod client;
mod queue_control;
pub(crate) const CHANNEL_SIZE: usize = 128;
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct AmadeusRemoteConfig { pub struct AmadeusRemoteConfig {
......
...@@ -8,19 +8,23 @@ pub enum Message { ...@@ -8,19 +8,23 @@ pub enum Message {
Disconnect, Disconnect,
} }
/// The state of the queue controler.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
struct State(Option<amalib::LektorState>); struct State(Option<amalib::LektorState>);
/// The queue controler. Can play/pause, play the next/previous kara, etc.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct QueueControl { pub struct QueueControl {
state: State, state: State,
} }
impl QueueControl { impl QueueControl {
/// Create a new queue controler
pub fn new() -> Self { pub fn new() -> Self {
Self { state: State(None) } Self { state: State(None) }
} }
/// Update the queue controler, apply any change received from lektord.
pub fn update(&mut self, message: Message) -> Command<Message> { pub fn update(&mut self, message: Message) -> Command<Message> {
use amalib::LektorState::*; use amalib::LektorState::*;
match message { match message {
...@@ -72,6 +76,8 @@ impl QueueControl { ...@@ -72,6 +76,8 @@ impl QueueControl {
} }
} }
/// View the queue controller. Depending on its state, we may want to send
/// commands to lektord.
pub fn view(&self) -> Element<Message> { pub fn view(&self) -> Element<Message> {
const SIZE: u16 = 20; const SIZE: u16 = 20;
use amalib::LektorState::*; use amalib::LektorState::*;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter