-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add NotificationUtil helper with file watcher and cache
- Loading branch information
1 parent
809791d
commit 97666df
Showing
11 changed files
with
104 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,3 @@ | |
#include <fstream> | ||
|
||
#include <common/logger/logger.h> | ||
#include <wil/filesystem.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
Check failure Code scanning / check-spelling Unrecognized Spelling Error
settingsfile is not a recognized word. (unrecognized-spelling)
|
||
|
||
m_settingsFileWatcher = std::make_unique<FileWatcher>(settingsfileName, [this]() { | ||
Check failure Code scanning / check-spelling Unrecognized Spelling Error
settingsfile is not a recognized word. (unrecognized-spelling)
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,22 @@ | ||
#pragma once | ||
|
||
#include <common/notifications/notifications.h> | ||
#include <common/notifications/dont_show_again.h> | ||
#include <common/utils/resources.h> | ||
#include <common/SettingsAPI/settings_helpers.h> | ||
|
||
#include "Generated Files/resource.h" | ||
#include <common/SettingsAPI/FileWatcher.h> | ||
|
||
namespace notifications | ||
{ | ||
// Non-Localizable strings | ||
namespace NonLocalizable | ||
class NotificationUtil | ||
{ | ||
const wchar_t RunAsAdminInfoPage[] = L"https://aka.ms/powertoysDetectedElevatedHelp"; | ||
const wchar_t ToastNotificationButtonUrl[] = L"powertoys://cant_drag_elevated_disable/"; | ||
} | ||
public: | ||
NotificationUtil(); | ||
~NotificationUtil(); | ||
|
||
inline void WarnIfElevationIsRequired(std::wstring title, std::wstring message, std::wstring button1, std::wstring button2) | ||
{ | ||
using namespace NonLocalizable; | ||
void WarnIfElevationIsRequired(std::wstring title, std::wstring message, std::wstring button1, std::wstring button2); | ||
|
||
auto settings = PTSettingsHelper::load_general_settings(); | ||
auto enableWarningsElevatedApps = settings.GetNamedBoolean(L"enable_warnings_elevated_apps", true); | ||
private: | ||
std::unique_ptr<FileWatcher> m_settingsFileWatcher; | ||
bool m_warningsElevatedApps; | ||
bool m_warningShown = false; | ||
|
||
static bool warning_shown = false; | ||
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; | ||
} | ||
} | ||
} | ||
void ReadSettings(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97666df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@check-spelling-bot Report
🔴 Please review
See the 📜action log or 📝 job summary for details.
Unrecognized words (1)
settingsfile
These words are not needed and should be removed
accctrl aclapi appdata Appium appmodel atlbase atlcom atlfile atlstr bootstrapper caniuse ceq cguid Cmds cne codicon comdef commandline commctrl commdlg comutil consts contentdialog cppwinrt CRSEL crx dcommon dcomp DCs desktopwindowxamlsource devpkey dxgidebug dxgiformat emmintrin Emoji endpointvolume evntrace exdisp Functiondiscoverykeys guiddef hinstance hstring Intelli ipreviewhandlervisualssetfont junja Knownfolders lmcons LONGLONG lpt LTRB mfapi mfidl mfobjects mftransform Minimatch mmdeviceapi mmsystem msedge msiquery newdev nodoc notlike ntfs Objbase objidl outputtype pathcch Pnp Preinstalled processthreadsapi propkey propvarutil redistributable Renamer reparse restrictederrorinfo roadmap ruleset runtimes shellapi shellscalingapi shldisp shlobj stl strsafe strutil subquery SWC tailwindcss tapp thumbcache tlhelp Toolset touchpad Tsd uninstantiated uniquifier Unknwn unregistering urlmon USERDATA Uxtheme verrsrc wcautil wincodec Wincodecsdk windef windowsapp windowsx winerror winevt winexe winforms winsdkver winternl wsl wtsapiTo accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands
... in a clone of the [email protected]:microsoft/PowerToys.git repository
on the
users/davidegiacometti/issue-36586
branch (ℹ️ how do I use this?):If the flagged items are 🤯 false positives
If items relate to a ...
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txt
file matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^
refers to the file's path from the root of the repository, so^README\.md$
would exclude README.md (on whichever branch you're using).well-formed pattern.
If you can write a pattern that would match it,
try adding it to the
patterns.txt
file.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.