Skip to content

Commit 6311ce3

Browse files
authored
Merge pull request timschneeb#600 from NilaierMusic/master
Fix crash in DeviceSelectStateConverter when switching to Bluetooth tab (timschneeb#580, timschneeb#597)
2 parents 541a28a + 4678268 commit 6311ce3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

GalaxyBudsClient/Interface/Converters/DeviceSelectStateConverter.cs

+14-7
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,27 @@ public class DeviceSelectStateConverter : IMultiValueConverter
2121
{
2222
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
2323
{
24-
if(values.Count < 2)
25-
throw new ArgumentException("Expected 2 values");
24+
if (values.Count < 2)
25+
return null;
26+
27+
// If the first value is null, you likely can't compare anything, so pick a fallback:
2628
if (values[0] is null)
2729
return null;
28-
if(values[0] is not Device device)
29-
throw new ArgumentException("Expected Device as first value");
30+
31+
if (values[0] is not Device device)
32+
{
33+
// Instead of throwing, return a fallback
34+
return null;
35+
}
3036

3137
var lastConnectedMac = values[1] as string;
3238
var isSelected = device.MacAddress == lastConnectedMac;
33-
39+
3440
return parameter switch
3541
{
3642
DeviceStateConverterTarget.Label => isSelected ? Strings.DevicesSelectActive : Strings.DevicesSelectInactive,
37-
DeviceStateConverterTarget.Icon => new SymbolIconSource {
43+
DeviceStateConverterTarget.Icon => new SymbolIconSource
44+
{
3845
Symbol = isSelected ? Symbol.CheckboxChecked : Symbol.CheckboxUnchecked,
3946
IsFilled = isSelected
4047
},
@@ -43,4 +50,4 @@ public class DeviceSelectStateConverter : IMultiValueConverter
4350
_ => isSelected
4451
};
4552
}
46-
}
53+
}

0 commit comments

Comments
 (0)