Skip to content

Commit

Permalink
fix: warnings and IsAotCompatible
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Nov 13, 2024
1 parent fa48752 commit 7b923bd
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/[email protected]
with:
dotnet-version: "8.0.x"
dotnet-version: "9.0.x"
- name: Build
run: |
dotnet workload restore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup .NET Core
uses: actions/[email protected]
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'
- name: Install dependencies
run: |
dotnet workload restore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<PropertyGroup>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Authors>bandysc</Authors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<PropertyGroup>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Authors>bandysc</Authors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<PropertyGroup>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Authors>bandysc</Authors>
Expand Down
23 changes: 13 additions & 10 deletions src/Classic.Avalonia.Theme/BulletDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public IBrush? Background
/// It should be aligned to BulletDecorator.Child which is the second visual child.
/// </summary>
/// <value></value>
public Control Bullet
public Control? Bullet
{
get => _bullet;
set
Expand All @@ -117,12 +117,15 @@ public Control Bullet

_bullet = value;

LogicalChildren.Add(value);
// notify the visual layer about the new child.
VisualChildren.Add(value);
if (value != null)
{
LogicalChildren.Add(value);
// notify the visual layer about the new child.
VisualChildren.Add(value);
}

// If we decorator content exists we need to move it at the end of the visual tree
Control child = Child;
Control? child = Child;
if (child != null)
{
VisualChildren.Remove(child);
Expand Down Expand Up @@ -169,8 +172,8 @@ protected override Size MeasureOverride(Size constraint)
{
Size bulletSize = new Size();
Size contentSize = new Size();
Control bullet = Bullet;
Control content = Child;
Control? bullet = Bullet;
Control? content = Child;

// If we have bullet we should measure it first
if (bullet != null)
Expand Down Expand Up @@ -200,8 +203,8 @@ protected override Size MeasureOverride(Size constraint)
/// <param name="arrangeSize">Size that BulletDecorator will assume to position children.</param>
protected override Size ArrangeOverride(Size arrangeSize)
{
Control bullet = Bullet;
Control content = Child;
Control? bullet = Bullet;
Control? content = Child;
double contentOffsetX = 0;

double bulletOffsetY = 0;
Expand Down Expand Up @@ -376,7 +379,7 @@ private double GetFirstLineHeight(Control element)
//-------------------------------------------------------------------

#region Private Members
Control _bullet = null;
Control? _bullet = null;
#endregion Private Members

}
6 changes: 5 additions & 1 deletion src/Classic.Avalonia.Theme/Classic.Avalonia.Theme.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<PropertyGroup>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Authors>bandysc</Authors>
Expand Down
9 changes: 6 additions & 3 deletions src/Classic.Avalonia.Theme/ClassicBorderDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ public static IBrush ClassicBorderBrush
/// <summary>
/// AvaloniaProperty for <see cref="BorderBrush" /> property.
/// </summary>
public static readonly StyledProperty<IBrush> BorderBrushProperty =
AvaloniaProperty.Register<ClassicBorderDecorator, IBrush>(
public static readonly StyledProperty<IBrush?> BorderBrushProperty =
AvaloniaProperty.Register<ClassicBorderDecorator, IBrush?>(
nameof(BorderBrush),
ClassicBorderBrush);

Expand Down Expand Up @@ -1266,6 +1266,9 @@ private MatrixTransform GetTabTransform(ClassicBorderStyle style, double xOffset
case ClassicBorderStyle.TabBottom:
_tabCache.Transform = new MatrixTransform(new Matrix(-1.0, 0.0, 0.0, -1.0, xOffset, yOffset));
break;
default:
_tabCache.Transform = new MatrixTransform(Matrix.Identity);
break;
}
_tabCache.xOffset = xOffset;
_tabCache.yOffset = yOffset;
Expand Down Expand Up @@ -1419,7 +1422,7 @@ private void DrawRadioButtonBorder(DrawingContext dc, ref Rect bounds)

private T GetResourceOrDefault<T>(object key, T defaultValue)
{
if (Application.Current.TryGetResource(key, out var res))
if (Application.Current!.TryGetResource(key, out var res))
if (res is T resT)
return resT;
return defaultValue;
Expand Down
2 changes: 1 addition & 1 deletion src/Classic.Avalonia.Theme/ClassicWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public ClassicWindow()
}
}

private void OnActivated(object sender, EventArgs e)
private void OnActivated(object? sender, EventArgs e)
{
// Fix for macOS: enable resizing despite SystemDecorations = None
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && CanResize)
Expand Down
12 changes: 6 additions & 6 deletions src/Classic.Avalonia.Theme/Converters/BorderGapMaskConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ internal class BorderGapMaskConverter : IMultiValueConverter
values[0] == null ||
values[1] == null ||
values[2] == null ||
!doubleType.IsAssignableFrom(values[0].GetType()) ||
!doubleType.IsAssignableFrom(values[1].GetType()) ||
!doubleType.IsAssignableFrom(values[2].GetType()) )
!doubleType.IsInstanceOfType(values[0]) ||
!doubleType.IsInstanceOfType(values[1]) ||
!doubleType.IsInstanceOfType(values[2]) )
{
return AvaloniaProperty.UnsetValue;
}
Expand All @@ -42,9 +42,9 @@ internal class BorderGapMaskConverter : IMultiValueConverter
// Conversion
//

double headerWidth = (double)values[0];
double borderWidth = (double)values[1];
double borderHeight = (double)values[2];
double headerWidth = (double?)values[0] ?? 0;
double borderWidth = (double?)values[1] ?? 0;
double borderHeight = (double?)values[2] ?? 0;

// Doesn't make sense to have a Grid
// with 0 as width or height
Expand Down
20 changes: 10 additions & 10 deletions src/Classic.Avalonia.Theme/Converters/ProgressBarBrushConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ internal class ProgressBarBrushConverter : IMultiValueConverter
(values[2] == null) ||
(values[3] == null) ||
(values[4] == null) ||
!typeof(IBrush).IsAssignableFrom(values[0].GetType()) ||
!typeof(bool).IsAssignableFrom(values[1].GetType()) ||
!doubleType.IsAssignableFrom(values[2].GetType()) ||
!doubleType.IsAssignableFrom(values[3].GetType()) ||
!doubleType.IsAssignableFrom(values[4].GetType()))
values[0] is not IBrush ||
values[1] is not bool ||
!doubleType.IsInstanceOfType(values[2]) ||
!doubleType.IsInstanceOfType(values[3]) ||
!doubleType.IsInstanceOfType(values[4]))
{
return null;
}
Expand All @@ -39,11 +39,11 @@ internal class ProgressBarBrushConverter : IMultiValueConverter
// Conversion
//

IBrush brush = (Brush)values[0];
bool isIndeterminate = (bool)values[1];
double width = (double)values[2];
double height = (double)values[3];
double trackWidth = (double)values[4];
IBrush brush = (Brush)values[0]!;
bool isIndeterminate = (bool)values[1]!;
double width = (double)values[2]!;
double height = (double)values[3]!;
double trackWidth = (double)values[4]!;

// if an invalid height, return a null brush
if (width <= 0.0 || Double.IsInfinity(width) || Double.IsNaN(width) ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Skia" Version="$(AvaloniaVersion)" />
Expand Down
26 changes: 13 additions & 13 deletions src/Classic.CommonControls.Avalonia/Dialogs/About/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ private MemoryMetrics GetWindowsMetrics()

using(var process = Process.Start(info))
{
output = process.StandardOutput.ReadToEnd();
output = process?.StandardOutput.ReadToEnd();
}

var lines = output.Trim().Split('\n');
var freeMemoryParts = lines[0].Split(['='], StringSplitOptions.RemoveEmptyEntries);
var totalMemoryParts = lines[1].Split(['='], StringSplitOptions.RemoveEmptyEntries);
var lines = output?.Trim().Split('\n');
var freeMemoryParts = lines?[0].Split(['='], StringSplitOptions.RemoveEmptyEntries);
var totalMemoryParts = lines?[1].Split(['='], StringSplitOptions.RemoveEmptyEntries);

var metrics = new MemoryMetrics();
metrics.Total = Math.Round(double.Parse(totalMemoryParts[1]) / 1024, 0);
metrics.Free = Math.Round(double.Parse(freeMemoryParts[1]) / 1024, 0);
metrics.Total = Math.Round(double.Parse(totalMemoryParts?[1] ?? "0") / 1024, 0);
metrics.Free = Math.Round(double.Parse(freeMemoryParts?[1] ?? "0") / 1024, 0);
metrics.Used = metrics.Total - metrics.Free;

return metrics;
Expand All @@ -71,13 +71,13 @@ private MemoryMetrics GetMacOsMetrics()

using(var process = Process.Start(info))
{
output = process.StandardOutput.ReadToEnd();
output = process?.StandardOutput.ReadToEnd();
}

var memory = output.Split([' '], StringSplitOptions.RemoveEmptyEntries);
var memory = output?.Split([' '], StringSplitOptions.RemoveEmptyEntries);

var metrics = new MemoryMetrics();
metrics.Total = double.Parse(memory[1]);
metrics.Total = double.Parse(memory?[1] ?? "0");

return metrics;
}
Expand All @@ -94,14 +94,14 @@ private MemoryMetrics GetLinuxMetrics()

using(var process = Process.Start(info))
{
output = process.StandardOutput.ReadToEnd();
output = process?.StandardOutput.ReadToEnd();
}

var lines = output.Split('\n');
var memory = lines[1].Split([' '], StringSplitOptions.RemoveEmptyEntries);
var lines = output?.Split('\n');
var memory = lines?[1].Split([' '], StringSplitOptions.RemoveEmptyEntries);

var metrics = new MemoryMetrics();
metrics.Total = double.Parse(memory[1]);
metrics.Total = double.Parse(memory?[1] ?? "0");

return metrics;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public class FontDialogViewModel : INotifyPropertyChanged
public ObservableCollection<LegacyFontStyle> FontStyles { get; } = new();
public List<double> FontSizes { get; } = new() { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };

private FontFamily selectedFont;
public FontFamily SelectedFont
private FontFamily? selectedFont;
public FontFamily? SelectedFont
{
get => selectedFont;
set
{
SetField(ref selectedFont, value);
SetField(ref fontNameText, value.Name, nameof(FontNameText));
SetField(ref fontNameText, value?.Name, nameof(FontNameText));
UpdateFontStyles();
}
}
Expand All @@ -37,8 +37,8 @@ public double SelectedFontSize
set => SetField(ref selectedFontSize, value);
}

private string fontNameText;
public string FontNameText
private string? fontNameText;
public string? FontNameText
{
get => fontNameText;
set
Expand Down Expand Up @@ -68,14 +68,17 @@ public FontDialogViewModel(FontDialogResult? initial) : this()
if (initial == null)
return;

selectedFont = Fonts.FirstOrDefault(x => x == initial.Family);
selectedFont = Fonts.FirstOrDefault(x => x == initial.Family) ?? Fonts.FirstOrDefault();
UpdateFontStyles();
selectedFontSize = initial.Size;
selectedFontStyle = FontStyles.FirstOrDefault(x => x.FontWeight == initial.Weight && x.FontStyle == initial.Style);
}

public void Accept()
{
if (SelectedFont == null)
return;

AcceptRequested?.Invoke(
new FontDialogResult(SelectedFont,
SelectedFontStyle?.FontStyle ?? FontStyle.Normal,
Expand Down Expand Up @@ -108,6 +111,9 @@ public void Cancel()
private void UpdateFontStyles()
{
FontStyles.Clear();
if (selectedFont == null)
return;

foreach (var style in styles)
{
foreach (var weight in weights)
Expand Down
Loading

0 comments on commit 7b923bd

Please sign in to comment.