Skip to content

Commit 882ed7c

Browse files
authored
Fix: Use config defaults instead of type defaults (#1556)
* fix: use the config instead of the type default * chore: update changelog * fix: repair build for pulseaudio-backend
1 parent c715885 commit 882ed7c

File tree

2 files changed

+43
-40
lines changed

2 files changed

+43
-40
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
- [connect] Only deletes the connect state on dealer shutdown instead on disconnecting
2121
- [core] Fixed a problem where in `spclient` where a http 411 error was thrown because the header were set wrong
22+
- [main] Use the config instead of the type default for values that are not provided by the user
23+
2224

2325
### Security
2426

src/main.rs

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,21 +1383,22 @@ async fn get_setup() -> Setup {
13831383
let connect_config = {
13841384
let connect_default_config = ConnectConfig::default();
13851385

1386-
let name = opt_str(NAME).unwrap_or_else(|| connect_default_config.name.clone());
1387-
1388-
if name.is_empty() {
1386+
let name = opt_str(NAME);
1387+
if matches!(name, Some(ref name) if name.is_empty()) {
13891388
empty_string_error_msg(NAME, NAME_SHORT);
13901389
exit(1);
13911390
}
13921391

13931392
#[cfg(feature = "pulseaudio-backend")]
13941393
{
13951394
if env::var("PULSE_PROP_application.name").is_err() {
1396-
let pulseaudio_name = if name != connect_default_config.name {
1397-
format!("{} - {}", connect_default_config.name, name)
1398-
} else {
1399-
name.clone()
1400-
};
1395+
let op_pulseaudio_name = name
1396+
.as_ref()
1397+
.map(|name| format!("{} - {}", connect_default_config.name, name));
1398+
1399+
let pulseaudio_name = op_pulseaudio_name
1400+
.as_deref()
1401+
.unwrap_or(&connect_default_config.name);
14011402

14021403
set_env_var("PULSE_PROP_application.name", pulseaudio_name).await;
14031404
}
@@ -1467,51 +1468,51 @@ async fn get_setup() -> Setup {
14671468
} else {
14681469
cache.as_ref().and_then(Cache::volume)
14691470
}
1470-
})
1471-
.unwrap_or_default();
1471+
});
14721472

1473-
let device_type = opt_str(DEVICE_TYPE)
1474-
.as_deref()
1475-
.map(|device_type| {
1476-
DeviceType::from_str(device_type).unwrap_or_else(|_| {
1477-
invalid_error_msg(
1478-
DEVICE_TYPE,
1479-
DEVICE_TYPE_SHORT,
1480-
device_type,
1481-
"computer, tablet, smartphone, \
1473+
let device_type = opt_str(DEVICE_TYPE).as_deref().map(|device_type| {
1474+
DeviceType::from_str(device_type).unwrap_or_else(|_| {
1475+
invalid_error_msg(
1476+
DEVICE_TYPE,
1477+
DEVICE_TYPE_SHORT,
1478+
device_type,
1479+
"computer, tablet, smartphone, \
14821480
speaker, tv, avr, stb, audiodongle, \
14831481
gameconsole, castaudio, castvideo, \
14841482
automobile, smartwatch, chromebook, \
14851483
carthing",
1486-
DeviceType::default().into(),
1487-
);
1484+
DeviceType::default().into(),
1485+
);
14881486

1489-
exit(1);
1490-
})
1487+
exit(1);
14911488
})
1492-
.unwrap_or_default();
1489+
});
14931490

1494-
let volume_steps = opt_str(VOLUME_STEPS)
1495-
.map(|steps| match steps.parse::<u16>() {
1496-
Ok(value) => value,
1497-
_ => {
1498-
let default_value = &connect_default_config.volume_steps.to_string();
1491+
let volume_steps = opt_str(VOLUME_STEPS).map(|steps| match steps.parse::<u16>() {
1492+
Ok(value) => value,
1493+
_ => {
1494+
let default_value = &connect_default_config.volume_steps.to_string();
14991495

1500-
invalid_error_msg(
1501-
VOLUME_STEPS,
1502-
VOLUME_STEPS_SHORT,
1503-
&steps,
1504-
"a positive whole number <= 65535",
1505-
default_value,
1506-
);
1496+
invalid_error_msg(
1497+
VOLUME_STEPS,
1498+
VOLUME_STEPS_SHORT,
1499+
&steps,
1500+
"a positive whole number <= 65535",
1501+
default_value,
1502+
);
15071503

1508-
exit(1);
1509-
}
1510-
})
1511-
.unwrap_or_else(|| connect_default_config.volume_steps);
1504+
exit(1);
1505+
}
1506+
});
15121507

15131508
let is_group = opt_present(DEVICE_IS_GROUP);
15141509

1510+
// use config defaults if not provided
1511+
let name = name.unwrap_or(connect_default_config.name);
1512+
let device_type = device_type.unwrap_or(connect_default_config.device_type);
1513+
let initial_volume = initial_volume.unwrap_or(connect_default_config.initial_volume);
1514+
let volume_steps = volume_steps.unwrap_or(connect_default_config.volume_steps);
1515+
15151516
ConnectConfig {
15161517
name,
15171518
device_type,

0 commit comments

Comments
 (0)