Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to disable theme switching while certain processes are running #734

Merged
merged 6 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 73 additions & 1 deletion AutoDarkModeApp/Pages/PageSwitchModes.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
Background="{DynamicResource Win11Border}" />

<DockPanel LastChildFill="false"
Margin="0,5,0,0">
Margin="0,5,0,10">
<TextBlock Margin="0,10,0,0"
VerticalAlignment="Center"
Text="{x:Static p:Resources.SwitchModesTextBlockGPUUsageDetectionSpeed}"
Expand All @@ -109,7 +109,79 @@
</ComboBox>
</DockPanel>

<Separator Margin="-30,0,-15,0"
Background="{DynamicResource Win11Border}" />

<DockPanel
Margin="0,5,0,0"
LastChildFill="false">
<TextBlock FontSize="14"
Text="{x:Static p:Resources.SwitchModesTextProcessBlockList}"
VerticalAlignment="Center"
Margin="0,10,0,0" />

</DockPanel>

<DockPanel Margin="0,10,0,0">
<Expander
DockPanel.Dock="Bottom"
FlowDirection="RightToLeft"
Header="{x:Static p:Resources.SwitchModesExpanderHeaderBlockedProcesses}"
HorizontalAlignment="Stretch"
Margin="0,10,0,10">
<Expander.HeaderTemplate>
<DataTemplate>
<!--Unsure why the negative left margin is necessary here,
pohuing marked this conversation as resolved.
Show resolved Hide resolved
removing it cuts off the leading character-->
<TextBlock
FlowDirection="LeftToRight"
Margin="-21,0,0,0"
Text="{Binding RelativeSource={RelativeSource AncestorType=Expander}, Path=Header}"
Width="{Binding RelativeSource={RelativeSource AncestorType=Expander}, Path=ActualWidth}">
</TextBlock>
</DataTemplate>
</Expander.HeaderTemplate>

<ItemsControl
Margin="0,5,0,0"
Name="ItemsControlProcessBlockList">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel
FlowDirection="LeftToRight"
HorizontalAlignment="Stretch"
LastChildFill="False"
Margin="0,5,0,5"
VerticalAlignment="Center">
<TextBlock
Text="{Binding}"
VerticalAlignment="Center" />
<Button
Click="SwitchModesRemoveProcess_OnClick"
Content="{x:Static p:Resources.SwitchModesButtonRemoveProcess}"
DockPanel.Dock="Right"
Tag="{Binding}"/>
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Expander>

<Button
Click="SwitchModesAddSelectedProcess_OnClick"
Content="{x:Static p:Resources.SwitchModesButtonAddProcess}"
DockPanel.Dock="Right"
HorizontalAlignment="Right"
VerticalAlignment="Center"/>

<ComboBox
DockPanel.Dock="Right"
IsReadOnly="True"
Margin="0,5,0,0"
MinWidth="250"
Name="ComboBoxProcessBlockList">
</ComboBox>
</DockPanel>
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
</uc:Card>
Expand Down
61 changes: 60 additions & 1 deletion AutoDarkModeApp/Pages/PageSwitchModes.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#endregion
using AutoDarkModeLib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -105,6 +106,9 @@ public PageSwitchModes()
ToggleHotkeys.IsOn = builder.Config.Hotkeys.Enabled;
TextBlockHotkeyEditHint.Visibility = ToggleHotkeys.IsOn ? Visibility.Visible : Visibility.Hidden;

ItemsControlProcessBlockList.ItemsSource = builder.Config.ProcessBlockList.ProcessNames;
ComboBoxProcessBlockList.DropDownOpened += (sender, args) => RefreshProcessComboBox();

init = false;
}

Expand Down Expand Up @@ -490,5 +494,60 @@ private void HotkeyCheckboxTogglePostpone_Click(object sender, RoutedEventArgs e
ShowErrorMessage(ex, "HotkeyCheckboxToggleAutomaticThemeSwitchNotification_Click");
}
}

private void SwitchModesAddSelectedProcess_OnClick(object sender, RoutedEventArgs e)
{
if (ComboBoxProcessBlockList.SelectedItem is not string processName ||
builder.Config.ProcessBlockList.ProcessNames.Contains(processName)) return;

builder.Config.ProcessBlockList.ProcessNames.Add(processName);
try
{
builder.Save();
ItemsControlProcessBlockList.Items.Refresh();
}
catch (Exception ex)
{
ShowErrorMessage(ex, "SwitchModesAddSelectedProcess_OnClick");
}
}

private void RefreshProcessComboBox()
{
var processes = Process.GetProcesses();
var filteredProcesses = new SortedSet<string>();
foreach (var process in processes)
{
// MainWindowHandle can throw exceptions, hence the try catch
try
{
// A process without a main window handle probably isn't interactive and thus irrelevant to theme changes
if (process.MainWindowHandle == -0) continue;
// No point in showing a process' name in the dropdown if it's already being excluded out
if (!builder.Config.ProcessBlockList.ProcessNames.Contains(process.ProcessName))
{
filteredProcesses.Add(process.ProcessName);
}
}
catch (Exception ex)
{
ShowErrorMessage(ex, "RefreshProcessComboBox");
}
}

ComboBoxProcessBlockList.ItemsSource = filteredProcesses;
}

private void SwitchModesRemoveProcess_OnClick(object sender, RoutedEventArgs e)
{
if (sender is Button {Tag: string entry})
{
var result = builder.Config.ProcessBlockList.ProcessNames.Remove(entry);
if (result)
{
ItemsControlProcessBlockList.Items.Refresh();
}
}
}
}
}
}
7 changes: 7 additions & 0 deletions AutoDarkModeLib/Configs/AdmConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public AdmConfig()
Location = new();
Tunable = new();
GPUMonitoring = new();
ProcessBlockList = new();
Events = new();
WindowsThemeMode = new();
Updater = new();
Expand Down Expand Up @@ -65,6 +66,7 @@ public AdmConfig()
public Location Location { get; set; }
public Tunable Tunable { get; set; }
public GPUMonitoring GPUMonitoring { get; set; }
public ProcessBlockList ProcessBlockList { get; set; }
public Events Events { get; set; }
public Notifications Notifications { get; set; }
public AutoSwitchNotify AutoSwitchNotify { get; set; }
Expand Down Expand Up @@ -221,4 +223,9 @@ public int Samples
}
}
}

public class ProcessBlockList
{
public SortedSet<string> ProcessNames { get; set; } = new SortedSet<string>();
}
}
37 changes: 36 additions & 1 deletion AutoDarkModeLib/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.cs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1234,4 +1234,7 @@ On rare occasions, Windows may emit a beeping sound when the mouse is moved duri
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
12 changes: 12 additions & 0 deletions AutoDarkModeLib/Properties/Resources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,16 @@ In einigen Fällen kann ein Piepston auftauchen, wenn die Maus während der DWM
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Wechsle nicht wenn eine der folgenden Anwendungen ausgeführt werden</value>
</data>
<data name="SwitchModesButtonAddProcess" xml:space="preserve">
<value>Hinzufügen</value>
</data>
<data name="SwitchModesButtonRemoveProcess" xml:space="preserve">
<value>Entfernen</value>
</data>
<data name="SwitchModesExpanderHeaderBlockedProcesses" xml:space="preserve">
<value>Anwendungen</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.el-gr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,7 @@
<data name="Manual" xml:space="preserve">
<value>Χειροκίνητα</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,7 @@ En casos excepcionales, Windows puede emitir un pitido cuando se mueve el mouse
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.fa.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,7 @@ On rare occasions, Windows may emit a beeping sound when the mouse is moved duri
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,7 @@ Dans de rares cas, Windows peut émettre un bip sonore lorsque la souris est dé
<data name="Manual" xml:space="preserve">
<value>Manuel</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.he.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,7 @@ On rare occasions, Windows may emit a beeping sound when the mouse is moved duri
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.hu.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,7 @@ On rare occasions, Windows may emit a beeping sound when the mouse is moved duri
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.id.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,7 @@ Pada kesempatan yang jarang terjadi, Windows dapat mengeluarkan suara bip ketika
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.it.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,7 @@ On rare occasions, Windows may emit a beeping sound when the mouse is moved duri
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,7 @@ Auto Dark Mode のリポジトリに issue (問題) を投稿しますか?
<data name="Manual" xml:space="preserve">
<value>手動</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.ko.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1234,4 +1234,7 @@ On rare occasions, Windows may emit a beeping sound when the mouse is moved duri
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.nb-no.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1215,4 +1215,7 @@ On rare occasions, Windows may emit a beeping sound when the mouse is moved duri
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AutoDarkModeLib/Properties/Resources.nl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,7 @@ Zelden kan Windows een piepgeluid afspelen wanneer de muis wordt bewogen tijdens
<data name="Manual" xml:space="preserve">
<value>Manual</value>
</data>
<data name="SwitchModesTextProcessBlockList" xml:space="preserve">
<value>Don't switch themes if any of these processes are running</value>
</data>
</root>
Loading