Skip to content

Commit

Permalink
[VCM]disable by default and admin warning (#14686)
Browse files Browse the repository at this point in the history
* Adding in InfoBar warning when not running as admin

* small newline text shift

* rolling out a text fix i didn't mean to commit

* defaulting to off, there are other spots is seems like

* [Runner] introduce is_enabled_by_default method and keep VCM disabled by default

* getting file back in good state

Co-authored-by: yuyoyuppe <a.yuyoyuppe@gmail.com>
  • Loading branch information
crutkas and yuyoyuppe committed Dec 7, 2021
1 parent aa376a2 commit 71380d6
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/modules/interface/powertoy_module_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PowertoyModuleIface

std::strong_ordering operator<=>(const Hotkey&) const = default;
};

struct HotkeyEx
{
WORD modifiersMask = 0;
Expand Down Expand Up @@ -98,7 +98,7 @@ class PowertoyModuleIface
*/
virtual bool on_hotkey(size_t hotkeyId) { return false; }

/* These are for enabling the legacy behavior of showing the shortcut guide after pressing the win key.
/* These are for enabling the legacy behavior of showing the shortcut guide after pressing the win key.
* keep_track_of_pressed_win_key returns true if the module wants to keep track of the win key being pressed.
* milliseconds_win_key_must_be_pressed returns the number of milliseconds the win key should be pressed before triggering the module.
* Don't use these for new modules.
Expand All @@ -110,6 +110,8 @@ class PowertoyModuleIface
{
}

virtual bool is_enabled_by_default() const { return true; }

protected:
HANDLE CreateDefaultEvent(const wchar_t* eventName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@ void VideoConferenceModule::destroy()
instance = nullptr;
}

bool VideoConferenceModule::is_enabled_by_default() const
{
return false;
}

void VideoConferenceModule::sendSourceCameraNameUpdate()
{
if (!_settingsUpdateChannel.has_value() || settings.selectedCamera.empty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class VideoConferenceModule : public PowertoyModuleIface
virtual void disable() override;
virtual bool is_enabled() override;
virtual void destroy() override;
virtual bool is_enabled_by_default() const override;

virtual const wchar_t * get_key() override;

Expand Down
31 changes: 17 additions & 14 deletions src/runner/general_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,15 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
}
}

void start_initial_powertoys()
void start_enabled_powertoys()
{
std::unordered_set<std::wstring> powertoys_to_disable;
// Take into account default values supplied by modules themselves
for (auto& [name, powertoy] : modules())
{
if (!powertoy->is_enabled_by_default())
powertoys_to_disable.emplace(name);
}

json::JsonObject general_settings;
try
Expand All @@ -192,9 +198,16 @@ void start_initial_powertoys()
json::JsonObject enabled = general_settings.GetNamedObject(L"enabled");
for (const auto& disabled_element : enabled)
{
std::wstring disable_module_name{ static_cast<std::wstring_view>(disabled_element.Key()) };
// Disable explicitly disabled modules
if (!disabled_element.Value().GetBoolean())
{
powertoys_to_disable.emplace(disabled_element.Key());
powertoys_to_disable.emplace(std::move(disable_module_name));
}
// If module was scheduled for disable, but it's enabled in the settings - override default value
else if (auto it = powertoys_to_disable.find(disable_module_name); it != end(powertoys_to_disable))
{
powertoys_to_disable.erase(it);
}
}
}
Expand All @@ -203,21 +216,11 @@ void start_initial_powertoys()
{
}

if (powertoys_to_disable.empty())
for (auto& [name, powertoy] : modules())
{
for (auto& [name, powertoy] : modules())
if (!powertoys_to_disable.contains(name))
{
powertoy->enable();
}
}
else
{
for (auto& [name, powertoy] : modules())
{
if (powertoys_to_disable.find(name) == powertoys_to_disable.end())
{
powertoy->enable();
}
}
}
}
2 changes: 1 addition & 1 deletion src/runner/general_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ struct GeneralSettings
json::JsonObject load_general_settings();
GeneralSettings get_general_settings();
void apply_general_settings(const json::JsonObject& general_configs, bool save = true);
void start_initial_powertoys();
void start_enabled_powertoys();
2 changes: 1 addition & 1 deletion src/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int runner(bool isProcessElevated, bool openSettings, std::string settingsWindow
}
}
// Start initial powertoys
start_initial_powertoys();
start_enabled_powertoys();

Trace::EventLaunch(get_product_version(), isProcessElevated);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public bool ShortcutGuide
}
}

private bool videoConference = true;
private bool videoConference; // defaulting to off https://github.com/microsoft/PowerToys/issues/14507

[JsonPropertyName("Video Conference")]
public bool VideoConference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1825,4 +1825,7 @@ From there, simply click on a Markdown file, PDF file or SVG icon in the File Ex
<data name="FancyZones_Zone_Appearance.Header" xml:space="preserve">
<value>Zone appearance</value>
</data>
<data name="VideoConference_RunAsAdminRequired.Title" xml:space="preserve">
<value>You need to run as administrator to modify these settings.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d">

<Page.Resources>
<converters:StringVisibilityConverter x:Name="EmptyToCollapsedConverter" EmptyValue="Collapsed" NotEmptyValue="Visible"/>
<converters:BoolToObjectConverter x:Key="BoolToVisibilityConverter" TrueValue="Collapsed" FalseValue="Visible"/>
</Page.Resources>

<controls:SettingsPageControl x:Uid="VideoConference"
ModuleImageSource="ms-appx:///Assets/Modules/VideoConference.png">
<controls:SettingsPageControl.ModuleContent>

<StackPanel Orientation="Vertical">

<muxc:InfoBar
Severity="Warning"
x:Uid="VideoConference_RunAsAdminRequired"
IsOpen="True"
IsTabStop="True"
IsClosable="False"
Visibility="{Binding Mode=OneWay, Path=IsElevated, Converter={StaticResource BoolToVisibilityConverter}}" />
<controls:Setting x:Uid="VideoConference_Enable" IsEnabled="{ Binding Mode=OneWay, Path=IsElevated }">
<controls:Setting.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/FluentIcons/FluentIconsVideoConferenceMute.png" ShowAsMonochrome="False" />
Expand Down

0 comments on commit 71380d6

Please sign in to comment.