2024-04-26 19:41:44 +02:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2022-10-13 13:05:43 +02:00
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2025-03-18 21:52:24 +08:00
|
|
|
using System;
|
2022-10-13 13:05:43 +02:00
|
|
|
using Hosts.Helpers;
|
2025-03-18 21:52:24 +08:00
|
|
|
using HostsEditor.Telemetry;
|
2024-04-26 19:41:44 +02:00
|
|
|
using HostsUILib.Helpers;
|
|
|
|
|
using HostsUILib.Views;
|
2023-10-23 18:16:11 +02:00
|
|
|
using ManagedCommon;
|
2025-03-18 21:52:24 +08:00
|
|
|
using Microsoft.PowerToys.Telemetry;
|
2025-09-02 07:02:43 +02:00
|
|
|
using Microsoft.UI.Windowing;
|
2023-07-19 07:45:53 +02:00
|
|
|
using Microsoft.UI.Xaml;
|
2024-04-26 19:41:44 +02:00
|
|
|
using Microsoft.UI.Xaml.Controls;
|
2023-07-19 07:45:53 +02:00
|
|
|
using Microsoft.UI.Xaml.Media;
|
2024-04-26 19:41:44 +02:00
|
|
|
using Microsoft.Windows.ApplicationModel.Resources;
|
2022-10-13 13:05:43 +02:00
|
|
|
using WinUIEx;
|
|
|
|
|
|
|
|
|
|
namespace Hosts
|
|
|
|
|
{
|
|
|
|
|
public sealed partial class MainWindow : WindowEx
|
|
|
|
|
{
|
2024-04-26 19:41:44 +02:00
|
|
|
private HostsMainPage MainPage { get; }
|
|
|
|
|
|
2022-10-13 13:05:43 +02:00
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2023-07-19 07:45:53 +02:00
|
|
|
ExtendsContentIntoTitleBar = true;
|
|
|
|
|
SetTitleBar(titleBar);
|
2023-07-20 00:12:46 +01:00
|
|
|
AppWindow.SetIcon("Assets/Hosts/Hosts.ico");
|
2023-09-12 12:11:26 +02:00
|
|
|
|
2024-04-26 19:41:44 +02:00
|
|
|
var loader = new ResourceLoader("PowerToys.HostsUILib.pri", "PowerToys.HostsUILib/Resources");
|
|
|
|
|
|
|
|
|
|
var title = Host.GetService<IElevationHelper>().IsElevated ? loader.GetString("WindowAdminTitle") : loader.GetString("WindowTitle");
|
2023-09-12 12:11:26 +02:00
|
|
|
Title = title;
|
2025-09-02 07:02:43 +02:00
|
|
|
titleBar.Title = title;
|
2022-10-13 13:05:43 +02:00
|
|
|
|
2023-09-12 15:50:02 +02:00
|
|
|
var handle = this.GetWindowHandle();
|
2023-07-19 07:45:53 +02:00
|
|
|
|
2025-01-13 17:13:16 +02:00
|
|
|
WindowHelpers.ForceTopBorder1PixelInsetOnWindows10(handle);
|
2024-04-26 19:41:44 +02:00
|
|
|
WindowHelpers.BringToForeground(handle);
|
|
|
|
|
|
|
|
|
|
MainPage = Host.GetService<HostsMainPage>();
|
2025-03-18 21:52:24 +08:00
|
|
|
|
|
|
|
|
PowerToysTelemetry.Log.WriteEvent(new HostEditorStartFinishEvent() { TimeStamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
|
2022-10-13 13:05:43 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-26 19:41:44 +02:00
|
|
|
private void Grid_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MainGrid.Children.Add(MainPage);
|
|
|
|
|
Grid.SetRow(MainPage, 1);
|
|
|
|
|
}
|
2024-10-24 22:04:32 +02:00
|
|
|
|
|
|
|
|
private void WindowEx_Closed(object sender, WindowEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
(Application.Current as App).EtwTrace?.Dispose();
|
|
|
|
|
}
|
2022-10-13 13:05:43 +02:00
|
|
|
}
|
|
|
|
|
}
|