[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

@@ -40,6 +40,7 @@
#include <common/utils/winapi_error.h>
#include <common/version/version.h>
#include <common/utils/window.h>
#include <runner/settings_window.h>
extern updating::notifications::strings Strings;
@@ -77,12 +78,8 @@ void open_menu_from_another_instance()
PostMessageW(hwnd_main, WM_COMMAND, ID_SETTINGS_MENU_COMMAND, 0);
}
int runner(bool isProcessElevated, bool openSettings)
int runner(bool isProcessElevated, bool openSettings, bool openOobe)
{
std::filesystem::path logFilePath(PTSettingsHelper::get_root_save_folder_location());
logFilePath.append(LogSettings::runnerLogPath);
Logger::init(LogSettings::runnerLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location());
Logger::info("Runner is starting. Elevated={}", isProcessElevated);
DPIAware::EnableDPIAwarenessForThisProcess();
@@ -161,6 +158,11 @@ int runner(bool isProcessElevated, bool openSettings)
open_settings_window();
}
if (openOobe)
{
open_oobe_window();
}
result = run_message_loop();
}
catch (std::runtime_error& err)
@@ -336,6 +338,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
break;
}
std::filesystem::path logFilePath(PTSettingsHelper::get_root_save_folder_location());
logFilePath.append(LogSettings::runnerLogPath);
Logger::init(LogSettings::runnerLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location());
wil::unique_mutex_nothrow msi_mutex;
wil::unique_mutex_nothrow msix_mutex;
@@ -401,6 +407,20 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
}
bool openOobe = false;
try
{
openOobe = !PTSettingsHelper::get_oobe_opened_state();
if (openOobe)
{
PTSettingsHelper::save_oobe_opened_state();
}
}
catch (const std::exception& e)
{
Logger::error("Failed to get or save OOBE state with an exception: {}", e.what());
}
int result = 0;
try
{
@@ -411,6 +431,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
auto general_settings = load_general_settings();
const bool openSettings = std::string(lpCmdLine).find("--open-settings") != std::string::npos;
// Apply the general settings but don't save it as the modules() variable has not been loaded yet
apply_general_settings(general_settings, false);
int rvalue = 0;
@@ -420,7 +441,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
std::string(lpCmdLine).find("--dont-elevate") != std::string::npos))
{
result = runner(elevated, openSettings);
result = runner(elevated, openSettings, openOobe);
}
else
{

View File

@@ -277,7 +277,7 @@ BOOL run_settings_non_elevated(LPCWSTR executable_path, LPWSTR executable_args,
DWORD g_settings_process_id = 0;
void run_settings_window()
void run_settings_window(bool showOobeWindow)
{
g_isLaunchInProgress = true;
@@ -303,7 +303,7 @@ void run_settings_window()
executable_path.append(L"\\PowerToysSettings.exe");
}
// Arg 2: pipe server. Generate unique names for the pipes, if getting a UUID is possible.
// Args 2,3: pipe server. Generate unique names for the pipes, if getting a UUID is possible.
std::wstring powertoys_pipe_name(L"\\\\.\\pipe\\powertoys_runner_");
std::wstring settings_pipe_name(L"\\\\.\\pipe\\powertoys_settings_");
UUID temp_uuid;
@@ -327,10 +327,10 @@ void run_settings_window()
uuid_chars = nullptr;
}
// Arg 3: process pid.
// Arg 4: process pid.
DWORD powertoys_pid = GetCurrentProcessId();
// Arg 4: settings theme.
// Arg 5: settings theme.
const std::wstring settings_theme_setting{ get_general_settings().theme };
std::wstring settings_theme = L"system";
if (settings_theme_setting == L"dark" || (settings_theme_setting == L"system" && WindowsColors::is_dark_mode()))
@@ -338,33 +338,18 @@ void run_settings_window()
settings_theme = L"dark";
}
// Arg 4: settings theme.
GeneralSettings save_settings = get_general_settings();
// Arg 6: elevated status
bool isElevated{ get_general_settings().isElevated };
std::wstring settings_elevatedStatus;
settings_elevatedStatus = isElevated;
if (isElevated)
{
settings_elevatedStatus = L"true";
}
else
{
settings_elevatedStatus = L"false";
}
std::wstring settings_elevatedStatus = isElevated ? L"true" : L"false";
// Arg 7: is user an admin
bool isAdmin{ get_general_settings().isAdmin };
std::wstring settings_isUserAnAdmin;
std::wstring settings_isUserAnAdmin = isAdmin ? L"true" : L"false";
if (isAdmin)
{
settings_isUserAnAdmin = L"true";
}
else
{
settings_isUserAnAdmin = L"false";
}
// Arg 8: should oobe window be shown
std::wstring settings_showOobe = showOobeWindow ? L"true" : L"false";
// create general settings file to initialize the settings file with installation configurations like :
// 1. Run on start up.
@@ -384,7 +369,9 @@ void run_settings_window()
executable_args.append(settings_elevatedStatus);
executable_args.append(L" ");
executable_args.append(settings_isUserAnAdmin);
executable_args.append(L" ");
executable_args.append(settings_showOobe);
BOOL process_created = false;
// Due to a bug in .NET, running the Settings process as non-elevated
@@ -510,7 +497,9 @@ void open_settings_window()
{
if (!g_isLaunchInProgress)
{
std::thread(run_settings_window).detach();
std::thread([]() {
run_settings_window(false);
}).detach();
}
}
}
@@ -526,3 +515,10 @@ void close_settings_window()
}
}
}
void open_oobe_window()
{
std::thread([]() {
run_settings_window(true);
}).detach();
}

View File

@@ -1,3 +1,5 @@
#pragma once
void open_settings_window();
void close_settings_window();
void close_settings_window();
void open_oobe_window();