mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-24 20:06:54 +00:00
52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using Avalonia;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.ReactiveUI;
|
|
|
|
namespace v2rayN.Desktop.Base;
|
|
|
|
public class WindowBase<TViewModel> : ReactiveWindow<TViewModel> where TViewModel : class
|
|
{
|
|
public WindowBase()
|
|
{
|
|
Loaded += OnLoaded;
|
|
}
|
|
|
|
private void ReactiveWindowBase_Closed(object? sender, EventArgs e)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
protected virtual void OnLoaded(object? sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var sizeItem = ConfigHandler.GetWindowSizeItem(AppHandler.Instance.Config, GetType().Name);
|
|
if (sizeItem == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Width = sizeItem.Width;
|
|
Height = sizeItem.Height;
|
|
|
|
var workingArea = (Screens.ScreenFromWindow(this) ?? Screens.Primary).WorkingArea;
|
|
var scaling = (Utils.IsOSX() ? null : VisualRoot?.RenderScaling) ?? 1.0;
|
|
|
|
var x = workingArea.X + ((workingArea.Width - (Width * scaling)) / 2);
|
|
var y = workingArea.Y + ((workingArea.Height - (Height * scaling)) / 2);
|
|
|
|
Position = new PixelPoint((int)x, (int)y);
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
protected override void OnClosed(EventArgs e)
|
|
{
|
|
base.OnClosed(e);
|
|
try
|
|
{
|
|
ConfigHandler.SaveWindowSizeItem(AppHandler.Instance.Config, GetType().Name, Width, Height);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|