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 f8d33dc
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 65 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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AvaloniaVersion>11.2.0</AvaloniaVersion>
<ClassicAvaloniaVersion>11.2.0.4</ClassicAvaloniaVersion>
<ClassicAvaloniaVersion>11.2.0.5</ClassicAvaloniaVersion>
<DockVersion>11.2.0</DockVersion>
</PropertyGroup>
</Project>
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
15 changes: 9 additions & 6 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 @@ -1211,7 +1211,7 @@ private Geometry GetHighlight1(Rect bounds)
private Geometry GetShadow1(Rect bounds)
{
// Assumed to always be called after GetHighlight1
Debug.Assert(_tabCache != null, "_tabCache is null. GetShadow1 should only be called after GetHighlight1");
_tabCache = _tabCache ?? throw new Exception("_tabCache is null. GetShadow1 should only be called after GetHighlight1");

if (_tabCache.Shadow1 == null)
{
Expand All @@ -1224,7 +1224,7 @@ private Geometry GetShadow1(Rect bounds)
private Geometry GetHighlight2(Rect bounds)
{
// Assumed to always be called after GetHighlight1
Debug.Assert(_tabCache != null, "_tabCache is null. GetHighlight2 should only be called after GetHighlight1");
_tabCache = _tabCache ?? throw new Exception("_tabCache is null. GetHighlight2 should only be called after GetHighlight1");

if (_tabCache.Highlight2 == null)
{
Expand All @@ -1237,7 +1237,7 @@ private Geometry GetHighlight2(Rect bounds)
private Geometry GetShadow2(Rect bounds)
{
// Assumed to always be called after GetHighlight1
Debug.Assert(_tabCache != null, "_tabCache is null. GetHighlight2 should only be called after GetHighlight1");
_tabCache = _tabCache ?? throw new Exception("_tabCache is null. GetHighlight2 should only be called after GetHighlight1");

if (_tabCache.Shadow2 == null)
{
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
4 changes: 2 additions & 2 deletions src/Classic.CommonControls.Avalonia/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class AppBuilderExtensions
{
public static AppBuilder UseMessageBoxSounds(this AppBuilder builder)
{
string? tempChimeFileName = null;
//string? tempChimeFileName = null;
string? tempChordFileName = null;
string? tempDingFileName = null;

Expand Down Expand Up @@ -38,7 +38,7 @@ public static AppBuilder UseMessageBoxSounds(this AppBuilder builder)
if (resourceStream != null)
{
var array = new byte[resourceStream.Length];
resourceStream.Read(array, 0, array.Length);
int read = resourceStream.Read(array, 0, array.Length);
fileName = Path.GetTempFileName();
File.WriteAllBytes(fileName, array);
if (msgBox.Icon is MessageBoxIcon.Error or MessageBoxIcon.Warning)
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
Loading

0 comments on commit f8d33dc

Please sign in to comment.