[OOBE] Out of box experience window (#9973)

This commit is contained in:
Seraphima Zykova
2021-03-02 20:56:37 +03:00
committed by GitHub
parent a12350274b
commit 078aa3d89b
81 changed files with 2460 additions and 78 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -16,6 +16,8 @@ namespace PowerToys.Settings
// Interaction logic for MainWindow.xaml.
public partial class MainWindow : Window
{
private static Window inst;
private bool isOpen = true;
public MainWindow()
@@ -29,6 +31,23 @@ namespace PowerToys.Settings
PowerToysTelemetry.Log.WriteEvent(new SettingsBootEvent() { BootTimeMs = bootTime.ElapsedMilliseconds });
}
public static void CloseHiddenWindow()
{
if (inst != null && inst.Visibility == Visibility.Hidden)
{
inst.Close();
}
}
public void NavigateToSection(Type type)
{
if (inst != null)
{
Activate();
ShellPage.Navigate(type);
}
}
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)
{
// If sender is null, it could lead to a NullReferenceException. This might occur on restarting as admin (check https://github.com/microsoft/PowerToys/issues/7393 for details)
@@ -63,6 +82,13 @@ namespace PowerToys.Settings
Program.GetTwoWayIPCManager().Send(msg);
});
// open oobe
ShellPage.SetOpenOobeCallback(() =>
{
var oobe = new OobeWindow();
oobe.Show();
});
// receive IPC Message
Program.IPCMessageReceivedCallback = (string msg) =>
{
@@ -97,7 +123,15 @@ namespace PowerToys.Settings
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
isOpen = false;
if (OobeWindow.IsOpened)
{
e.Cancel = true;
((Window)sender).Hide();
}
else
{
isOpen = false;
}
// XAML Islands: If the window is closed while minimized, exit the process. Required to avoid process not terminating issue - https://github.com/microsoft/PowerToys/issues/4430
if (WindowState == WindowState.Minimized)
@@ -106,5 +140,18 @@ namespace PowerToys.Settings
System.Threading.Tasks.Task.Run(() => { Environment.Exit(0); });
}
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
inst = (Window)sender;
}
private void MainWindow_Activated(object sender, EventArgs e)
{
if (((Window)sender).Visibility == Visibility.Hidden)
{
((Window)sender).Visibility = Visibility.Visible;
}
}
}
}