Browse Source
* Make RemoteServer/RemoteWidget internal * Remote Previewer and RemoteDemo projects * Update API suppressionspull/20776/head
committed by
GitHub
13 changed files with 28 additions and 264 deletions
@ -1,5 +0,0 @@ |
|||
<Application xmlns="https://github.com/avaloniaui"> |
|||
<Application.Styles> |
|||
<SimpleTheme /> |
|||
</Application.Styles> |
|||
</Application> |
|||
@ -1,22 +0,0 @@ |
|||
using Avalonia; |
|||
using Avalonia.Controls.ApplicationLifetimes; |
|||
using Avalonia.Markup.Xaml; |
|||
|
|||
namespace Previewer |
|||
{ |
|||
public class App : Application |
|||
{ |
|||
public override void Initialize() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
|
|||
public override void OnFrameworkInitializationCompleted() |
|||
{ |
|||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) |
|||
desktop.MainWindow = new MainWindow(); |
|||
base.OnFrameworkInitializationCompleted(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
using Avalonia; |
|||
using Avalonia.Controls; |
|||
|
|||
namespace Previewer |
|||
{ |
|||
public class Center : Decorator |
|||
{ |
|||
protected override Size ArrangeOverride(Size finalSize) |
|||
{ |
|||
if (Child != null) |
|||
{ |
|||
var desired = Child.DesiredSize; |
|||
Child.Arrange(new Rect((finalSize.Width - desired.Width) / 2, (finalSize.Height - desired.Height) / 2, |
|||
desired.Width, desired.Height)); |
|||
} |
|||
return finalSize; |
|||
} |
|||
} |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
<Window xmlns="https://github.com/avaloniaui" Width="600" Height="500" |
|||
Title="Previewer"> |
|||
<Grid RowDefinitions="0.5*,200"> |
|||
<ScrollViewer Name="Remote"/> |
|||
|
|||
<ScrollViewer Name="ErrorsContainer" Background="#ffe0e0"> |
|||
<TextBlock Name="Errors"/> |
|||
</ScrollViewer> |
|||
<TextBox Grid.Row="1" AcceptsReturn="True" Name="Xaml"/> |
|||
</Grid> |
|||
|
|||
</Window> |
|||
@ -1,86 +0,0 @@ |
|||
using System; |
|||
using System.Net; |
|||
using Avalonia; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Controls.Remote; |
|||
using Avalonia.Markup.Xaml; |
|||
using Avalonia.Remote.Protocol; |
|||
using Avalonia.Remote.Protocol.Designer; |
|||
using Avalonia.Remote.Protocol.Viewport; |
|||
using Avalonia.Threading; |
|||
|
|||
namespace Previewer |
|||
{ |
|||
public class MainWindow : Window |
|||
{ |
|||
private const string InitialXaml = @"<Window xmlns=""https://github.com/avaloniaui"" Width=""600"" Height=""500"">
|
|||
<TextBlock>Hello world!</TextBlock> |
|||
|
|||
</Window>";
|
|||
private IAvaloniaRemoteTransportConnection? _connection; |
|||
private Control _errorsContainer; |
|||
private TextBlock _errors; |
|||
private RemoteWidget? _remote; |
|||
|
|||
|
|||
public MainWindow() |
|||
{ |
|||
this.InitializeComponent(); |
|||
var tb = this.GetControl<TextBox>("Xaml"); |
|||
tb.Text = InitialXaml; |
|||
var scroll = this.GetControl<ScrollViewer>("Remote"); |
|||
var rem = new Center(); |
|||
scroll.Content = rem; |
|||
_errorsContainer = this.GetControl<Control>("ErrorsContainer"); |
|||
_errors = this.GetControl<TextBlock>("Errors"); |
|||
tb.GetObservable(TextBox.TextProperty).Subscribe(text => _connection?.Send(new UpdateXamlMessage |
|||
{ |
|||
Xaml = text |
|||
})); |
|||
new BsonTcpTransport().Listen(IPAddress.Loopback, 25000, t => |
|||
{ |
|||
Dispatcher.UIThread.Post(() => |
|||
{ |
|||
if (_connection != null) |
|||
{ |
|||
_connection.Dispose(); |
|||
_connection.OnMessage -= OnMessage; |
|||
} |
|||
_connection = t; |
|||
rem.Child = _remote = new RemoteWidget(t); |
|||
t.Send(new UpdateXamlMessage |
|||
{ |
|||
Xaml = tb.Text |
|||
}); |
|||
|
|||
t.OnMessage += OnMessage; |
|||
}); |
|||
}); |
|||
Title = "Listening on 127.0.0.1:25000"; |
|||
} |
|||
|
|||
private void OnMessage(IAvaloniaRemoteTransportConnection transport, object obj) |
|||
{ |
|||
Dispatcher.UIThread.Post(() => |
|||
{ |
|||
if (transport != _connection) |
|||
return; |
|||
if (obj is UpdateXamlResultMessage result) |
|||
{ |
|||
_errorsContainer.IsVisible = result.Error != null; |
|||
_errors.Text = result.Error ?? ""; |
|||
} |
|||
if (obj is RequestViewportResizeMessage resize && _remote is not null) |
|||
{ |
|||
_remote.Width = Math.Min(4096, Math.Max(resize.Width, 1)); |
|||
_remote.Height = Math.Min(4096, Math.Max(resize.Height, 1)); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Compile Update="**\*.xaml.cs"> |
|||
<DependentUpon>%(Filename)</DependentUpon> |
|||
</Compile> |
|||
<EmbeddedResource Include="**\*.xaml" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Avalonia.Fonts.Inter\Avalonia.Fonts.Inter.csproj" /> |
|||
<ProjectReference Include="..\..\src\Avalonia.Themes.Simple\Avalonia.Themes.Simple.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="System.Reactive" /> |
|||
</ItemGroup> |
|||
<Import Project="..\..\build\SampleApp.props" /> |
|||
<Import Project="..\..\build\ReferenceCoreLibraries.props" /> |
|||
</Project> |
|||
@ -1,14 +0,0 @@ |
|||
using Avalonia; |
|||
|
|||
namespace Previewer |
|||
{ |
|||
class Program |
|||
{ |
|||
public static AppBuilder BuildAvaloniaApp() |
|||
=> AppBuilder.Configure<App>() |
|||
.UsePlatformDetect(); |
|||
|
|||
public static int Main(string[] args) |
|||
=> BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); |
|||
} |
|||
} |
|||
@ -1,53 +0,0 @@ |
|||
using System; |
|||
using System.Net; |
|||
using System.Net.Sockets; |
|||
using System.Threading; |
|||
using Avalonia; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Controls.Remote; |
|||
using Avalonia.Remote.Protocol; |
|||
using Avalonia.Threading; |
|||
using ControlCatalog; |
|||
|
|||
namespace RemoteDemo |
|||
{ |
|||
class Program |
|||
{ |
|||
static void Main(string[] args) |
|||
{ |
|||
AppBuilder.Configure<App>().UsePlatformDetect().SetupWithoutStarting(); |
|||
|
|||
var l = new TcpListener(IPAddress.Loopback, 0); |
|||
l.Start(); |
|||
var port = ((IPEndPoint) l.LocalEndpoint).Port; |
|||
l.Stop(); |
|||
|
|||
var transport = new BsonTcpTransport(); |
|||
transport.Listen(IPAddress.Loopback, port, sc => |
|||
{ |
|||
Dispatcher.UIThread.Post(() => |
|||
{ |
|||
new RemoteServer(sc).Content = new MainView(); |
|||
}); |
|||
}); |
|||
|
|||
var cts = new CancellationTokenSource(); |
|||
transport.Connect(IPAddress.Loopback, port).ContinueWith(t => |
|||
{ |
|||
Dispatcher.UIThread.Post(() => |
|||
{ |
|||
var window = new Window() |
|||
{ |
|||
Content = new RemoteWidget(t.Result) |
|||
}; |
|||
window.Closed += delegate { cts.Cancel(); }; |
|||
window.Show(); |
|||
}); |
|||
}); |
|||
Dispatcher.UIThread.MainLoop(cts.Token); |
|||
|
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>$(AvsCurrentTargetFramework)</TargetFramework> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\ControlCatalog\ControlCatalog.csproj" /> |
|||
</ItemGroup> |
|||
<Import Project="..\..\build\SampleApp.props" /> |
|||
<Import Project="..\..\build\ReferenceCoreLibraries.props" /> |
|||
<Import Project="..\..\build\BuildTargets.targets" /> |
|||
</Project> |
|||
Loading…
Reference in new issue