-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1105 from AvaloniaUI/remote2
Remoting & New Previewer
- Loading branch information
Showing
57 changed files
with
4,110 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,3 +175,4 @@ artifacts/ | |
nuget | ||
Avalonia.XBuild.sln | ||
project.lock.json | ||
.idea/* |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Application xmlns="https://github.com/avaloniaui"> | ||
<Application.Styles> | ||
<StyleInclude Source="resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"/> | ||
<StyleInclude Source="resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"/> | ||
</Application.Styles> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Avalonia; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace Previewer | ||
{ | ||
public class App : Application | ||
{ | ||
public override void Initialize() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
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.FindControl<TextBox>("Xaml"); | ||
tb.Text = InitialXaml; | ||
var scroll = this.FindControl<ScrollViewer>("Remote"); | ||
var rem = new Center(); | ||
scroll.Content = rem; | ||
_errorsContainer = this.FindControl<Control>("ErrorsContainer"); | ||
_errors = this.FindControl<TextBlock>("Errors"); | ||
tb.GetObservable(TextBox.TextProperty).Subscribe(text => _connection?.Send(new UpdateXamlMessage | ||
{ | ||
Xaml = text | ||
})); | ||
new BsonTcpTransport().Listen(IPAddress.Loopback, 25000, t => | ||
{ | ||
Dispatcher.UIThread.InvokeAsync(() => | ||
{ | ||
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.InvokeAsync(() => | ||
{ | ||
if (transport != _connection) | ||
return; | ||
if (obj is UpdateXamlResultMessage result) | ||
{ | ||
_errorsContainer.IsVisible = result.Error != null; | ||
_errors.Text = result.Error ?? ""; | ||
} | ||
if (obj is RequestViewportResizeMessage resize) | ||
{ | ||
_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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Update="**\*.xaml.cs"> | ||
<DependentUpon>%(Filename)</DependentUpon> | ||
</Compile> | ||
<EmbeddedResource Include="**\*.xaml" /> | ||
<ProjectReference Include="..\..\src\Avalonia.DotNetCoreRuntime\Avalonia.DotNetCoreRuntime.csproj" /> | ||
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj" /> | ||
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup\Avalonia.Markup.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Animation\Avalonia.Animation.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Base\Avalonia.Base.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Controls\Avalonia.Controls.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.HtmlRenderer\Avalonia.HtmlRenderer.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Input\Avalonia.Input.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Interactivity\Avalonia.Interactivity.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Layout\Avalonia.Layout.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.ReactiveUI\Avalonia.ReactiveUI.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Visuals\Avalonia.Visuals.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Styling\Avalonia.Styling.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using Avalonia; | ||
|
||
namespace Previewer | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
AppBuilder.Configure<App>().UsePlatformDetect().Start<MainWindow>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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 RemoteTest | ||
{ | ||
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.InvokeAsync(() => | ||
{ | ||
new RemoteServer(sc).Content = new MainView(); | ||
}); | ||
}); | ||
|
||
var cts = new CancellationTokenSource(); | ||
transport.Connect(IPAddress.Loopback, port).ContinueWith(t => | ||
{ | ||
Dispatcher.UIThread.InvokeAsync(() => | ||
{ | ||
var window = new Window() | ||
{ | ||
Content = new RemoteWidget(t.Result) | ||
}; | ||
window.Closed += delegate { cts.Cancel(); }; | ||
window.Show(); | ||
}); | ||
}); | ||
Dispatcher.UIThread.MainLoop(cts.Token); | ||
|
||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Avalonia.Animation\Avalonia.Animation.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Base\Avalonia.Base.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Controls\Avalonia.Controls.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.DesignerSupport\Avalonia.DesignerSupport.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.DotNetCoreRuntime\Avalonia.DotNetCoreRuntime.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Input\Avalonia.Input.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Interactivity\Avalonia.Interactivity.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Layout\Avalonia.Layout.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Styling\Avalonia.Styling.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Themes.Default\Avalonia.Themes.Default.csproj" /> | ||
<ProjectReference Include="..\..\src\Avalonia.Visuals\Avalonia.Visuals.csproj" /> | ||
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj" /> | ||
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup\Avalonia.Markup.csproj" /> | ||
<ProjectReference Include="..\ControlCatalog\ControlCatalog.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.