Skip to content

Commit 4678268

Browse files
authored
Fix crash when switching to Bluetooth tab
Replaced thrown exceptions with safe fallback returns in DeviceSelectStateConverter. Prevents an unhandled ArgumentException when the binding returns a null or non-Device.
1 parent 541a28a commit 4678268

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Diff for: 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)