Skip to content

Commit

Permalink
GUI: autoreconnect supports multiple players
Browse files Browse the repository at this point in the history
fixes issue #129
  • Loading branch information
dheijl committed Apr 23, 2024
1 parent b0d1cee commit 68ae8bb
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# swyh-rs Changelog

- 1.10.4 (unreleased)
- 1.10.4 (Apr 23 2024 dheijl)
- GUI: autoreconnect now works for multiple players. When you close swyh-rs (GUI) any players still active will be remembered in the config before they are stopped. This should fix issue #129. CLI is unaffected by this change.

- 1.10.3 (Apr 82024 dheijl)
- 1.10.3 (Apr 8 2024 dheijl)
- GUI: try to stop any players still streaming when the swyh-rs windows is closed. If the players don't stop streaming voluntarily exit anyway (after a 5 second time-out).

- 1.10.2 (Apr 8 2024 dheijl)
Expand Down
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[profile.release]
codegen-units = 1
lto = "thin"

[features]
gui = ["dep:fltk"]
cli = ["dep:local-ip-address"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A "Stream-What-You-Hear" implementation written in Rust, MIT licensed.

## Current Release

The current release is 1.10.3, refer to the [Changelog](CHANGELOG.md) for more details.
The current release is 1.10.4, refer to the [Changelog](CHANGELOG.md) for more details.

## Why this SWYH alternative ?

Expand Down
11 changes: 10 additions & 1 deletion src/bin/swyh-rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,23 @@ fn main() {
mf.add_log_msg(&msg);
}
} // while app::wait()
// if anyone is still streaming: stop them first

// if anyone is still streaming: stop them first
let mut active_players: Vec<String> = Vec::new();
for button in mf.buttons.iter() {
if button.1.is_set() {
if let Some(r) = renderers.iter().find(|r| r.remote_addr == *button.0) {
active_players.push(r.remote_addr.clone());
r.stop_play(&ui_log);
}
}
}
// remeber active players in config for auto_reconnect
{
let mut config = CONFIG.write();
config.active_renderers = active_players;
let _ = config.update_config();
}
// and now wait some time for them to stop the HTTP streaming connection too
for _ in 0..50 {
if CLIENTS.read().len() == 0 {
Expand Down
17 changes: 11 additions & 6 deletions src/ui/mainform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use fltk::{
window::DoubleWindow,
};
//use fltk_flow::Flow;
use log::{debug, LevelFilter};
use log::{debug, info, LevelFilter};
use parking_lot::Mutex;
use std::{cell::Cell, collections::HashMap, net::IpAddr, rc::Rc, str::FromStr};

Expand Down Expand Up @@ -697,11 +697,16 @@ impl MainForm {
.insert(new_renderer.remote_addr.clone(), pbut.clone()); // and keep a reference to it for bookkeeping
app::redraw();
// check if autoreconnect is set for this renderer
if self.auto_reconnect.is_set()
&& pbut.label() == *CONFIG.read().last_renderer.as_ref().unwrap()
{
pbut.turn_on(true);
pbut.do_callback();
if self.auto_reconnect.is_set() {
let active_players = CONFIG.read().active_renderers.clone();
info!("AutoReconnect: Active Renderers = {:?}", active_players);
if active_players
.iter()
.any(|p| *p == new_renderer.remote_addr)
{
pbut.turn_on(true);
pbut.do_callback();
}
}
}
}
3 changes: 3 additions & 0 deletions src/utils/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pub struct Configuration {
pub inject_silence: Option<bool>,
#[serde(alias = "LastRenderer", default)]
pub last_renderer: Option<String>,
#[serde(alias = "ActiveRenderers", default)]
pub active_renderers: Vec<String>,
#[serde(alias = "LastNetwork", default)]
pub last_network: Option<String>,
#[serde(alias = "ConfigDir", default)]
Expand Down Expand Up @@ -137,6 +139,7 @@ impl Configuration {
capture_timeout: Some(2000),
inject_silence: Some(false),
last_renderer: None,
active_renderers: Vec::new(),
last_network: None,
config_dir: Self::get_config_dir(),
config_id: Some(Self::get_config_id()),
Expand Down

0 comments on commit 68ae8bb

Please sign in to comment.