[General]Add setting to disable elevated apps warning (#30628)

This commit is contained in:
gokcekantarci
2024-01-03 20:22:54 +03:00
committed by GitHub
parent 7c0f24df65
commit f60c4fd2f3
8 changed files with 47 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
#include <common/notifications/notifications.h> #include <common/notifications/notifications.h>
#include <common/notifications/dont_show_again.h> #include <common/notifications/dont_show_again.h>
#include <common/utils/resources.h> #include <common/utils/resources.h>
#include <common/SettingsAPI/settings_helpers.h>
#include "Generated Files/resource.h" #include "Generated Files/resource.h"
@@ -19,8 +20,11 @@ namespace notifications
{ {
using namespace NonLocalizable; using namespace NonLocalizable;
auto settings = PTSettingsHelper::load_general_settings();
auto enableWarningsElevatedApps = settings.GetNamedBoolean(L"enable_warnings_elevated_apps", true);
static bool warning_shown = false; static bool warning_shown = false;
if (!warning_shown && !is_toast_disabled(ElevatedDontShowAgainRegistryPath, ElevatedDisableIntervalInDays)) if (enableWarningsElevatedApps && !warning_shown && !is_toast_disabled(ElevatedDontShowAgainRegistryPath, ElevatedDisableIntervalInDays))
{ {
std::vector<action_t> actions = { std::vector<action_t> actions = {
link_button{ button1, RunAsAdminInfoPage }, link_button{ button1, RunAsAdminInfoPage },

View File

@@ -17,6 +17,7 @@ static std::wstring settings_theme = L"system";
static bool run_as_elevated = false; static bool run_as_elevated = false;
static bool download_updates_automatically = true; static bool download_updates_automatically = true;
static bool enable_experimentation = true; static bool enable_experimentation = true;
static bool enable_warnings_elevated_apps = true;
json::JsonObject GeneralSettings::to_json() json::JsonObject GeneralSettings::to_json()
{ {
@@ -40,6 +41,7 @@ json::JsonObject GeneralSettings::to_json()
result.SetNamedValue(L"download_updates_automatically", json::value(downloadUpdatesAutomatically)); result.SetNamedValue(L"download_updates_automatically", json::value(downloadUpdatesAutomatically));
result.SetNamedValue(L"enable_experimentation", json::value(enableExperimentation)); result.SetNamedValue(L"enable_experimentation", json::value(enableExperimentation));
result.SetNamedValue(L"is_admin", json::value(isAdmin)); result.SetNamedValue(L"is_admin", json::value(isAdmin));
result.SetNamedValue(L"enable_warnings_elevated_apps", json::value(enableWarningsElevatedApps));
result.SetNamedValue(L"theme", json::value(theme)); result.SetNamedValue(L"theme", json::value(theme));
result.SetNamedValue(L"system_theme", json::value(systemTheme)); result.SetNamedValue(L"system_theme", json::value(systemTheme));
result.SetNamedValue(L"powertoys_version", json::value(powerToysVersion)); result.SetNamedValue(L"powertoys_version", json::value(powerToysVersion));
@@ -58,6 +60,7 @@ json::JsonObject load_general_settings()
run_as_elevated = loaded.GetNamedBoolean(L"run_elevated", false); run_as_elevated = loaded.GetNamedBoolean(L"run_elevated", false);
download_updates_automatically = loaded.GetNamedBoolean(L"download_updates_automatically", true) && check_user_is_admin(); download_updates_automatically = loaded.GetNamedBoolean(L"download_updates_automatically", true) && check_user_is_admin();
enable_experimentation = loaded.GetNamedBoolean(L"enable_experimentation",true); enable_experimentation = loaded.GetNamedBoolean(L"enable_experimentation",true);
enable_warnings_elevated_apps = loaded.GetNamedBoolean(L"enable_warnings_elevated_apps", true);
return loaded; return loaded;
} }
@@ -69,6 +72,7 @@ GeneralSettings get_general_settings()
.isElevated = is_process_elevated(), .isElevated = is_process_elevated(),
.isRunElevated = run_as_elevated, .isRunElevated = run_as_elevated,
.isAdmin = is_user_admin, .isAdmin = is_user_admin,
.enableWarningsElevatedApps = enable_warnings_elevated_apps,
.downloadUpdatesAutomatically = download_updates_automatically && is_user_admin, .downloadUpdatesAutomatically = download_updates_automatically && is_user_admin,
.enableExperimentation = enable_experimentation, .enableExperimentation = enable_experimentation,
.theme = settings_theme, .theme = settings_theme,
@@ -91,6 +95,8 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
Logger::info(L"apply_general_settings: {}", std::wstring{ general_configs.ToString() }); Logger::info(L"apply_general_settings: {}", std::wstring{ general_configs.ToString() });
run_as_elevated = general_configs.GetNamedBoolean(L"run_elevated", false); run_as_elevated = general_configs.GetNamedBoolean(L"run_elevated", false);
enable_warnings_elevated_apps = general_configs.GetNamedBoolean(L"enable_warnings_elevated_apps", true);
download_updates_automatically = general_configs.GetNamedBoolean(L"download_updates_automatically", true); download_updates_automatically = general_configs.GetNamedBoolean(L"download_updates_automatically", true);
enable_experimentation = general_configs.GetNamedBoolean(L"enable_experimentation", true); enable_experimentation = general_configs.GetNamedBoolean(L"enable_experimentation", true);

View File

@@ -10,6 +10,7 @@ struct GeneralSettings
bool isElevated; bool isElevated;
bool isRunElevated; bool isRunElevated;
bool isAdmin; bool isAdmin;
bool enableWarningsElevatedApps;
bool downloadUpdatesAutomatically; bool downloadUpdatesAutomatically;
bool enableExperimentation; bool enableExperimentation;
std::wstring theme; std::wstring theme;

View File

@@ -52,6 +52,7 @@ void Trace::SettingsChanged(const GeneralSettings& settings)
g_hProvider, g_hProvider,
"GeneralSettingsChanged", "GeneralSettingsChanged",
TraceLoggingBoolean(settings.isStartupEnabled, "RunAtStartup"), TraceLoggingBoolean(settings.isStartupEnabled, "RunAtStartup"),
TraceLoggingBoolean(settings.enableWarningsElevatedApps, "EnableWarningsElevatedApps"),
TraceLoggingWideString(settings.startupDisabledReason.c_str(), "StartupDisabledReason"), TraceLoggingWideString(settings.startupDisabledReason.c_str(), "StartupDisabledReason"),
TraceLoggingWideString(enabledModules.c_str(), "ModulesEnabled"), TraceLoggingWideString(enabledModules.c_str(), "ModulesEnabled"),
TraceLoggingBoolean(settings.isRunElevated, "AlwaysRunElevated"), TraceLoggingBoolean(settings.isRunElevated, "AlwaysRunElevated"),

View File

@@ -29,6 +29,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("is_admin")] [JsonPropertyName("is_admin")]
public bool IsAdmin { get; set; } public bool IsAdmin { get; set; }
// Gets or sets a value indicating whether is warnings of elevated apps enabled.
[JsonPropertyName("enable_warnings_elevated_apps")]
public bool EnableWarningsElevatedApps { get; set; }
// Gets or sets theme Name. // Gets or sets theme Name.
[JsonPropertyName("theme")] [JsonPropertyName("theme")]
public string Theme { get; set; } public string Theme { get; set; }
@@ -57,6 +61,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{ {
Startup = false; Startup = false;
IsAdmin = false; IsAdmin = false;
EnableWarningsElevatedApps = true;
IsElevated = false; IsElevated = false;
AutoDownloadUpdates = false; AutoDownloadUpdates = false;
EnableExperimentation = true; EnableExperimentation = true;

View File

@@ -209,6 +209,9 @@
</controls:SettingsCard> </controls:SettingsCard>
</controls:SettingsExpander.Items> </controls:SettingsExpander.Items>
</controls:SettingsExpander> </controls:SettingsExpander>
<controls:SettingsCard x:Uid="GeneralPage_WarningsElevatedApps">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{Binding Mode=TwoWay, Path=EnableWarningsElevatedApps}" />
</controls:SettingsCard>
</custom:SettingsGroup> </custom:SettingsGroup>
<custom:SettingsGroup x:Uid="Appearance_Behavior" IsEnabled="True"> <custom:SettingsGroup x:Uid="Appearance_Behavior" IsEnabled="True">

View File

@@ -1022,6 +1022,12 @@
<data name="GeneralPage_RunAtStartUp.Description" xml:space="preserve"> <data name="GeneralPage_RunAtStartUp.Description" xml:space="preserve">
<value>PowerToys will launch automatically</value> <value>PowerToys will launch automatically</value>
</data> </data>
<data name="GeneralPage_WarningsElevatedApps.Header" xml:space="preserve">
<value>Elevated Apps warnings </value>
</data>
<data name="GeneralPage_WarningsElevatedApps.Description" xml:space="preserve">
<value>Show notifications about PowerToys functionality issues when running alongside elevated applications.</value>
</data>
<data name="PowerRename.ModuleDescription" xml:space="preserve"> <data name="PowerRename.ModuleDescription" xml:space="preserve">
<value>A Windows Shell extension for more advanced bulk renaming using search &amp; replace or regular expressions.</value> <value>A Windows Shell extension for more advanced bulk renaming using search &amp; replace or regular expressions.</value>
</data> </data>

View File

@@ -126,6 +126,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_isElevated = isElevated; _isElevated = isElevated;
_runElevated = GeneralSettingsConfig.RunElevated; _runElevated = GeneralSettingsConfig.RunElevated;
_enableWarningsElevatedApps = GeneralSettingsConfig.EnableWarningsElevatedApps;
RunningAsUserDefaultText = runAsUserText; RunningAsUserDefaultText = runAsUserText;
RunningAsAdminDefaultText = runAsAdminText; RunningAsAdminDefaultText = runAsAdminText;
@@ -150,6 +151,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private bool _isElevated; private bool _isElevated;
private bool _runElevated; private bool _runElevated;
private bool _isAdmin; private bool _isAdmin;
private bool _enableWarningsElevatedApps;
private int _themeIndex; private int _themeIndex;
private bool _autoDownloadUpdates; private bool _autoDownloadUpdates;
@@ -270,6 +272,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
} }
} }
public bool EnableWarningsElevatedApps
{
get
{
return _enableWarningsElevatedApps;
}
set
{
if (_enableWarningsElevatedApps != value)
{
_enableWarningsElevatedApps = value;
GeneralSettingsConfig.EnableWarningsElevatedApps = value;
NotifyPropertyChanged();
}
}
}
// Are we running a dev build? (Please note that we verify this in the code that gets the newest version from GitHub too.) // Are we running a dev build? (Please note that we verify this in the code that gets the newest version from GitHub too.)
public static bool AutoUpdatesDisabledOnDevBuild public static bool AutoUpdatesDisabledOnDevBuild
{ {