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

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