Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Companion/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace Companion;

public class App : Application
{
public static IServiceProvider ServiceProvider { get; private set; }
public static IServiceProvider ServiceProvider { get; private set; } = null!;

public static string OSType { get; private set; }
public static string OSType { get; private set; } = "Unknown";

#if DEBUG
private bool _ShouldCheckForUpdates = false;
Expand Down Expand Up @@ -243,7 +243,7 @@ public override void OnFrameworkInitializationCompleted()

// check for updates
if (_ShouldCheckForUpdates)
CheckForUpdatesAsync();
_ = CheckForUpdatesAsync();

if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
Expand Down
6 changes: 3 additions & 3 deletions Companion/Converters/BooleanGreaterThanConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Companion.Converters;
/// </summary>
public class BooleanGreaterThanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value == null || parameter == null)
return false;
Expand All @@ -27,8 +27,8 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
return false;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
16 changes: 11 additions & 5 deletions Companion/Converters/BooleanToTextConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ namespace Companion.Converters;

public class BooleanToTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var texts = parameter.ToString().Split(',');
return (bool)value ? texts[1] : texts[0];
if (parameter == null)
return string.Empty;

var texts = parameter.ToString()?.Split(',') ?? Array.Empty<string>();
if (texts.Length < 2 || value is not bool flag)
return string.Empty;

return flag ? texts[1] : texts[0];
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
12 changes: 7 additions & 5 deletions Companion/Converters/BooleanToVisibilityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ namespace Companion.Converters;

public class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var isVisible = (bool)value;
return isVisible ? Visibility.Visible : Visibility.Collapse;
if (value is bool isVisible)
return isVisible ? Visibility.Visible : Visibility.Collapse;

return Visibility.Collapse;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
20 changes: 15 additions & 5 deletions Companion/Converters/BooleanToWidthConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ namespace Companion.Converters;

public class BooleanToWidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var widths = parameter.ToString().Split(',');
return (bool)value ? double.Parse(widths[0]) : double.Parse(widths[1]);
if (parameter == null || value is not bool flag)
return 0d;

var widths = parameter.ToString()?.Split(',') ?? Array.Empty<string>();
if (widths.Length < 2)
return 0d;

if (!double.TryParse(widths[0], out var trueWidth) ||
!double.TryParse(widths[1], out var falseWidth))
return 0d;

return flag ? trueWidth : falseWidth;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
6 changes: 3 additions & 3 deletions Companion/Converters/CanConnectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Companion.Converters;

public class CanConnectConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
// Try to get the DataContext from the current view model
if (Avalonia.Application.Current?.DataContext is PresetsTabViewModel viewModel)
Expand Down Expand Up @@ -58,8 +58,8 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
return null;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
12 changes: 6 additions & 6 deletions Companion/Converters/EnumToBoolConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ namespace Companion.Converters;

public class EnumToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value != null && value.GetType().IsEnum) return (int)value == (int)parameter;
if (value != null && value.GetType().IsEnum && parameter != null) return (int)value == (int)parameter;
return false;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (targetType.IsEnum)
if (value is bool boolValue)
if (value is bool boolValue && parameter != null)
{
if (boolValue)
return Enum.Parse(targetType, parameter.ToString());
return Enum.Parse(targetType, parameter.ToString() ?? "None");
return Enum.Parse(targetType, "None"); // or some other default value
}

throw new ArgumentException("Unsupported type", nameof(value));
}
}
}
6 changes: 3 additions & 3 deletions Companion/Converters/InvertedBooleanConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace Companion.Converters;
public class InvertedBooleanConverter : IValueConverter

{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool booleanValue) return !booleanValue;
return false;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool booleanValue) return !booleanValue;
return false;
}
}
}
6 changes: 3 additions & 3 deletions Companion/Converters/NullToBoolConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace Companion.Converters;

public class NullToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value != null;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
4 changes: 2 additions & 2 deletions Companion/Converters/PowerThresholdColorConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PowerThresholdColorConverter : IValueConverter
/// </summary>
public ISolidColorBrush WarningColor { get; set; } = new SolidColorBrush(Colors.Red);

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is double doubleValue)
{
Expand All @@ -40,7 +40,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
return NormalColor;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
Expand Down
6 changes: 3 additions & 3 deletions Companion/Converters/TagsToStringConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Companion.Converters;

public class TagsToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is ObservableCollection<string> tags)
{
Expand All @@ -16,8 +16,8 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
return string.Empty;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
4 changes: 2 additions & 2 deletions Companion/Events/AppMessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AppMessage
public string? Status
{
get => _status;
set => _status = value;
set => _status = value ?? string.Empty;
}

public DeviceConfig DeviceConfig { get; set; } = DeviceConfig.Instance;
Expand All @@ -31,4 +31,4 @@ public override string ToString()
return $"{nameof(Message)}: {Message}, {nameof(Status)}: {Status}, " +
$"{nameof(DeviceConfig)}: {DeviceConfig}, {nameof(CanConnect)}: {CanConnect}";
}
}
}
10 changes: 5 additions & 5 deletions Companion/Events/RadxaContentUpdateEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ public class RadxaContentUpdateChangeEvent : PubSubEvent<RadxaContentUpdatedMess

public class RadxaContentUpdatedMessage
{
public string WifiBroadcastContent { get; set; }
public string ScreenModeContent { get; set; }
public string WfbConfContent { get; set; }
public string WifiBroadcastContent { get; set; } = string.Empty;
public string ScreenModeContent { get; set; } = string.Empty;
public string WfbConfContent { get; set; } = string.Empty;

public string DroneKeyContent { get; set; }
public string DroneKeyContent { get; set; } = string.Empty;


public override string ToString()
{
return
$"{nameof(WifiBroadcastContent)}: {WifiBroadcastContent}, {nameof(ScreenModeContent)}: {ScreenModeContent}, {nameof(WfbConfContent)}: {WfbConfContent}, {nameof(DroneKeyContent)}: {DroneKeyContent}";
}
}
}
4 changes: 2 additions & 2 deletions Companion/Logging/EventAggregatorSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class EventAggregatorSink : ILogEventSink
private readonly IEventAggregator _eventAggregator;
private readonly IFormatProvider _formatProvider;

public EventAggregatorSink(IEventAggregator eventAggregator, IFormatProvider formatProvider = null)
public EventAggregatorSink(IEventAggregator eventAggregator, IFormatProvider? formatProvider = null)
{
_eventAggregator = eventAggregator;
_formatProvider = formatProvider ?? CultureInfo.InvariantCulture;
Expand All @@ -25,4 +25,4 @@ public void Emit(LogEvent logEvent)
// Enqueue the log message instead of directly publishing
LogQueue.Enqueue(message);
}
}
}
22 changes: 11 additions & 11 deletions Companion/Models/DeviceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ namespace Companion.Models;
public class DeviceConfig : INotifyPropertyChanged
{
#region Private Fields
private static DeviceConfig _instance;
private string _hostname;
private string _ipAddress;
private string _keyChksum;
private string _password;
private string _chipType;
private string _sensorType;
private string _networkCardType;
private static DeviceConfig? _instance;
private string _hostname = string.Empty;
private string _ipAddress = string.Empty;
private string _keyChksum = string.Empty;
private string _password = string.Empty;
private string _chipType = string.Empty;
private string _sensorType = string.Empty;
private string _networkCardType = string.Empty;

private int _port;
private string _username;
private string _username = "root";


#endregion
Expand All @@ -37,7 +37,7 @@ public DeviceConfig()
/// <summary>
/// Gets or sets the event aggregator for device events
/// </summary>
public IEventAggregator EventAggregator { get; set; }
public IEventAggregator? EventAggregator { get; set; }

/// <summary>
/// Gets the singleton instance of DeviceConfig
Expand Down Expand Up @@ -209,4 +209,4 @@ protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? prop
return true;
}
#endregion
}
}
16 changes: 8 additions & 8 deletions Companion/Models/OpenIPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public enum FileType
public const string RemoteTempFolder = "/tmp";
public const string RemoteWifiBroadcastBinFileLoc = "/usr/bin/wifibroadcast";

public static string DroneKeyPath;
public static string GsKeyPath;
public static string DroneKeyPath = string.Empty;
public static string GsKeyPath = string.Empty;

public static string LocalFirmwareFolder;
public static string LocalBackUpFolder;
public static string LocalFirmwareFolder = string.Empty;
public static string LocalBackUpFolder = string.Empty;

public static string DeviceUsername = "root";

Expand All @@ -61,12 +61,12 @@ static OpenIPC()
}

// Expose configPath and configDirectory as public static properties
public static string AppDataConfigDirectory { get; private set; }
public static string AppDataConfigDirectory { get; private set; } = string.Empty;

public static string LocalTempFolder { get; private set; }
public static string AppDataConfigPath { get; private set; }
public static string LocalTempFolder { get; private set; } = string.Empty;
public static string AppDataConfigPath { get; private set; } = string.Empty;

public static string DeviceSettingsConfigPath { get; private set; }
public static string DeviceSettingsConfigPath { get; private set; } = string.Empty;

public static string GetBinariesPath()
{
Expand Down
4 changes: 2 additions & 2 deletions Companion/Models/Presets/FileModification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Companion.Models.Presets;

public class FileModification
{
public string FileName { get; set; }
public string FileName { get; set; } = string.Empty;
public ObservableCollection<KeyValuePair<string, string>> Changes { get; set; }

public FileModification()
{
Changes = new ObservableCollection<KeyValuePair<string, string>>();
}
}
}
Loading