Skip to content

Commit 6bcc579

Browse files
committed
fix: fix various small issues
1 parent 7c82da1 commit 6bcc579

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

debian/service

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
[Unit]
22
Description=BloopBox
33
After=network.target
4+
StartLimitIntervalSec=0
45

56
[Service]
67
Type=simple
78
User=bloop-box
89
ExecStart=/usr/bin/bloop-box
910
Environment="RUST_LOG=info"
1011
Restart=always
12+
RestartSec=2
1113

1214
[Install]
1315
WantedBy=multi-user.target

src/etc_config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use anyhow::Result;
1+
use anyhow::{Context, Result};
22
use serde::Deserialize;
3+
use std::path::Path;
34
use tokio::fs::File;
45
use tokio::io::AsyncReadExt;
56

@@ -39,7 +40,10 @@ pub struct EtcConfig {
3940
}
4041

4142
pub async fn load_etc_config() -> Result<EtcConfig> {
42-
let mut file = File::open("/etc/bloop-box.conf").await?;
43+
let path = Path::new("/etc/bloop-box.conf");
44+
let mut file = File::open(&path)
45+
.await
46+
.with_context(|| format!("Failed to open {}", path.display()))?;
4347
let mut toml_config = String::new();
4448
file.read_to_string(&mut toml_config).await?;
4549
let config: EtcConfig = toml::from_str(&toml_config)?;

src/subsystems/audio_player.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::thread::sleep;
44
use std::time::Duration;
55

66
use crate::subsystems::config_manager::ConfigCommand;
7-
use anyhow::{anyhow, Error, Result};
7+
use anyhow::{anyhow, Context, Error, Result};
88
use glob::glob;
99
use log::info;
1010
use rand::seq::SliceRandom;
@@ -63,7 +63,7 @@ impl AudioPlayer {
6363

6464
async fn process(&mut self) -> Result<()> {
6565
let (soloud_tx, mut soloud_rx) = mpsc::channel(8);
66-
let share_path = self.share_path.to_str().unwrap().to_owned();
66+
let share_path = self.share_path.to_owned();
6767

6868
thread::spawn(move || {
6969
struct PlayState {
@@ -73,26 +73,30 @@ impl AudioPlayer {
7373

7474
let mut soloud = Soloud::default().unwrap();
7575
let mut play_wav = audio::Wav::default();
76+
let volume_change_path = share_path.join(Path::new("volume-change.mp3"));
7677
let mut volume_change_wav = audio::Wav::default();
77-
volume_change_wav
78-
.load(format!("{}/volume-change.mp3", share_path))
79-
.unwrap();
78+
volume_change_wav.load(volume_change_path).unwrap();
8079

8180
let mut handle_command = |soloud: &mut Soloud, command| {
8281
use SoloudCommand::*;
8382

8483
match command {
8584
PlayAsset { path, done } => {
85+
let path = share_path.join(path);
8686
play_wav
87-
.load(format!("{}/{}", share_path, path.to_str().unwrap()))
87+
.load(&path)
88+
.with_context(|| format!("Failed to play {}", path.display()))
8889
.unwrap();
8990
return Some(PlayState {
9091
handle: soloud.play(&play_wav),
9192
done,
9293
});
9394
}
9495
PlayFile { path, done } => {
95-
play_wav.load(path).unwrap();
96+
play_wav
97+
.load(&path)
98+
.with_context(|| format!("Failed to play {}", path.display()))
99+
.unwrap();
96100
return Some(PlayState {
97101
handle: soloud.play(&play_wav),
98102
done,

src/subsystems/controller.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ impl Controller {
123123
}
124124
None => continue,
125125
}
126-
127-
let (done_tx, done_rx) = oneshot::channel();
128-
self.audio_player.send(PlayerCommand::PlayCached {
129-
path: PathBuf::from(filename),
130-
done: done_tx,
131-
}).await?;
132-
done_rx.await?;
133126
}
127+
128+
let (done_tx, done_rx) = oneshot::channel();
129+
self.audio_player.send(PlayerCommand::PlayCached {
130+
path: PathBuf::from(filename),
131+
done: done_tx,
132+
}).await?;
133+
done_rx.await?;
134134
}
135135
},
136136
CheckUidResponse::Error {} => {

src/subsystems/networker.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::time::Duration;
77

88
use anyhow::{Error, Result};
99

10-
use log::info;
10+
use log::{debug, info};
1111

1212
use thiserror;
1313

@@ -142,12 +142,16 @@ impl Networker {
142142
CheckUid { uid, responder } => {
143143
let stream = match maybe_stream {
144144
Some(ref mut stream) => stream,
145-
None => continue,
145+
None => {
146+
responder.send(CheckUidResponse::Error {}).unwrap();
147+
continue;
148+
},
146149
};
147150

148151
match self.check_uid(stream, &uid).await {
149152
Ok(response) => responder.send(response).unwrap(),
150-
Err(_) => {
153+
Err(error) => {
154+
debug!("Lost connection due to: {}", error);
151155
maybe_stream = None;
152156
self.status_tx.send(NetworkerStatus::Disconnected).await?;
153157
responder.send(CheckUidResponse::Error {}).unwrap();
@@ -157,12 +161,16 @@ impl Networker {
157161
GetAudio { id, responder } => {
158162
let stream = match maybe_stream {
159163
Some(ref mut stream) => stream,
160-
None => continue,
164+
None => {
165+
responder.send(None).unwrap();
166+
continue;
167+
},
161168
};
162169

163170
match self.get_audio(stream, &id).await {
164171
Ok(data) => responder.send(data).unwrap(),
165-
Err(_) => {
172+
Err(error) => {
173+
debug!("Lost connection due to: {}", error);
166174
maybe_stream = None;
167175
self.status_tx.send(NetworkerStatus::Disconnected).await?;
168176
responder.send(None).unwrap();

0 commit comments

Comments
 (0)