Skip to content

Commit

Permalink
Update for latest Rust nightly and bump version (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-jan committed Jul 19, 2022
1 parent 6c8c00d commit e47a478
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 70 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "apex-tux"
version = "1.0.0"
version = "1.0.1"
edition = "2021"

[workspace]
Expand Down Expand Up @@ -51,6 +51,7 @@ apex-input = {path = "./apex-input" }
apex-music = { path = "./apex-music" }
apex-simulator = { path = "./apex-simulator", optional = true }
apex-engine = { path = "./apex-engine", optional = true }
lazy_static = "1.4.0"


[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
10 changes: 6 additions & 4 deletions src/dbus/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ use dbus_tokio::connection;
use embedded_graphics::pixelcolor::BinaryColor;
use futures::{channel::mpsc, StreamExt};
use futures_core::Stream;
use lazy_static::lazy_static;
use linkme::distributed_slice;
use log::{debug, info};
use std::{convert::TryFrom, lazy::SyncLazy, time::Duration};
use std::{convert::TryFrom, time::Duration};
use tinybmp::Bmp;

#[distributed_slice(NOTIFICATION_PROVIDERS)]
Expand All @@ -35,9 +36,10 @@ fn register_callback() -> Result<Box<dyn NotificationWrapper>> {
}

static DISCORD_ICON: &[u8] = include_bytes!("./../../assets/discord.bmp");

static DISCORD_ICON_BMP: SyncLazy<Bmp<BinaryColor>> =
SyncLazy::new(|| Bmp::<BinaryColor>::from_slice(DISCORD_ICON).expect("Failed to parse BMP"));
lazy_static! {
static ref DISCORD_ICON_BMP: Bmp<'static, BinaryColor> =
Bmp::<BinaryColor>::from_slice(DISCORD_ICON).expect("Failed to parse BMP");
}

pub struct Dbus {}

Expand Down
3 changes: 0 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
#![feature(
generic_associated_types,
type_alias_impl_trait,
const_fn_trait_bound,
once_cell,
try_blocks,
const_fn_floating_point_arithmetic,
inherent_associated_types,
box_into_pin,
async_closure,
async_iterator,
decl_macro
Expand Down
10 changes: 6 additions & 4 deletions src/providers/coindesk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ use embedded_graphics::{
Drawable,
};
use futures::Stream;
use lazy_static::lazy_static;
use linkme::distributed_slice;
use log::info;
use reqwest::{header, Client, ClientBuilder};
use serde::{Deserialize, Serialize};
use std::{convert::TryFrom, lazy::SyncLazy, time::Duration};
use std::{convert::TryFrom, time::Duration};
use tinybmp::Bmp;
use tokio::{time, time::MissedTickBehavior};

static BTC_ICON: &[u8] = include_bytes!("./../../assets/btc.bmp");

static BTC_BMP: SyncLazy<Bmp<BinaryColor>> = SyncLazy::new(|| {
Bmp::<BinaryColor>::from_slice(BTC_ICON).expect("Failed to parse BMP for BTC icon!")
});
lazy_static! {
static ref BTC_BMP: Bmp<'static, BinaryColor> =
Bmp::<BinaryColor>::from_slice(BTC_ICON).expect("Failed to parse BMP for BTC icon!");
}

#[distributed_slice(CONTENT_PROVIDERS)]
pub static PROVIDER_INIT: fn(&Config) -> Result<Box<dyn ContentWrapper>> = register_callback;
Expand Down
114 changes: 56 additions & 58 deletions src/providers/music.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ use crate::render::display::ContentProvider;
use anyhow::anyhow;
use anyhow::Result;
use async_stream::try_stream;
use embedded_graphics::{
geometry::Size,
image::Image,
pixelcolor::BinaryColor,
prelude::{Point, },

Drawable,
};
#[cfg(not(target_os = "windows"))]
use embedded_graphics::prelude::Primitive;
#[cfg(not(target_os = "windows"))]
use embedded_graphics::primitives::{Line, PrimitiveStyle};
use embedded_graphics::{
geometry::Size, image::Image, pixelcolor::BinaryColor, prelude::Point, Drawable,
};
use futures_core::stream::Stream;
use linkme::distributed_slice;

Expand All @@ -26,41 +21,43 @@ use crate::render::{
scheduler::{ContentWrapper, CONTENT_PROVIDERS},
text::{ScrollableBuilder, StatefulScrollable},
};
use apex_music::{AsyncPlayer, Metadata};
use apex_music::{AsyncPlayer, Metadata, Progress};
use config::Config;
use embedded_graphics::{
mono_font::{ascii, MonoTextStyle},
text::{Baseline, Text},
};
use futures::StreamExt;
use apex_music::Progress;
use std::{convert::TryInto, lazy::SyncLazy, sync::Arc};
use std::{convert::TryInto, sync::Arc};
use tokio::time::{Duration, MissedTickBehavior};

use apex_hardware::FrameBuffer;
use apex_music::PlaybackStatus;
use futures::pin_mut;
use lazy_static::lazy_static;

static NOTE_ICON: &[u8] = include_bytes!("./../../assets/note.bmp");
static PAUSE_ICON: &[u8] = include_bytes!("./../../assets/pause.bmp");

static PAUSE_BMP: SyncLazy<Bmp<BinaryColor>> = SyncLazy::new(|| {
Bmp::<BinaryColor>::from_slice(PAUSE_ICON).expect("Failed to parse BMP for pause icon!")
});

static NOTE_BMP: SyncLazy<Bmp<BinaryColor>> = SyncLazy::new(|| {
Bmp::<BinaryColor>::from_slice(NOTE_ICON).expect("Failed to parse BMP for note icon!")
});
lazy_static! {
static ref PAUSE_BMP: Bmp<'static, BinaryColor> =
Bmp::<BinaryColor>::from_slice(PAUSE_ICON).expect("Failed to parse BMP for pause icon!");
}

// Windows doesn't expose the current progress within the song so we don't draw it here
// TODO: Spice this up?
lazy_static! {
static ref NOTE_BMP: Bmp<'static, BinaryColor> =
Bmp::<BinaryColor>::from_slice(NOTE_ICON).expect("Failed to parse BMP for note icon!");
}
#[cfg(target_os = "windows")]
static PLAYER_TEMPLATE: SyncLazy<FrameBuffer> = SyncLazy::new(|| {
FrameBuffer::new()
});
lazy_static! {
// Windows doesn't expose the current progress within the song so we don't draw
// it here TODO: Spice this up?
static ref PLAYER_TEMPLATE: FrameBuffer = FrameBuffer::new();
}

#[cfg(not(target_os = "windows"))]
static PLAYER_TEMPLATE: SyncLazy<FrameBuffer> = SyncLazy::new(|| {
lazy_static! {
static ref PLAYER_TEMPLATE: FrameBuffer = {
let mut base = FrameBuffer::new();
let style = PrimitiveStyle::with_stroke(BinaryColor::On, 1);

Expand All @@ -71,7 +68,7 @@ static PLAYER_TEMPLATE: SyncLazy<FrameBuffer> = SyncLazy::new(|| {
];

// Draw a border for the progress bar
points
points
.iter()
.try_for_each(|(first, second)| {
Line::new(*first, *second)
Expand All @@ -81,37 +78,41 @@ static PLAYER_TEMPLATE: SyncLazy<FrameBuffer> = SyncLazy::new(|| {
.expect("Failed to prepare template image for music player!");

base
});

static PLAY_TEMPLATE: SyncLazy<FrameBuffer> = SyncLazy::new(|| {
let mut base = *PLAYER_TEMPLATE;
Image::new(&*NOTE_BMP, Point::new(5, 5))
.draw(&mut base)
.expect("Failed to prepare 'play' template for music player");
base
});

static PAUSE_TEMPLATE: SyncLazy<FrameBuffer> = SyncLazy::new(|| {
let mut base = *PLAYER_TEMPLATE;
Image::new(&*PAUSE_BMP, Point::new(5, 5))
};
}
lazy_static! {
static ref PLAY_TEMPLATE: FrameBuffer = {
let mut base = *PLAYER_TEMPLATE;
Image::new(&*NOTE_BMP, Point::new(5, 5))
.draw(&mut base)
.expect("Failed to prepare 'play' template for music player");
base
};
}
lazy_static! {
static ref PAUSE_TEMPLATE: FrameBuffer = {
let mut base = *PLAYER_TEMPLATE;
Image::new(&*PAUSE_BMP, Point::new(5, 5))
.draw(&mut base)
.expect("Failed to prepare 'pause' template for music player");
base
};
}
lazy_static! {
static ref IDLE_TEMPLATE: FrameBuffer = {
let mut base = *PAUSE_TEMPLATE;
let style = MonoTextStyle::new(&ascii::FONT_6X10, BinaryColor::On);
Text::with_baseline(
"No player found",
Point::new(5 + 3 + 24, 3),
style,
Baseline::Top,
)
.draw(&mut base)
.expect("Failed to prepare 'pause' template for music player");
base
});

static IDLE_TEMPLATE: SyncLazy<FrameBuffer> = SyncLazy::new(|| {
let mut base = *PAUSE_TEMPLATE;
let style = MonoTextStyle::new(&ascii::FONT_6X10, BinaryColor::On);
Text::with_baseline(
"No player found",
Point::new(5 + 3 + 24, 3),
style,
Baseline::Top,
)
.draw(&mut base)
.expect("Failed to prepare 'idle' template for music player");
base
});
.expect("Failed to prepare 'idle' template for music player");
base
};
}

static UNKNOWN_TITLE: &str = "Unknown title";
static UNKNOWN_ARTIST: &str = "Unknown artist";
Expand Down Expand Up @@ -241,9 +242,6 @@ impl ContentProvider for MediaPlayerBuilder {
self.name
);




let mut renderer = MediaPlayerRenderer::new()?;

Ok(try_stream! {
Expand Down

0 comments on commit e47a478

Please sign in to comment.