[Common]NotificationUtil helper class with FileWatcher (#36720)
* add NotificationUtil helper with file watcher and cache * fix spellcheck * indentation
This commit is contained in:
Родитель
403060e109
Коммит
9e1242e8d5
|
@ -9,6 +9,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#include <wil/resource.h>
|
||||||
|
#include <wil/filesystem.h>
|
||||||
|
|
||||||
class FileWatcher
|
class FileWatcher
|
||||||
{
|
{
|
||||||
std::wstring m_path;
|
std::wstring m_path;
|
||||||
|
|
|
@ -10,4 +10,3 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include <common/logger/logger.h>
|
#include <common/logger/logger.h>
|
||||||
#include <wil/filesystem.h>
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
#include "pch.h"
|
||||||
|
#include "NotificationUtil.h"
|
||||||
|
|
||||||
|
#include <common/notifications/notifications.h>
|
||||||
|
#include <common/notifications/dont_show_again.h>
|
||||||
|
#include <common/utils/resources.h>
|
||||||
|
#include <common/SettingsAPI/settings_helpers.h>
|
||||||
|
|
||||||
|
// Non-Localizable strings
|
||||||
|
namespace NonLocalizable
|
||||||
|
{
|
||||||
|
const wchar_t RunAsAdminInfoPage[] = L"https://aka.ms/powertoysDetectedElevatedHelp";
|
||||||
|
const wchar_t ToastNotificationButtonUrl[] = L"powertoys://cant_drag_elevated_disable/";
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace notifications
|
||||||
|
{
|
||||||
|
NotificationUtil::NotificationUtil()
|
||||||
|
{
|
||||||
|
ReadSettings();
|
||||||
|
auto settingsFileName = PTSettingsHelper::get_powertoys_general_save_file_location();
|
||||||
|
|
||||||
|
m_settingsFileWatcher = std::make_unique<FileWatcher>(settingsFileName, [this]() {
|
||||||
|
ReadSettings();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationUtil::~NotificationUtil()
|
||||||
|
{
|
||||||
|
m_settingsFileWatcher.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationUtil::WarnIfElevationIsRequired(std::wstring title, std::wstring message, std::wstring button1, std::wstring button2)
|
||||||
|
{
|
||||||
|
if (m_warningsElevatedApps && !m_warningShown && !is_toast_disabled(ElevatedDontShowAgainRegistryPath, ElevatedDisableIntervalInDays))
|
||||||
|
{
|
||||||
|
std::vector<action_t> actions = {
|
||||||
|
link_button{ button1, NonLocalizable::RunAsAdminInfoPage },
|
||||||
|
link_button{ button2, NonLocalizable::ToastNotificationButtonUrl }
|
||||||
|
};
|
||||||
|
|
||||||
|
show_toast_with_activations(message,
|
||||||
|
title,
|
||||||
|
{},
|
||||||
|
std::move(actions));
|
||||||
|
|
||||||
|
m_warningShown = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotificationUtil::ReadSettings()
|
||||||
|
{
|
||||||
|
auto settings = PTSettingsHelper::load_general_settings();
|
||||||
|
m_warningsElevatedApps = settings.GetNamedBoolean(L"enable_warnings_elevated_apps", true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,40 +1,22 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <common/notifications/notifications.h>
|
#include <common/SettingsAPI/FileWatcher.h>
|
||||||
#include <common/notifications/dont_show_again.h>
|
|
||||||
#include <common/utils/resources.h>
|
|
||||||
#include <common/SettingsAPI/settings_helpers.h>
|
|
||||||
|
|
||||||
#include "Generated Files/resource.h"
|
|
||||||
|
|
||||||
namespace notifications
|
namespace notifications
|
||||||
{
|
{
|
||||||
// Non-Localizable strings
|
class NotificationUtil
|
||||||
namespace NonLocalizable
|
|
||||||
{
|
{
|
||||||
const wchar_t RunAsAdminInfoPage[] = L"https://aka.ms/powertoysDetectedElevatedHelp";
|
public:
|
||||||
const wchar_t ToastNotificationButtonUrl[] = L"powertoys://cant_drag_elevated_disable/";
|
NotificationUtil();
|
||||||
}
|
~NotificationUtil();
|
||||||
|
|
||||||
inline void WarnIfElevationIsRequired(std::wstring title, std::wstring message, std::wstring button1, std::wstring button2)
|
void WarnIfElevationIsRequired(std::wstring title, std::wstring message, std::wstring button1, std::wstring button2);
|
||||||
{
|
|
||||||
using namespace NonLocalizable;
|
|
||||||
|
|
||||||
auto settings = PTSettingsHelper::load_general_settings();
|
private:
|
||||||
auto enableWarningsElevatedApps = settings.GetNamedBoolean(L"enable_warnings_elevated_apps", true);
|
std::unique_ptr<FileWatcher> m_settingsFileWatcher;
|
||||||
|
bool m_warningsElevatedApps;
|
||||||
|
bool m_warningShown = false;
|
||||||
|
|
||||||
static bool warning_shown = false;
|
void ReadSettings();
|
||||||
if (enableWarningsElevatedApps && !warning_shown && !is_toast_disabled(ElevatedDontShowAgainRegistryPath, ElevatedDisableIntervalInDays))
|
};
|
||||||
{
|
}
|
||||||
std::vector<action_t> actions = {
|
|
||||||
link_button{ button1, RunAsAdminInfoPage },
|
|
||||||
link_button{ button2, ToastNotificationButtonUrl }
|
|
||||||
};
|
|
||||||
show_toast_with_activations(message,
|
|
||||||
title,
|
|
||||||
{},
|
|
||||||
std::move(actions));
|
|
||||||
warning_shown = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -27,13 +27,14 @@
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="notifications.h" />
|
<ClInclude Include="notifications.h" />
|
||||||
<ClInclude Include="NotificationUtil.h" />
|
|
||||||
<ClInclude Include="dont_show_again.h" />
|
<ClInclude Include="dont_show_again.h" />
|
||||||
|
<ClInclude Include="NotificationUtil.h" />
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dont_show_again.cpp" />
|
<ClCompile Include="dont_show_again.cpp" />
|
||||||
<ClCompile Include="notifications.cpp" />
|
<ClCompile Include="notifications.cpp" />
|
||||||
|
<ClCompile Include="NotificationUtil.cpp" />
|
||||||
<ClCompile Include="pch.cpp">
|
<ClCompile Include="pch.cpp">
|
||||||
<PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <common/utils/elevation.h>
|
#include <common/utils/elevation.h>
|
||||||
#include <common/utils/process_path.h>
|
#include <common/utils/process_path.h>
|
||||||
|
#include <common/utils/resources.h>
|
||||||
#include <common/notifications/NotificationUtil.h>
|
#include <common/notifications/NotificationUtil.h>
|
||||||
|
|
||||||
#include <workspaces-common/WindowEnumerator.h>
|
#include <workspaces-common/WindowEnumerator.h>
|
||||||
|
@ -12,6 +13,8 @@
|
||||||
#include <WorkspacesLib/PwaHelper.h>
|
#include <WorkspacesLib/PwaHelper.h>
|
||||||
#include <WindowProperties/WorkspacesWindowPropertyUtils.h>
|
#include <WindowProperties/WorkspacesWindowPropertyUtils.h>
|
||||||
|
|
||||||
|
#include "Generated Files/resource.h"
|
||||||
|
|
||||||
#pragma comment(lib, "ntdll.lib")
|
#pragma comment(lib, "ntdll.lib")
|
||||||
|
|
||||||
namespace SnapshotUtils
|
namespace SnapshotUtils
|
||||||
|
@ -74,10 +77,12 @@ namespace SnapshotUtils
|
||||||
// Notify the user that running as admin is required to process elevated windows.
|
// Notify the user that running as admin is required to process elevated windows.
|
||||||
if (!is_process_elevated() && IsProcessElevated(pid))
|
if (!is_process_elevated() && IsProcessElevated(pid))
|
||||||
{
|
{
|
||||||
notifications::WarnIfElevationIsRequired(GET_RESOURCE_STRING(IDS_PROJECTS),
|
auto notificationUtil = std::make_unique<notifications::NotificationUtil>();
|
||||||
GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED),
|
|
||||||
GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED_LEARN_MORE),
|
notificationUtil->WarnIfElevationIsRequired(GET_RESOURCE_STRING(IDS_PROJECTS),
|
||||||
GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED_DIALOG_DONT_SHOW_AGAIN));
|
GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED),
|
||||||
|
GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED_LEARN_MORE),
|
||||||
|
GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED_DIALOG_DONT_SHOW_AGAIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <common/utils/process_path.h>
|
#include <common/utils/process_path.h>
|
||||||
|
|
||||||
#include <common/utils/elevation.h>
|
#include <common/utils/elevation.h>
|
||||||
#include <common/notifications/NotificationUtil.h>
|
|
||||||
#include <Generated Files/resource.h>
|
#include <Generated Files/resource.h>
|
||||||
|
|
||||||
#include <interop/shared_constants.h>
|
#include <interop/shared_constants.h>
|
||||||
|
@ -36,7 +35,8 @@ AlwaysOnTop::AlwaysOnTop(bool useLLKH, DWORD mainThreadId) :
|
||||||
SettingsObserver({SettingId::FrameEnabled, SettingId::Hotkey, SettingId::ExcludeApps}),
|
SettingsObserver({SettingId::FrameEnabled, SettingId::Hotkey, SettingId::ExcludeApps}),
|
||||||
m_hinstance(reinterpret_cast<HINSTANCE>(&__ImageBase)),
|
m_hinstance(reinterpret_cast<HINSTANCE>(&__ImageBase)),
|
||||||
m_useCentralizedLLKH(useLLKH),
|
m_useCentralizedLLKH(useLLKH),
|
||||||
m_mainThreadId(mainThreadId)
|
m_mainThreadId(mainThreadId),
|
||||||
|
m_notificationUtil(std::make_unique<notifications::NotificationUtil>())
|
||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
DPIAware::EnableDPIAwarenessForThisProcess();
|
DPIAware::EnableDPIAwarenessForThisProcess();
|
||||||
|
@ -64,6 +64,7 @@ AlwaysOnTop::AlwaysOnTop(bool useLLKH, DWORD mainThreadId) :
|
||||||
AlwaysOnTop::~AlwaysOnTop()
|
AlwaysOnTop::~AlwaysOnTop()
|
||||||
{
|
{
|
||||||
m_running = false;
|
m_running = false;
|
||||||
|
m_notificationUtil.reset();
|
||||||
|
|
||||||
if (m_hPinEvent)
|
if (m_hPinEvent)
|
||||||
{
|
{
|
||||||
|
@ -509,7 +510,10 @@ void AlwaysOnTop::HandleWinHookEvent(WinHookEvent* data) noexcept
|
||||||
{
|
{
|
||||||
if (!is_process_elevated() && IsProcessOfWindowElevated(data->hwnd))
|
if (!is_process_elevated() && IsProcessOfWindowElevated(data->hwnd))
|
||||||
{
|
{
|
||||||
notifications::WarnIfElevationIsRequired(GET_RESOURCE_STRING(IDS_ALWAYSONTOP), GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED), GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED_LEARN_MORE), GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED_DIALOG_DONT_SHOW_AGAIN));
|
m_notificationUtil->WarnIfElevationIsRequired(GET_RESOURCE_STRING(IDS_ALWAYSONTOP),
|
||||||
|
GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED),
|
||||||
|
GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED_LEARN_MORE),
|
||||||
|
GET_RESOURCE_STRING(IDS_SYSTEM_FOREGROUND_ELEVATED_DIALOG_DONT_SHOW_AGAIN));
|
||||||
}
|
}
|
||||||
RefreshBorders();
|
RefreshBorders();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <WindowBorder.h>
|
#include <WindowBorder.h>
|
||||||
|
|
||||||
#include <common/hooks/WinHookEvent.h>
|
#include <common/hooks/WinHookEvent.h>
|
||||||
|
#include <common/notifications/NotificationUtil.h>
|
||||||
|
|
||||||
class AlwaysOnTop : public SettingsObserver
|
class AlwaysOnTop : public SettingsObserver
|
||||||
{
|
{
|
||||||
|
@ -53,6 +54,7 @@ private:
|
||||||
std::thread m_thread;
|
std::thread m_thread;
|
||||||
const bool m_useCentralizedLLKH;
|
const bool m_useCentralizedLLKH;
|
||||||
bool m_running = true;
|
bool m_running = true;
|
||||||
|
std::unique_ptr<notifications::NotificationUtil> m_notificationUtil;
|
||||||
|
|
||||||
LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
|
LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
|
||||||
void HandleWinHookEvent(WinHookEvent* data) noexcept;
|
void HandleWinHookEvent(WinHookEvent* data) noexcept;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <common/utils/EventWaiter.h>
|
#include <common/utils/EventWaiter.h>
|
||||||
#include <common/utils/winapi_error.h>
|
#include <common/utils/winapi_error.h>
|
||||||
#include <common/SettingsAPI/FileWatcher.h>
|
#include <common/SettingsAPI/FileWatcher.h>
|
||||||
|
#include <common/notifications/NotificationUtil.h>
|
||||||
|
|
||||||
#include <FancyZonesLib/DraggingState.h>
|
#include <FancyZonesLib/DraggingState.h>
|
||||||
#include <FancyZonesLib/EditorParameters.h>
|
#include <FancyZonesLib/EditorParameters.h>
|
||||||
|
@ -185,6 +186,8 @@ private:
|
||||||
|
|
||||||
EventWaiter m_toggleEditorEventWaiter;
|
EventWaiter m_toggleEditorEventWaiter;
|
||||||
|
|
||||||
|
std::unique_ptr<notifications::NotificationUtil> m_notificationUtil;
|
||||||
|
|
||||||
// If non-recoverable error occurs, trigger disabling of entire FancyZones.
|
// If non-recoverable error occurs, trigger disabling of entire FancyZones.
|
||||||
static std::function<void()> disableModuleCallback;
|
static std::function<void()> disableModuleCallback;
|
||||||
|
|
||||||
|
@ -266,6 +269,8 @@ FancyZones::Run() noexcept
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m_notificationUtil = std::make_unique<notifications::NotificationUtil>();
|
||||||
|
|
||||||
SyncVirtualDesktops();
|
SyncVirtualDesktops();
|
||||||
|
|
||||||
// id format of applied-layouts and app-zone-history was changed in 0.60
|
// id format of applied-layouts and app-zone-history was changed in 0.60
|
||||||
|
@ -288,6 +293,8 @@ FancyZones::Destroy() noexcept
|
||||||
m_window = nullptr;
|
m_window = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_notificationUtil.reset();
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +309,7 @@ FancyZones::VirtualDesktopChanged() noexcept
|
||||||
|
|
||||||
void FancyZones::MoveSizeStart(HWND window, HMONITOR monitor)
|
void FancyZones::MoveSizeStart(HWND window, HMONITOR monitor)
|
||||||
{
|
{
|
||||||
m_windowMouseSnapper = WindowMouseSnap::Create(window, m_workAreaConfiguration.GetAllWorkAreas());
|
m_windowMouseSnapper = WindowMouseSnap::Create(window, m_workAreaConfiguration.GetAllWorkAreas(), m_notificationUtil.get());
|
||||||
if (m_windowMouseSnapper)
|
if (m_windowMouseSnapper)
|
||||||
{
|
{
|
||||||
if (FancyZonesSettings::settings().spanZonesAcrossMonitors)
|
if (FancyZonesSettings::settings().spanZonesAcrossMonitors)
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <FancyZonesLib/trace.h>
|
#include <FancyZonesLib/trace.h>
|
||||||
|
|
||||||
#include <common/utils/elevation.h>
|
#include <common/utils/elevation.h>
|
||||||
#include <common/notifications/NotificationUtil.h>
|
#include <common/utils/resources.h>
|
||||||
|
|
||||||
WindowMouseSnap::WindowMouseSnap(HWND window, const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& activeWorkAreas) :
|
WindowMouseSnap::WindowMouseSnap(HWND window, const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& activeWorkAreas) :
|
||||||
m_window(window),
|
m_window(window),
|
||||||
|
@ -27,7 +27,7 @@ WindowMouseSnap::~WindowMouseSnap()
|
||||||
ResetWindowTransparency();
|
ResetWindowTransparency();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<WindowMouseSnap> WindowMouseSnap::Create(HWND window, const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& activeWorkAreas)
|
std::unique_ptr<WindowMouseSnap> WindowMouseSnap::Create(HWND window, const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& activeWorkAreas, notifications::NotificationUtil* notificationUtil)
|
||||||
{
|
{
|
||||||
if (FancyZonesWindowUtils::IsCursorTypeIndicatingSizeEvent() || !FancyZonesWindowProcessing::IsProcessableManually(window))
|
if (FancyZonesWindowUtils::IsCursorTypeIndicatingSizeEvent() || !FancyZonesWindowProcessing::IsProcessableManually(window))
|
||||||
{
|
{
|
||||||
|
@ -36,8 +36,15 @@ std::unique_ptr<WindowMouseSnap> WindowMouseSnap::Create(HWND window, const std:
|
||||||
|
|
||||||
if (!is_process_elevated() && IsProcessOfWindowElevated(window))
|
if (!is_process_elevated() && IsProcessOfWindowElevated(window))
|
||||||
{
|
{
|
||||||
// Notifies user if unable to drag elevated window
|
if (notificationUtil != nullptr)
|
||||||
notifications::WarnIfElevationIsRequired(GET_RESOURCE_STRING(IDS_FANCYZONES), GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED), GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED_LEARN_MORE), GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED_DIALOG_DONT_SHOW_AGAIN));
|
{
|
||||||
|
// Notifies user if unable to drag elevated window
|
||||||
|
notificationUtil->WarnIfElevationIsRequired(GET_RESOURCE_STRING(IDS_FANCYZONES),
|
||||||
|
GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED),
|
||||||
|
GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED_LEARN_MORE),
|
||||||
|
GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED_DIALOG_DONT_SHOW_AGAIN));
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <FancyZonesLib/HighlightedZones.h>
|
#include <FancyZonesLib/HighlightedZones.h>
|
||||||
|
#include <common/notifications/NotificationUtil.h>
|
||||||
|
|
||||||
class WorkArea;
|
class WorkArea;
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ class WindowMouseSnap
|
||||||
WindowMouseSnap(HWND window, const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& activeWorkAreas);
|
WindowMouseSnap(HWND window, const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& activeWorkAreas);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<WindowMouseSnap> Create(HWND window, const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& activeWorkAreas);
|
static std::unique_ptr<WindowMouseSnap> Create(HWND window, const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& activeWorkAreas, notifications::NotificationUtil* notificationUtil);
|
||||||
~WindowMouseSnap();
|
~WindowMouseSnap();
|
||||||
|
|
||||||
bool MoveSizeStart(HMONITOR monitor, bool isSnapping);
|
bool MoveSizeStart(HMONITOR monitor, bool isSnapping);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче