Files
FluentTerminal/FluentTerminal.App/Views/MainPage.xaml.cs
T
Felix 58e3ab9115 Use AppService for Commnunication instead of WebSocket (#55)
* Use AppService for Commnunication instead of WebSocket

* Code cleanup

* Some polishing

* Added some tests
2018-07-19 12:05:02 +02:00

95 lines
3.1 KiB
C#

using FluentTerminal.App.Utilities;
using FluentTerminal.App.ViewModels;
using System.ComponentModel;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace FluentTerminal.App.Views
{
public sealed partial class MainPage : Page, INotifyPropertyChanged
{
private readonly CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
public event PropertyChangedEventHandler PropertyChanged;
public double CoreTitleBarHeight => coreTitleBar.Height;
public Thickness CoreTitleBarPadding
{
get
{
if (FlowDirection == FlowDirection.LeftToRight)
{
return new Thickness { Left = coreTitleBar.SystemOverlayLeftInset, Right = coreTitleBar.SystemOverlayRightInset };
}
else
{
return new Thickness { Left = coreTitleBar.SystemOverlayRightInset, Right = coreTitleBar.SystemOverlayLeftInset };
}
}
}
public MainViewModel ViewModel { get; private set; }
public MainPage()
{
InitializeComponent();
Root.DataContext = this;
Window.Current.SetTitleBar(TitleBar);
Loaded += OnLoaded;
Unloaded += OnUnloaded;
Window.Current.Activated += OnWindowActivated;
RegisterPropertyChangedCallback(RequestedThemeProperty, (s, e) =>
{
ContrastHelper.SetTitleBarButtonsForTheme(RequestedTheme);
});
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Parameter is MainViewModel viewModel)
{
ViewModel = viewModel;
}
}
private async void OnWindowActivated(object sender, WindowActivatedEventArgs e)
{
if (e.WindowActivationState != CoreWindowActivationState.Deactivated && TerminalContainer.Content is TerminalView terminal)
{
await terminal.FocusWebView().ConfigureAwait(true);
}
}
private void OnUnloaded(object sender, RoutedEventArgs e)
{
coreTitleBar.LayoutMetricsChanged -= OnLayoutMetricsChanged;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
coreTitleBar.LayoutMetricsChanged += OnLayoutMetricsChanged;
UpdateLayoutMetrics();
}
private void OnLayoutMetricsChanged(CoreApplicationViewTitleBar sender, object e)
{
UpdateLayoutMetrics();
}
private void UpdateLayoutMetrics()
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CoreTitleBarHeight)));
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CoreTitleBarPadding)));
}
}
}
}