Window Size

* Preserve window size when swapping Fluent and Simple themes.
* Simplify test batch files.
* Trim output.
* Different output type depending on the configuration.
This commit is contained in:
Joseph Moreno 2023-02-10 13:11:58 -05:00
parent cd2a9d72aa
commit dcc47c332f
9 changed files with 49 additions and 20 deletions

View File

@ -2,23 +2,29 @@
<PropertyGroup>
<!-- if you want to check exceptions, change this to "Exe" and start your app from the console -->
<OutputType>WinExe</OutputType>
<OutputType Condition="'$(Configuration.toUpper())' != 'DEBUG'">WinExe</OutputType>
<OutputType Condition="'$(Configuration.toUpper())' == 'DEBUG'">Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Platforms>x64</Platforms>
<ApplicationIcon>Assets/app.ico</ApplicationIcon>
<InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>true</PublishAot>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<PublishTrimmed>true</PublishTrimmed>
<SelfContained>true</SelfContained>
</PropertyGroup>
<PropertyGroup>
<IsWindows Condition="$([MSBuild]::IsOSPlatform('Windows'))">true</IsWindows>
<IsLinux Condition="$([MSBuild]::IsOSPlatform('Linux'))">true</IsLinux>
<IsOSX Condition="$([MSBuild]::IsOSPlatform('OSX'))">true</IsOSX>
</PropertyGroup>
<PropertyGroup>
<!--Tthese can help when debugging weird exceptions especially when reflection is involved. See https://github.com/dotnet/corert/blob/master/Documentation/using-corert/optimizing-corert.md -->
<TrimMode>link</TrimMode>
<!--These can help when debugging weird exceptions especially when reflection is involved. See https://github.com/dotnet/corert/blob/master/Documentation/using-corert/optimizing-corert.md -->
<!--RootAllApplicationAssemblies: False -> TrimMode:link See https://github.com/dotnet/runtimelab/issues/597 and https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/docs/using-nativeaot/optimizing.md -->
<IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>
<IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>
<IlcGenerateStackTraceData Condition="'$(Configuration.toUpper())' != 'DEBUG'">false</IlcGenerateStackTraceData>
<IlcDisableUnhandledExceptionExperience>true</IlcDisableUnhandledExceptionExperience>
<StripSymbols>true</StripSymbols>
</PropertyGroup>
@ -37,6 +43,7 @@
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<RuntimeHostConfigurationOption Include="Switch.System.Reflection.Assembly.SimulatedCallingAssembly" Value="true" />
</ItemGroup>
<ItemGroup>
@ -49,7 +56,7 @@
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0-*" />
<!--Condition below is needed to generate macOS App only.-->
<PackageReference Include="Dotnet.Bundle" Version="*" Condition="$(RuntimeIdentifier.StartsWith('osx'))" />
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" Condition="$(RuntimeIdentifier.StartsWith('osx'))" />
</ItemGroup>
<!-- Information for Dotnet.Bundle to Generate macOS app-->

View File

@ -18,10 +18,9 @@ namespace AvaloniaCoreRTDemo.Controls
this.DataContext = new MainControlViewModel();
}
public void Reload(IMainWindowState? model)
public void Reload(IMainWindowState model)
{
if (model is not null)
this.DataContext = new MainControlViewModel(model);
this.DataContext = new MainControlViewModel(model);
}
}
}

View File

@ -1,8 +1,15 @@
namespace AvaloniaCoreRTDemo.Interfaces
using Avalonia;
using Avalonia.Controls;
namespace AvaloniaCoreRTDemo.Interfaces
{
public interface IMainWindow
{
IThemeSwitch ThemeSwitch { get; }
IMainWindowState Model { get; }
PixelPoint Position { get; }
Size ClientSize { get; }
Size? FrameSize { get; }
WindowState State { get; }
}
}

View File

@ -10,20 +10,23 @@ namespace AvaloniaCoreRTDemo.Windows
{
public sealed partial class AboutWindow : Window
{
private readonly Boolean _darkTheme;
public AboutWindow() : this(false) { }
public AboutWindow(Boolean darkTheme)
{
this.InitializeComponent(darkTheme);
this._darkTheme = darkTheme;
this.InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
private void InitializeComponent(Boolean darkTheme = default)
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
this.DataContext = new AboutViewModel(darkTheme);
this.DataContext = new AboutViewModel(this._darkTheme);
}
}
}

View File

@ -7,7 +7,7 @@
x:DataType="viewModels1:ApplicationModelBase">
<DockPanel>
<NativeMenuBar DockPanel.Dock="Top" />
<controls:MainControl Name="mainControl"/>
<controls:MainControl Name="MainControl"/>
</DockPanel>
<NativeMenu.Menu>
<NativeMenu>

View File

@ -12,6 +12,8 @@ namespace AvaloniaCoreRTDemo.Windows
{
private readonly Application? _app = App.Current;
private MainControl MainControl => this.GetControl<MainControl>("MainControl");
public MainWindow() : this(default) { }
public MainWindow(IMainWindow? window)
{
@ -21,14 +23,25 @@ namespace AvaloniaCoreRTDemo.Windows
#endif
}
IThemeSwitch IMainWindow.ThemeSwitch => (this._app as IThemeSwitch)!;
IMainWindowState IMainWindow.Model => (this.GetControl<MainControl>("mainControl")!.DataContext as IMainWindowState)!;
IThemeSwitch IMainWindow.ThemeSwitch => (IThemeSwitch)this._app!;
IMainWindowState IMainWindow.Model => (IMainWindowState)this.MainControl.DataContext!;
PixelPoint IMainWindow.Position => this.Position;
Size IMainWindow.ClientSize => this.ClientSize;
Size? IMainWindow.FrameSize => this.FrameSize;
WindowState IMainWindow.State => this.WindowState;
private void InitializeComponent(IMainWindow? window)
{
AvaloniaXamlLoader.Load(this);
this.DataContext = new MainViewModel<MainWindow>(this);
this.GetControl<MainControl>("mainControl").Reload(window?.Model);
if(window is not null)
{
this.MainControl.Reload(window.Model);
this.WindowState = window.State;
this.Position = window.Position;
this.FrameSize = window.FrameSize;
this.ClientSize = window.ClientSize;
}
}
}
}

View File

@ -1,2 +1,2 @@
del src\packages.lock.json
dotnet publish -r win-x64 -c release /p:RestoreLockedMode=true /p:TrimLink=true --self-contained
dotnet publish -r win-x64 -c Release /p:RestoreLockedMode=true

View File

@ -4,7 +4,7 @@ if [ -d "$dir" ]; then
cd "$dir"
fi
rm -f src/packages.lock.json
dotnet publish -r osx-x64 -c release /p:RestoreLockedMode=true -t:BundleApp /p:TrimLink=true --self-contained
dotnet publish -r osx-x64 -c Release /p:RestoreLockedMode=true -t:BundleApp
rm -rf src/bin/x64/Release/net7.0/osx-x64/publish/Assets/
rm -rf src/bin/x64/Release/net7.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/Assets/
rm src/bin/x64/Release/net7.0/osx-x64/publish/AvaloniaCoreRTDemo.app/Contents/MacOS/AvaloniaCoreRTDemo.dwarf

View File

@ -1,6 +1,6 @@
#!/bin/bash
rm -f src/packages.lock.json
dotnet publish -r linux-x64 -c release /p:RestoreLockedMode=true /p:TrimLink=true --self-contained
dotnet publish -r linux-x64 -c Release /p:RestoreLockedMode=true
cd src/bin/x64/Release/net7.0/linux-x64/publish
cp AvaloniaCoreRTDemo AvaloniaCoreRTDemo.bin
strip AvaloniaCoreRTDemo.bin