/ src / common / notifications / NotificationUtil.cpp
NotificationUtil.cpp
 1  #include "pch.h"
 2  #include "NotificationUtil.h"
 3  
 4  #include <common/notifications/notifications.h>
 5  #include <common/notifications/dont_show_again.h>
 6  #include <common/utils/resources.h>
 7  #include <common/SettingsAPI/settings_helpers.h>
 8  
 9  // Non-Localizable strings
10  namespace NonLocalizable
11  {
12      const wchar_t RunAsAdminInfoPage[] = L"https://aka.ms/powertoysDetectedElevatedHelp";
13      const wchar_t ToastNotificationButtonUrl[] = L"powertoys://cant_drag_elevated_disable/";
14  }
15  
16  namespace notifications
17  {
18      NotificationUtil::NotificationUtil()
19      {
20          ReadSettings();
21          auto settingsFileName = PTSettingsHelper::get_powertoys_general_save_file_location();
22  
23          m_settingsFileWatcher = std::make_unique<FileWatcher>(settingsFileName, [this]() {
24              ReadSettings();
25          });
26      }
27  
28      NotificationUtil::~NotificationUtil()
29      {
30          m_settingsFileWatcher.reset();
31      }
32  
33      void NotificationUtil::WarnIfElevationIsRequired(std::wstring title, std::wstring message, std::wstring button1, std::wstring button2)
34      {
35          if (m_warningsElevatedApps && !m_warningShown && !is_toast_disabled(ElevatedDontShowAgainRegistryPath, ElevatedDisableIntervalInDays))
36          {
37              std::vector<action_t> actions = {
38                  link_button{ button1, NonLocalizable::RunAsAdminInfoPage },
39                  link_button{ button2, NonLocalizable::ToastNotificationButtonUrl }
40              };
41  
42              show_toast_with_activations(message,
43                                          title,
44                                          {},
45                                          std::move(actions));
46  
47              m_warningShown = true;
48          }
49      }
50  
51      void NotificationUtil::ReadSettings()
52      {
53          auto settings = PTSettingsHelper::load_general_settings();
54          m_warningsElevatedApps = settings.GetNamedBoolean(L"enable_warnings_elevated_apps", true);
55      }
56  }