mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
settings: use actionable toast notifications for file explorer modules warning
This commit is contained in:
committed by
Andrey Nekrasov
parent
5e772340bc
commit
ec18e31ff1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Import Project="..\Version.props" />
|
||||
@@ -140,6 +140,7 @@
|
||||
<ClInclude Include="shared_constants.h" />
|
||||
<ClInclude Include="string_utils.h" />
|
||||
<ClInclude Include="timeutil.h" />
|
||||
<ClInclude Include="toast_dont_show_again.h" />
|
||||
<ClInclude Include="two_way_pipe_message_ipc.h" />
|
||||
<ClInclude Include="VersionHelper.h" />
|
||||
<ClInclude Include="window_helpers.h" />
|
||||
@@ -185,6 +186,7 @@
|
||||
<ClCompile Include="start_visible.cpp" />
|
||||
<ClCompile Include="tasklist_positions.cpp" />
|
||||
<ClCompile Include="common.cpp" />
|
||||
<ClCompile Include="toast_dont_show_again.cpp" />
|
||||
<ClCompile Include="version.cpp" />
|
||||
<ClCompile Include="two_way_pipe_message_ipc.cpp" />
|
||||
<ClCompile Include="VersionHelper.cpp" />
|
||||
|
||||
@@ -141,6 +141,9 @@
|
||||
<ClInclude Include="string_utils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="toast_dont_show_again.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="d2d_svg.cpp">
|
||||
@@ -222,6 +225,9 @@
|
||||
<ClCompile Include="comUtils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="toast_dont_show_again.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <Windows.h>
|
||||
#include <limits>
|
||||
|
||||
#include "../timeutil.h"
|
||||
namespace
|
||||
{
|
||||
const inline wchar_t CANT_DRAG_ELEVATED_DONT_SHOW_AGAIN_REGISTRY_PATH[] = LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain\{e16ea82f-6d94-4f30-bb02-d6d911588afd})";
|
||||
const inline int64_t disable_interval_in_days = 30;
|
||||
}
|
||||
|
||||
inline bool disable_cant_drag_elevated_warning()
|
||||
{
|
||||
HKEY key{};
|
||||
if (RegCreateKeyExW(HKEY_CURRENT_USER,
|
||||
CANT_DRAG_ELEVATED_DONT_SHOW_AGAIN_REGISTRY_PATH,
|
||||
0,
|
||||
nullptr,
|
||||
REG_OPTION_NON_VOLATILE,
|
||||
KEY_ALL_ACCESS,
|
||||
nullptr,
|
||||
&key,
|
||||
nullptr) != ERROR_SUCCESS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const auto now = timeutil::now();
|
||||
const size_t buf_size = sizeof(now);
|
||||
if (RegSetValueExW(key, nullptr, 0, REG_QWORD, reinterpret_cast<const BYTE*>(&now), sizeof(now)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(key);
|
||||
return false;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool is_cant_drag_elevated_warning_disabled()
|
||||
{
|
||||
HKEY key{};
|
||||
if (RegOpenKeyExW(HKEY_CURRENT_USER,
|
||||
CANT_DRAG_ELEVATED_DONT_SHOW_AGAIN_REGISTRY_PATH,
|
||||
0,
|
||||
KEY_READ,
|
||||
&key) != ERROR_SUCCESS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::wstring buffer(std::numeric_limits<time_t>::digits10 + 2, L'\0');
|
||||
time_t last_disabled_time{};
|
||||
DWORD time_size = static_cast<DWORD>(sizeof(last_disabled_time));
|
||||
if (RegGetValueW(
|
||||
key,
|
||||
nullptr,
|
||||
nullptr,
|
||||
RRF_RT_REG_QWORD,
|
||||
nullptr,
|
||||
&last_disabled_time,
|
||||
&time_size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(key);
|
||||
return false;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
return timeutil::diff::in_days(timeutil::now(), last_disabled_time) < disable_interval_in_days;
|
||||
return false;
|
||||
}
|
||||
62
src/common/toast_dont_show_again.cpp
Normal file
62
src/common/toast_dont_show_again.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "pch.h"
|
||||
#include "toast_dont_show_again.h"
|
||||
|
||||
namespace notifications
|
||||
{
|
||||
bool disable_toast(const wchar_t* registry_path)
|
||||
{
|
||||
HKEY key{};
|
||||
if (RegCreateKeyExW(HKEY_CURRENT_USER,
|
||||
registry_path,
|
||||
0,
|
||||
nullptr,
|
||||
REG_OPTION_NON_VOLATILE,
|
||||
KEY_ALL_ACCESS,
|
||||
nullptr,
|
||||
&key,
|
||||
nullptr) != ERROR_SUCCESS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const auto now = timeutil::now();
|
||||
const size_t buf_size = sizeof(now);
|
||||
if (RegSetValueExW(key, nullptr, 0, REG_QWORD, reinterpret_cast<const BYTE*>(&now), sizeof(now)) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(key);
|
||||
return false;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_toast_disabled(const wchar_t* registry_path, const int64_t disable_interval_in_days)
|
||||
{
|
||||
HKEY key{};
|
||||
if (RegOpenKeyExW(HKEY_CURRENT_USER,
|
||||
registry_path,
|
||||
0,
|
||||
KEY_READ,
|
||||
&key) != ERROR_SUCCESS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::wstring buffer(std::numeric_limits<time_t>::digits10 + 2, L'\0');
|
||||
time_t last_disabled_time{};
|
||||
DWORD time_size = static_cast<DWORD>(sizeof(last_disabled_time));
|
||||
if (RegGetValueW(
|
||||
key,
|
||||
nullptr,
|
||||
nullptr,
|
||||
RRF_RT_REG_QWORD,
|
||||
nullptr,
|
||||
&last_disabled_time,
|
||||
&time_size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(key);
|
||||
return false;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
return timeutil::diff::in_days(timeutil::now(), last_disabled_time) < disable_interval_in_days;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
15
src/common/toast_dont_show_again.h
Normal file
15
src/common/toast_dont_show_again.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "timeutil.h"
|
||||
|
||||
namespace notifications
|
||||
{
|
||||
const inline wchar_t CantDragElevatedDontShowAgainRegistryPath[] = LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain\{e16ea82f-6d94-4f30-bb02-d6d911588afd})";
|
||||
const inline int64_t CantDragElevatedDisableIntervalInDays = 30;
|
||||
|
||||
const inline wchar_t PreviewModulesDontShowAgainRegistryPath[] = LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain\{7e29e2b2-b31c-4dcd-b7b0-79c078b02430})";
|
||||
const inline int64_t PreviewModulesDisableIntervalInDays = 30;
|
||||
|
||||
bool disable_toast(const wchar_t* registry_path);
|
||||
bool is_toast_disabled(const wchar_t* registry_path, const int64_t disable_interval_in_days);
|
||||
}
|
||||
Reference in New Issue
Block a user