Skip to content

Commit

Permalink
Code cleanup, remove arm mac build (#216)
Browse files Browse the repository at this point in the history
* more code cleanup

* remove mac aarch from build for now

* gh actions

* fix gh action
  • Loading branch information
iamdb authored Nov 4, 2023
1 parent cf760bb commit 7b9e0bb
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 94 deletions.
34 changes: 5 additions & 29 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest]
target: [x86_64-unknown-linux-gnu, x86_64-apple-darwin, aarch64-apple-darwin]
target: [x86_64-unknown-linux-gnu, x86_64-apple-darwin]
rust: [stable]
exclude:
- os: ubuntu-latest
target: x86_64-apple-darwin
- os: ubuntu-latest
target: aarch64-apple-darwin
- os: macos-latest
target: x86_64-unknown-linux-gnu
env:
Expand All @@ -48,7 +46,6 @@ jobs:
run: |
brew install gstreamer
- name: Install Rust Toolchain
if: matrix.target != 'aarch64-unknown-linux-gnu'
uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -57,15 +54,15 @@ jobs:
components: rustfmt, clippy
override: true
- name: Install Cargo Plugins
if: matrix.target != 'aarch64-unknown-linux-gnu'
run: cargo install cargo-make cargo-insta sqlx-cli
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-make cargo-insta sqlx-cli
- name: Create db file
if: matrix.target != 'aarch64-unknown-linux-gnu'
run: "touch /tmp/data.db && cd hifirs && cargo sqlx database reset -y"
env:
DATABASE_URL: "sqlite:///tmp/data.db"
- name: Run CI Flow
if: matrix.target != 'aarch64-unknown-linux-gnu'
uses: actions-rs/cargo@v1
env:
QOBUZ_USERNAME: ${{secrets.QOBUZ_USERNAME}}
Expand All @@ -74,24 +71,3 @@ jobs:
with:
command: make
args: ci-flow
# - name: Check arm64
# uses: pguyot/arm-runner-action@v2
# if: matrix.target == 'aarch64-unknown-linux-gnu'
# env:
# QOBUZ_USERNAME: ${{secrets.QOBUZ_USERNAME}}
# QOBUZ_PASSWORD: ${{secrets.QOBUZ_PASSWORD}}
# DATABASE_URL: "sqlite:///tmp/data.db"
# with:
# base_image: raspios_lite_arm64:latest
# import_github_env: true
# commands: |
# apt-get update -y --allow-releaseinfo-change
# apt-get install --no-install-recommends -y libunwind-dev libgstreamer1.0-dev
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# echo 'source $HOME/.cargo/env' >> $HOME/.bashrc
# export PATH="$HOME/.cargo/bin:${PATH}"
# rustup -y target add aarch64-unknown-linux-gnu
# rustup -y toolchain install stable-aarch64-unknown-linux-gnu
# cargo binstall --no-confirm cargo-make cargo-insta sqlx-cli
# touch /tmp/data.db && cargo sqlx database reset --source ./hifirs/migrations -y
# cargo make ci-flow
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest]
target: [x86_64-unknown-linux-gnu, x86_64-apple-darwin, aarch64-apple-darwin]
target: [x86_64-unknown-linux-gnu, x86_64-apple-darwin]
rust: [stable]
exclude:
- os: ubuntu-latest
target: x86_64-apple-darwin
- os: ubuntu-latest
target: aarch64-apple-darwin
- os: macos-latest
target: x86_64-unknown-linux-gnu
env:
Expand Down Expand Up @@ -52,25 +50,27 @@ jobs:
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true
components: rust-src
- name: Install Cargo Plugins
run: cargo install sqlx-cli
uses: actions-rs/[email protected]
with:
crate: sqlx-cli
version: latest
use-tool-cache: true
- name: Create db file
run: "touch /tmp/data.db && cd hifirs && cargo sqlx database reset -y"
env:
env:
DATABASE_URL: "sqlite:///tmp/data.db"
- name: Build ${{ matrix.target }}
uses: actions-rs/cargo@v1
env:
PKG_CONFIG_ALLOW_CROSS: 1
SQLITE3_STATIC: true
PKG_CONFIG_ALL_STATIC: true
DATABASE_URL: "sqlite:///tmp/data.db"
with:
use-cross: true
command: build
args: --bin hifi-rs --release --target=${{ matrix.target }}
- name: Tar hifi-rs-${{ matrix.target }}.tar.gz
Expand Down
4 changes: 2 additions & 2 deletions hifirs/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ pub async fn run() -> Result<(), Error> {
)
.await?;

player::play_uri(url).await?;
player::play_uri(&url).await?;

wait!(mut handles, cli.disable_tui);

Expand Down Expand Up @@ -307,7 +307,7 @@ pub async fn run() -> Result<(), Error> {
)
.await?;

player::play_album(album_id).await?;
player::play_album(&album_id).await?;

wait!(mut handles, cli.disable_tui);

Expand Down
12 changes: 6 additions & 6 deletions hifirs/src/cursive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl CursiveUI {
let open = Arc::new(move |s: &mut Cursive| {
let mut panel = CursiveUI::enter_url(move |s, url| {
let u = url.to_string();
tokio::spawn(async move { CONTROLS.play_uri(u).await });
tokio::spawn(async move { CONTROLS.play_uri(&u).await });
s.pop_layer();
ENTER_URL_OPEN.store(false, Ordering::Relaxed);
});
Expand Down Expand Up @@ -549,8 +549,8 @@ fn load_search_results(item: &str, s: &mut Cursive) {

search_results.set_on_submit(move |_s: &mut Cursive, item: &String| {
if item != UNSTREAMABLE {
let i = item.clone();
tokio::spawn(async move { CONTROLS.play_album(i).await });
let item = item.clone();
tokio::spawn(async move { CONTROLS.play_album(&item).await });
}
});
}
Expand Down Expand Up @@ -671,7 +671,7 @@ fn submit_artist(s: &mut Cursive, item: i32) {

tree.add_leaf(a.list_item(), move |s: &mut Cursive| {
let id = a.id.clone();
tokio::spawn(async move { CONTROLS.play_album(id).await });
tokio::spawn(async move { CONTROLS.play_album(&id).await });

s.call_on_name(
"screens",
Expand Down Expand Up @@ -726,8 +726,8 @@ fn submit_track(s: &mut Cursive, item: (i32, Option<String>)) {
s.screen_mut().pop_layer();

if let Some(album_id) = &item.1 {
let a = album_id.clone();
tokio::spawn(async move { CONTROLS.play_album(a).await });
let id = album_id.clone();
tokio::spawn(async move { CONTROLS.play_album(&id).await });

s.call_on_name(
"screens",
Expand Down
14 changes: 7 additions & 7 deletions hifirs/src/mpris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub struct MprisPlayer {

#[dbus_interface(name = "org.mpris.MediaPlayer2.Player")]
impl MprisPlayer {
async fn open_uri(&self, uri: String) {
async fn open_uri(&self, uri: &str) {
self.controls.play_uri(uri).await;
}
async fn play(&self) {
Expand All @@ -280,13 +280,13 @@ impl MprisPlayer {
self.controls.previous().await;
}
#[dbus_interface(property, name = "PlaybackStatus")]
async fn playback_status(&self) -> String {
async fn playback_status(&self) -> &str {
match self.status {
GstState::Playing => "Playing".to_string(),
GstState::Paused => "Paused".to_string(),
GstState::Null => "Stopped".to_string(),
GstState::VoidPending => "Stopped".to_string(),
GstState::Ready => "Ready".to_string(),
GstState::Playing => "Playing",
GstState::Paused => "Paused",
GstState::Null => "Stopped",
GstState::VoidPending => "Stopped",
GstState::Ready => "Ready",
}
}
#[dbus_interface(property, name = "LoopStatus")]
Expand Down
20 changes: 15 additions & 5 deletions hifirs/src/player/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,21 @@ impl Controls {
pub async fn jump_backward(&self) {
action!(self, Action::JumpBackward);
}
pub async fn play_album(&self, album_id: String) {
action!(self, Action::PlayAlbum { album_id });
}
pub async fn play_uri(&self, uri: String) {
action!(self, Action::PlayUri { uri });
pub async fn play_album(&self, album_id: &str) {
action!(
self,
Action::PlayAlbum {
album_id: album_id.to_string()
}
);
}
pub async fn play_uri(&self, uri: &str) {
action!(
self,
Action::PlayUri {
uri: uri.to_string()
}
);
}
pub async fn play_track(&self, track_id: i32) {
action!(self, Action::PlayTrack { track_id });
Expand Down
32 changes: 16 additions & 16 deletions hifirs/src/player/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ pub async fn set_player_state(state: gst::State) -> Result<()> {

Ok(())
}
async fn broadcast_track_list<'a>(list: TrackListValue) -> Result<()> {
async fn broadcast_track_list<'a>(list: &TrackListValue) -> Result<()> {
BROADCAST_CHANNELS
.tx
.broadcast(Notification::CurrentTrackList { list })
.broadcast(Notification::CurrentTrackList { list: list.clone() })
.await?;
Ok(())
}
Expand Down Expand Up @@ -390,7 +390,7 @@ pub async fn skip(new_position: u32) -> Result<()> {

drop(state);

broadcast_track_list(list).await?;
broadcast_track_list(&list).await?;
BROADCAST_CHANNELS
.tx
.broadcast(Notification::Position {
Expand All @@ -415,7 +415,7 @@ pub async fn play_track(track_id: i32) -> Result<()> {

if let Some(track_url) = state.play_track(track_id).await {
let list = state.track_list();
broadcast_track_list(list).await?;
broadcast_track_list(&list).await?;

drop(state);

Expand All @@ -428,14 +428,14 @@ pub async fn play_track(track_id: i32) -> Result<()> {
}
#[instrument]
/// Plays a full album.
pub async fn play_album(album_id: String) -> Result<()> {
pub async fn play_album(album_id: &str) -> Result<()> {
ready().await?;

let mut state = QUEUE.get().unwrap().write().await;

if let Some(track_url) = state.play_album(album_id).await {
let list = state.track_list();
broadcast_track_list(list).await?;
broadcast_track_list(&list).await?;

drop(state);

Expand All @@ -454,7 +454,7 @@ pub async fn play_playlist(playlist_id: i64) -> Result<()> {
let mut state = QUEUE.get().unwrap().write().await;
if let Some(track_url) = state.play_playlist(playlist_id).await {
let list = state.track_list();
broadcast_track_list(list).await?;
broadcast_track_list(&list).await?;

drop(state);

Expand All @@ -467,11 +467,11 @@ pub async fn play_playlist(playlist_id: i64) -> Result<()> {
}
#[instrument]
/// Play an item from Qobuz web uri
pub async fn play_uri(uri: String) -> Result<()> {
match client::parse_url(uri.as_str()) {
pub async fn play_uri(uri: &str) -> Result<()> {
match client::parse_url(uri) {
Ok(url) => match url {
UrlType::Album { id } => {
play_album(id).await?;
play_album(&id).await?;
}
UrlType::Playlist { id } => {
play_playlist(id).await?;
Expand Down Expand Up @@ -687,12 +687,12 @@ pub async fn player_loop() -> Result<()> {
}
Some(msg) = messages.next() => {
if msg.type_() == MessageType::Buffering {
match handle_message(msg).await {
match handle_message(&msg).await {
Ok(_) => {},
Err(error) => debug!(?error),
};
} else {
tokio::spawn(async { match handle_message(msg).await {
tokio::spawn(async move { match handle_message(&msg).await {
Ok(()) => {}
Err(error) => {debug!(?error);}
}
Expand Down Expand Up @@ -728,13 +728,13 @@ async fn handle_action(action: Action) -> Result<()> {
}
Action::Stop => stop().await?,
Action::PlayAlbum { album_id } => {
play_album(album_id).await?;
play_album(&album_id).await?;
}
Action::PlayTrack { track_id } => {
play_track(track_id).await?;
}
Action::PlayUri { uri } => {
play_uri(uri).await?;
play_uri(&uri).await?;
}
Action::PlayPlaylist { playlist_id } => {
play_playlist(playlist_id).await?;
Expand All @@ -754,7 +754,7 @@ async fn handle_action(action: Action) -> Result<()> {
Ok(())
}

async fn handle_message(msg: Message) -> Result<()> {
async fn handle_message(msg: &Message) -> Result<()> {
match msg.view() {
MessageView::Eos(_) => {
debug!("END OF STREAM");
Expand All @@ -771,7 +771,7 @@ async fn handle_message(msg: Message) -> Result<()> {
MessageView::StreamStart(_) => {
if is_playing() {
let list = QUEUE.get().unwrap().read().await.track_list();
broadcast_track_list(list).await?;
broadcast_track_list(&list).await?;
}
}
MessageView::AsyncDone(msg) => {
Expand Down
4 changes: 2 additions & 2 deletions hifirs/src/player/queue/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ impl From<PlayerState> for SavedState {
}

impl PlayerState {
pub async fn play_album(&mut self, album_id: String) -> Option<String> {
pub async fn play_album(&mut self, album_id: &str) -> Option<String> {
debug!("setting up album to play");

if let Some(album) = self.service.album(album_id.as_str()).await {
if let Some(album) = self.service.album(album_id).await {
let mut tracklist = TrackListValue::new(Some(&album.tracks));
tracklist.set_album(album);
tracklist.set_list_type(TrackListType::Album);
Expand Down
4 changes: 2 additions & 2 deletions hifirs/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ async fn handle_connection(socket: WebSocket) {
Action::JumpForward => controls.jump_forward().await,
Action::JumpBackward => controls.jump_backward().await,
Action::PlayAlbum { album_id } => {
controls.play_album(album_id).await
controls.play_album(&album_id).await
}
Action::PlayTrack { track_id } => {
controls.play_track(track_id).await
}
Action::PlayUri { uri } => controls.play_uri(uri).await,
Action::PlayUri { uri } => controls.play_uri(&uri).await,
Action::PlayPlaylist { playlist_id } => {
controls.play_playlist(playlist_id).await
}
Expand Down
Loading

0 comments on commit 7b9e0bb

Please sign in to comment.