[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

@@ -0,0 +1,41 @@
// 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.
using System;
using System.ComponentModel.Composition;
using System.Threading;
using System.Windows;
using interop;
namespace ColorPicker.Helpers
{
[Export(typeof(NativeEventWaiter))]
public class NativeEventWaiter
{
private AppStateHandler _appStateHandler;
[ImportingConstructor]
public NativeEventWaiter(AppStateHandler appStateHandler)
{
_appStateHandler = appStateHandler;
WaitForEventLoop(Constants.ShowColorPickerSharedEvent(), _appStateHandler.ShowColorPicker);
}
public static void WaitForEventLoop(string eventName, Action callback)
{
new Thread(() =>
{
var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
while (true)
{
if (eventHandle.WaitOne())
{
Logger.LogInfo("Successfully waited for SHOW_COLOR_PICKER_EVENT");
Application.Current.Dispatcher.Invoke(callback);
}
}
}).Start();
}
}
}

View File

@@ -26,6 +26,7 @@ namespace ColorPicker.ViewModels
private readonly ZoomWindowHelper _zoomWindowHelper;
private readonly AppStateHandler _appStateHandler;
private readonly IUserSettings _userSettings;
private readonly NativeEventWaiter _nativeEventWaiter;
/// <summary>
/// Backing field for <see cref="OtherColor"/>
@@ -48,11 +49,13 @@ namespace ColorPicker.ViewModels
ZoomWindowHelper zoomWindowHelper,
AppStateHandler appStateHandler,
KeyboardMonitor keyboardMonitor,
NativeEventWaiter nativeEventWaiter,
IUserSettings userSettings)
{
_zoomWindowHelper = zoomWindowHelper;
_appStateHandler = appStateHandler;
_userSettings = userSettings;
_nativeEventWaiter = nativeEventWaiter;
if (mouseInfoProvider != null)
{

View File

@@ -41,6 +41,7 @@ void D2DWindow::show(UINT x, UINT y, UINT width, UINT height)
on_show();
SetWindowPos(hwnd, HWND_TOPMOST, x, y, width, height, 0);
ShowWindow(hwnd, SW_SHOWNORMAL);
SetForegroundWindow(hwnd);
UpdateWindow(hwnd);
}

View File

@@ -0,0 +1,29 @@
#include "pch.h"
#include "native_event_waiter.h"
void NativeEventWaiter::run()
{
while (!aborting)
{
auto result = WaitForSingleObject(event_handle, timeout);
if (!aborting && result == WAIT_OBJECT_0)
{
action();
}
}
}
NativeEventWaiter::NativeEventWaiter(const std::wstring& event_name, std::function<void()> action)
{
event_handle = CreateEventW(NULL, FALSE, FALSE, event_name.c_str());
this->action = action;
running_thread = std::thread([&]() { run(); });
}
NativeEventWaiter::~NativeEventWaiter()
{
aborting = true;
SetEvent(event_handle);
running_thread.join();
CloseHandle(event_handle);
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include "pch.h"
#include "common/interop/shared_constants.h"
class NativeEventWaiter
{
static const int timeout = 1000;
HANDLE event_handle;
std::function<void()> action;
std::atomic<bool> aborting;
void run();
std::thread running_thread;
public:
NativeEventWaiter(const std::wstring& event_name, std::function<void()> action);
~NativeEventWaiter();
};

View File

@@ -5,6 +5,7 @@
#include <common/SettingsAPI/settings_objects.h>
#include <common/debug_control.h>
#include <common/interop/shared_constants.h>
#include <sstream>
#include <modules/shortcut_guide/ShortcutGuideConstants.h>
@@ -94,6 +95,8 @@ namespace
((style & WS_THICKFRAME) == WS_THICKFRAME);
return result;
}
const LPARAM eventActivateWindow = 1;
}
OverlayWindow::OverlayWindow()
@@ -212,6 +215,13 @@ void OverlayWindow::enable()
instance->target_state->toggle_force_shown();
return 0;
}
if (msg == WM_APP && lparam == eventActivateWindow)
{
instance->target_state->toggle_force_shown();
return 0;
}
if (msg != WM_HOTKEY)
{
return 0;
@@ -260,6 +270,12 @@ void OverlayWindow::enable()
}
}
RegisterHotKey(winkey_popup->get_window_handle(), alternative_switch_hotkey_id, alternative_switch_modifier_mask, alternative_switch_vk_code);
auto show_action = [&]() {
PostMessageW(winkey_popup->get_window_handle(), WM_APP, 0, eventActivateWindow);
};
event_waiter = std::make_unique<NativeEventWaiter>(CommonSharedConstants::SHOW_SHORTCUT_GUIDE_SHARED_EVENT, show_action);
}
_enabled = true;
}
@@ -276,6 +292,7 @@ void OverlayWindow::disable(bool trace_event)
Trace::EnableShortcutGuide(false);
}
UnregisterHotKey(winkey_popup->get_window_handle(), alternative_switch_hotkey_id);
event_waiter.reset();
winkey_popup->hide();
target_state->exit();
target_state.reset();

View File

@@ -1,6 +1,7 @@
#pragma once
#include <interface/powertoy_module_interface.h>
#include "overlay_window.h"
#include "native_event_waiter.h"
#include "Generated Files/resource.h"
@@ -44,6 +45,7 @@ private:
std::unique_ptr<D2DOverlayWindow> winkey_popup;
bool _enabled = false;
HHOOK hook_handle;
std::unique_ptr<NativeEventWaiter> event_waiter;
void init_settings();
void disable(bool trace_event);

View File

@@ -67,6 +67,7 @@
<ClInclude Include="d2d_svg.h" />
<ClInclude Include="d2d_text.h" />
<ClInclude Include="d2d_window.h" />
<ClInclude Include="native_event_waiter.h" />
<ClInclude Include="overlay_window.h" />
<ClInclude Include="keyboard_state.h" />
<ClInclude Include="Generated Files/resource.h" />
@@ -83,6 +84,7 @@
<ClCompile Include="d2d_svg.cpp" />
<ClCompile Include="d2d_text.cpp" />
<ClCompile Include="d2d_window.cpp" />
<ClCompile Include="native_event_waiter.cpp" />
<ClCompile Include="overlay_window.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="keyboard_state.cpp" />

View File

@@ -36,6 +36,9 @@
<ClCompile Include="tasklist_positions.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="native_event_waiter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
@@ -73,6 +76,9 @@
<ClInclude Include="start_visible.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="native_event_waiter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">