settings: use actionable toast notifications for file explorer modules warning

This commit is contained in:
yuyoyuppe
2020-10-20 01:27:24 +03:00
committed by Andrey Nekrasov
parent 5e772340bc
commit ec18e31ff1
9 changed files with 146 additions and 101 deletions

View File

@@ -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" />

View File

@@ -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" />

View File

@@ -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;
}

View 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;
}
}

View 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);
}

View File

@@ -3,7 +3,7 @@
#include <common/dpi_aware.h>
#include <common/notifications.h>
#include <common/notifications/fancyzones_notifications.h>
#include <common/toast_dont_show_again.h>
#include <common/window_helpers.h>
#include "FancyZonesData.h"
@@ -214,7 +214,7 @@ void WindowMoveHandler::MoveSizeEnd(HWND window, POINT const& ptScreen, const st
if ((isStandardWindow == false && hasNoVisibleOwner == true &&
m_moveSizeWindowInfo.isStandardWindow == true && m_moveSizeWindowInfo.hasNoVisibleOwner == true) ||
FancyZonesUtils::IsWindowMaximized(window))
FancyZonesUtils::IsWindowMaximized(window))
{
// Abort the zoning, this is a Chromium based tab that is merged back with an existing window
// or if the window is maximized by Windows when the cursor hits the screen top border
@@ -299,20 +299,23 @@ bool WindowMoveHandler::ExtendWindowByDirectionAndPosition(HWND window, DWORD vk
void WindowMoveHandler::WarnIfElevationIsRequired(HWND window) noexcept
{
using namespace notifications;
using namespace NonLocalizable;
static bool warning_shown = false;
if (!is_process_elevated() && IsProcessOfWindowElevated(window))
{
m_dragEnabled = false;
if (!warning_shown && !is_cant_drag_elevated_warning_disabled())
if (!warning_shown && !is_toast_disabled(CantDragElevatedDontShowAgainRegistryPath, CantDragElevatedDisableIntervalInDays))
{
std::vector<notifications::action_t> actions = {
notifications::link_button{ GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED_LEARN_MORE), NonLocalizable::FancyZonesRunAsAdminInfoPage },
notifications::link_button{ GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED_DIALOG_DONT_SHOW_AGAIN), NonLocalizable::ToastNotificationButtonUrl }
std::vector<action_t> actions = {
link_button{ GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED_LEARN_MORE), FancyZonesRunAsAdminInfoPage },
link_button{ GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED_DIALOG_DONT_SHOW_AGAIN), ToastNotificationButtonUrl }
};
notifications::show_toast_with_activations(GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED),
GET_RESOURCE_STRING(IDS_FANCYZONES),
{},
std::move(actions));
show_toast_with_activations(GET_RESOURCE_STRING(IDS_CANT_DRAG_ELEVATED),
GET_RESOURCE_STRING(IDS_FANCYZONES),
{},
std::move(actions));
warning_shown = true;
}
}

View File

@@ -157,9 +157,15 @@
<value>Render SVG images</value>
</data>
<data name="FileExplorer_Admin_Restart_Warning_Description" xml:space="preserve">
<value>Some of the File Explorer modules could not be registered/unregistered as per your settings. Please restart PowerToys as admin for the changes to take place.</value>
<value>Some of the File Explorer modules could not be turned off/on as per your settings. Please restart PowerToys as admin for the changes to take place.</value>
</data>
<data name="FileExplorer_Admin_Restart_Warning_Title" xml:space="preserve">
<value>Failed to modify File Explorer modules</value>
<value>Couldn't modify File Explorer modules</value>
</data>
<data name="FileExplorer_Admin_Restart_Warning_Open_Settings" xml:space="preserve">
<value>Open Settings</value>
</data>
<data name="FileExplorer_Admin_Restart_Warning_Dont_Show_Again" xml:space="preserve">
<value>Don't show again</value>
</data>
</root>

View File

@@ -5,7 +5,9 @@
#include "trace.h"
#include "settings.h"
#include "Generated Files/resource.h"
#include <common\os-detect.h>
#include <common/notifications.h>
#include <common/os-detect.h>
#include <common/toast_dont_show_again.h>
// Constructor
PowerPreviewModule::PowerPreviewModule() :
@@ -203,11 +205,20 @@ bool PowerPreviewModule::is_registry_update_required()
// Function to warn the user that PowerToys needs to run as administrator for changes to take effect
void PowerPreviewModule::show_update_warning_message()
{
// Show warning message if update is required
MessageBoxW(NULL,
GET_RESOURCE_STRING(IDS_FILEEXPLORER_ADMIN_RESTART_WARNING_DESCRIPTION).c_str(),
GET_RESOURCE_STRING(IDS_FILEEXPLORER_ADMIN_RESTART_WARNING_TITLE).c_str(),
MB_OK | MB_ICONWARNING);
using namespace notifications;
if (!is_toast_disabled(PreviewModulesDontShowAgainRegistryPath, PreviewModulesDisableIntervalInDays))
{
std::vector<action_t> actions = {
link_button{ GET_RESOURCE_STRING(IDS_FILEEXPLORER_ADMIN_RESTART_WARNING_OPEN_SETTINGS),
L"powertoys://open_settings/" },
link_button{ GET_RESOURCE_STRING(IDS_FILEEXPLORER_ADMIN_RESTART_WARNING_DONT_SHOW_AGAIN),
L"powertoys://couldnt_toggle_powerpreview_modules_disable/" }
};
show_toast_with_activations(GET_RESOURCE_STRING(IDS_FILEEXPLORER_ADMIN_RESTART_WARNING_DESCRIPTION),
GET_RESOURCE_STRING(IDS_FILEEXPLORER_ADMIN_RESTART_WARNING_TITLE),
{},
std::move(actions));
}
}
// Function that checks if a registry method is required and if so checks if the process is elevated and accordingly executes the method or shows a warning

View File

@@ -9,15 +9,16 @@
#include "restart_elevated.h"
#include "Generated files/resource.h"
#include <common/common.h>
#include <common/dpi_aware.h>
#include <common/winstore.h>
#include <common/notifications.h>
#include <common/updating/updating.h>
#include <common/RestartManagement.h>
#include <common/appMutex.h>
#include <common/processApi.h>
#include <common/common.h>
#include <common/comUtils.h>
#include <common/dpi_aware.h>
#include <common/notifications.h>
#include <common/processApi.h>
#include <common/RestartManagement.h>
#include <common/toast_dont_show_again.h>
#include <common/updating/updating.h>
#include <common/winstore.h>
#include "update_state.h"
#include "update_utils.h"
@@ -32,7 +33,6 @@
#if _DEBUG && _WIN64
#include "unhandled_exception_handler.h"
#endif
#include <common/notifications/fancyzones_notifications.h>
extern "C" IMAGE_DOS_HEADER __ImageBase;
@@ -210,13 +210,15 @@ enum class toast_notification_handler_result
toast_notification_handler_result toast_notification_handler(const std::wstring_view param)
{
const std::wstring_view cant_drag_elevated_disable = L"cant_drag_elevated_disable/";
const std::wstring_view update_now = L"update_now/";
const std::wstring_view schedule_update = L"schedule_update/";
const std::wstring_view couldnt_toggle_powerpreview_modules_disable = L"couldnt_toggle_powerpreview_modules_disable/";
const std::wstring_view download_and_install_update = L"download_and_install_update/";
const std::wstring_view open_settings = L"open_settings/";
const std::wstring_view schedule_update = L"schedule_update/";
const std::wstring_view update_now = L"update_now/";
if (param == cant_drag_elevated_disable)
{
return disable_cant_drag_elevated_warning() ? toast_notification_handler_result::exit_success : toast_notification_handler_result::exit_error;
return notifications::disable_toast(notifications::CantDragElevatedDontShowAgainRegistryPath) ? toast_notification_handler_result::exit_success : toast_notification_handler_result::exit_error;
}
else if (param.starts_with(update_now))
{
@@ -260,6 +262,15 @@ toast_notification_handler_result toast_notification_handler(const std::wstring_
return toast_notification_handler_result::exit_error;
}
}
else if (param == couldnt_toggle_powerpreview_modules_disable)
{
return notifications::disable_toast(notifications::PreviewModulesDontShowAgainRegistryPath) ? toast_notification_handler_result::exit_success : toast_notification_handler_result::exit_error;
}
else if (param == open_settings)
{
open_menu_from_another_instance();
return toast_notification_handler_result::exit_success;
}
else
{
return toast_notification_handler_result::exit_error;