Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Upgrade to Avalonia 11.0 + add Browser project #645

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions MSBuildStructuredLog.Avalonia.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TaskRunner", "src\TaskRunne
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StructuredLogViewer.Core", "src\StructuredLogViewer.Core\StructuredLogViewer.Core.csproj", "{3C655C5D-22C3-4B8D-969C-3FC497294703}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructuredLogViewer.Avalonia.Desktop", "src\StructuredLogViewer.Avalonia.Desktop\StructuredLogViewer.Avalonia.Desktop.csproj", "{4143B4F2-1FC3-469C-A91C-2721705820AC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructuredLogViewer.Avalonia.Browser", "src\StructuredLogViewer.Avalonia.Browser\StructuredLogViewer.Avalonia.Browser.csproj", "{95215092-37BB-4ED1-91D4-A96535508C12}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
Expand All @@ -48,6 +52,14 @@ Global
{B8DB3798-1636-417D-B57A-25C51C574F1E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{B8DB3798-1636-417D-B57A-25C51C574F1E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{B8DB3798-1636-417D-B57A-25C51C574F1E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{4143B4F2-1FC3-469C-A91C-2721705820AC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{4143B4F2-1FC3-469C-A91C-2721705820AC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{4143B4F2-1FC3-469C-A91C-2721705820AC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{4143B4F2-1FC3-469C-A91C-2721705820AC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{95215092-37BB-4ED1-91D4-A96535508C12}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{95215092-37BB-4ED1-91D4-A96535508C12}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{95215092-37BB-4ED1-91D4-A96535508C12}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{95215092-37BB-4ED1-91D4-A96535508C12}.Release|Mixed Platforms.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 5 additions & 0 deletions src/StructuredLogViewer.Avalonia.Browser/AppBundle/Logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions src/StructuredLogViewer.Avalonia.Browser/AppBundle/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* HTML styles for the splash screen */

.highlight {
color: white;
font-size: 2.5rem;
display: block;
}

.purple {
color: #8b44ac;
}

.icon {
opacity: 0.05;
height: 35%;
width: 35%;
position: absolute;
background-repeat: no-repeat;
right: 0px;
bottom: 0px;
margin-right: 3%;
margin-bottom: 5%;
z-index: 5000;
background-position: right bottom;
pointer-events: none;
}

#avalonia-splash a {
color: whitesmoke;
text-decoration: none;
}

.center {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

#avalonia-splash {
position: relative;
height: 100%;
width: 100%;
color: whitesmoke;
background: #1b2a4e;
font-family: 'Nunito', sans-serif;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
justify-content: center;
align-items: center;
}

.splash-close {
animation: fadeout 0.25s linear forwards;
}

@keyframes fadeout {
0% {
opacity: 100%;
}

100% {
opacity: 0;
visibility: collapse;
}
}
Binary file not shown.
31 changes: 31 additions & 0 deletions src/StructuredLogViewer.Avalonia.Browser/AppBundle/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>

<head>
<title>AvaloniaTest.Web</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<base href="/" />
<link rel="modulepreload" href="./main.js" />
<link rel="modulepreload" href="./dotnet.js" />
<link rel="modulepreload" href="./avalonia.js" />
<link rel="stylesheet" href="./app.css" />
<link rel="preconnect" href="https://fonts.googleapis.com">
</head>

<body style="margin: 0px; overflow: hidden">
<div id="out">
<div id="avalonia-splash">
<div class="center">
<h2 class="purple">
Powered by
<a class="highlight" href="https://www.avaloniaui.net/" target="_blank">Avalonia UI</a>
</h2>
</div>
<img class="icon" src="Logo.svg" alt="Avalonia Logo" />
</div>
</div>
<script type='module' src="./main.js"></script>
</body>

</html>
16 changes: 16 additions & 0 deletions src/StructuredLogViewer.Avalonia.Browser/AppBundle/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dotnet } from './dotnet.js'
import { registerAvaloniaModule } from './avalonia.js';

const is_browser = typeof window != "undefined";
if (!is_browser) throw new Error(`Expected to be running in a browser`);

const dotnetRuntime = await dotnet
.withDiagnosticTracing(false)
.withApplicationArgumentsFromQuery()
.create();

await registerAvaloniaModule(dotnetRuntime);

const config = dotnetRuntime.getConfig();

await dotnetRuntime.runMainAndExit(config.mainAssemblyName, [window.location.search]);
15 changes: 15 additions & 0 deletions src/StructuredLogViewer.Avalonia.Browser/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Runtime.Versioning;
using Avalonia;
using Avalonia.Web;
using StructuredLogViewer.Avalonia;

[assembly: SupportedOSPlatform("browser")]

internal partial class Program
{
private static void Main(string[] args) => BuildAvaloniaApp()
.SetupBrowserApp("out");

public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<WasmMainJSPath>AppBundle\main.js</WasmMainJSPath>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<WasmExtraFilesToDeploy Include="AppBundle\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia.Web" Version="11.0-preview4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\StructuredLogViewer.Avalonia\StructuredLogViewer.Avalonia.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"wasmHostProperties": {
"perHostConfig": [
{
"name": "browser",
"html-path": "index.html",
"Host": "browser"
}
]
}
}
20 changes: 20 additions & 0 deletions src/StructuredLogViewer.Avalonia.Desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Avalonia;
using System;

namespace StructuredLogViewer.Avalonia.Desktop;

class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="11.0-preview4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\StructuredLogViewer.Avalonia\StructuredLogViewer.Avalonia.csproj" />
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions src/StructuredLogViewer.Avalonia/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
</Application.Resources>

<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<SimpleTheme Mode="Light" />
<StyleInclude Source="avares://AvaloniaEdit/AvaloniaEdit.xaml" />
<StyleInclude Source="/Styles.xaml" />

Expand Down
2 changes: 2 additions & 0 deletions src/StructuredLogViewer.Avalonia/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = new MainWindow();
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
singleView.MainView = new MainView();

base.OnFrameworkInitializationCompleted();
}
Expand Down
49 changes: 5 additions & 44 deletions src/StructuredLogViewer.Avalonia/Avalonia.rd.xml
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
<Directives>
<Application>
<!-- these are needed when you show images and draw text -->
<!-- <Assembly Name="Avalonia.Animation" Dynamic="Required All"></Assembly> -->
<Assembly Name="Avalonia.Themes.Default" Dynamic="Required All"></Assembly>
<!-- <Assembly Name="Avalonia.Visuals" Dynamic="Required All"></Assembly>
<Assembly Name="SkiaSharp" Dynamic="Required All"></Assembly> -->

<!--
This is for opening files dialog
Tracked here https://github.com/AvaloniaUI/Avalonia/issues/7533
-->
<Assembly Name="Avalonia.X11" Dynamic="Required All">
<Type Name="Avalonia.X11.NativeDialogs.Gtk+signal_generic" MarshalDelegate="Required All" />
<Type Name="Avalonia.X11.NativeDialogs.Gtk+signal_dialog_response" MarshalDelegate="Required All" />
</Assembly>

<!-- Not known if and when you need these:
<Assembly Name="Avalonia.Controls" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Base" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Interactivity" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Layout" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Markup" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Markup.Xaml" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Styling" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.DesktopRuntime" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.DesignerSupport" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Diagnostics" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Dialogs" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Input" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Logging.Serilog" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.OpenGL" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Desktop" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Direct2D1" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.ReactiveUI" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Skia" Dynamic="Required All"></Assembly>
<Assembly Name="Avalonia.Win32" Dynamic="Required All"></Assembly>
<Assembly Name="ReactiveUI" Dynamic="Required All"></Assembly>
<Assembly Name="System.Reactive" Dynamic="Required All"></Assembly>
<Assembly Name="Splat" Dynamic="Required All"></Assembly>
-->
</Application>
</Directives>
<Directives>
maxkatz6 marked this conversation as resolved.
Show resolved Hide resolved
<Application>
<Assembly Name="Avalonia.Themes.Default" Dynamic="Required All"></Assembly>
</Application>
</Directives>
8 changes: 1 addition & 7 deletions src/StructuredLogViewer.Avalonia/AvaloniaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void RemoveItem(this ItemsControl itemsControl, object o)
{
(itemsControl.Items as IList)?.Remove(o);
}

public static void ClearItems(this ItemsControl itemsControl)
{
(itemsControl.Items as IList)?.Clear();
Expand All @@ -27,11 +27,5 @@ public static void RegisterControl<TControl>(this IControl parent, out TControl
{
control = parent.FindControl<TControl>(name);
}

public static async Task<string> ShowAndGetFileAsync(this OpenFileDialog dialog, Window window = null)
{
var result = await dialog.ShowAsync(window);
return result?.FirstOrDefault();
}
}
}
14 changes: 6 additions & 8 deletions src/StructuredLogViewer.Avalonia/Controls/BuildControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
using Avalonia.Styling;
using Avalonia.Data;
using Avalonia.Layout;
using Avalonia.Platform.Storage;

namespace StructuredLogViewer.Avalonia.Controls
{
public partial class BuildControl : UserControl
{
public Build Build { get; set; }
public TreeViewItem SelectedTreeViewItem { get; private set; }
public string LogFilePath { get; private set; }

private ScrollViewer scrollViewer;

Expand Down Expand Up @@ -61,7 +61,7 @@ public BuildControl()
{
}

public BuildControl(Build build, string logFilePath)
public BuildControl(Build build, IStorageFile logFile)
{
DataContext = build;

Expand All @@ -87,17 +87,15 @@ public BuildControl(Build build, string logFilePath)

Build = build;

LogFilePath = logFilePath;

if (build.SourceFilesArchive != null)
{
// first try to see if the source archive was embedded in the log
sourceFileResolver = new SourceFileResolver(build.SourceFiles.Values);
}
else
else if (logFile.TryGetUri(out var logFilePath) && logFilePath.IsAbsoluteUri && logFilePath.Scheme == "file")
{
// otherwise try to read from the .zip file on disk if present
sourceFileResolver = new SourceFileResolver(logFilePath);
sourceFileResolver = new SourceFileResolver(logFilePath.LocalPath);
}

sharedTreeContextMenu = new ContextMenu();
Expand Down Expand Up @@ -174,7 +172,7 @@ Style GetTreeViewItemStyle()
var text =
@"This log contains the full text of projects and imported files used during the build.
You can use the 'Files' tab in the bottom left to view these files and the 'Find in Files' tab for full-text search.
For many nodes in the tree (Targets, Tasks, Errors, Projects, etc) pressing SPACE or ENTER or double-clicking
For many nodes in the tree (Targets, Tasks, Errors, Projects, etc) pressing SPACE or ENTER or double-clicking
on the node will navigate to the corresponding source code associated with the node.

More functionality is available from the right-click context menu for each node.
Expand Down Expand Up @@ -649,7 +647,7 @@ private void BuildControl_Loaded(object sender, RoutedEventArgs e)
public void SelectItem(BaseNode item)
{
var parentChain = item.GetParentChainExcludingThis();

foreach (var node in parentChain)
{
if (node is TreeNode treeNode)
Expand Down
Loading