Skip to content

Commit

Permalink
General module - Decreased active window update rate
Browse files Browse the repository at this point in the history
General module - Added option to disable active window detection
  • Loading branch information
RobertBeekman committed Feb 24, 2021
1 parent 90341c6 commit c86cd39
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance viewModels:PhilipsHueConfigurationViewModel}">
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance viewModels:PhilipsHueConfigurationViewModel}">
<Grid>

<materialDesign:Transitioner SelectedIndex="{Binding WizardPage}" AutoApplyTransitionOrigins="True" >
Expand Down
18 changes: 18 additions & 0 deletions src/Modules/Artemis.Plugins.Modules.General/Bootstrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Artemis.Core;
using Artemis.Plugins.Modules.General.ViewModels;
using Artemis.UI.Shared;

namespace Artemis.Plugins.Modules.General
{
public class Bootstrapper : IPluginBootstrapper
{
public void Enable(Plugin plugin)
{
plugin.ConfigurationDialog = new PluginConfigurationDialog<GeneralModuleConfigurationViewModel>();
}

public void Disable(Plugin plugin)
{
}
}
}
29 changes: 25 additions & 4 deletions src/Modules/Artemis.Plugins.Modules.General/GeneralModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,31 @@ namespace Artemis.Plugins.Modules.General
public class GeneralModule : ProfileModule<GeneralDataModel>
{
private readonly IColorQuantizerService _quantizerService;
private readonly IInputService _inputService;
private readonly PluginSetting<bool> _enableActiveWindow;

public GeneralModule(IColorQuantizerService quantizerService, IInputService inputService)
public GeneralModule(IColorQuantizerService quantizerService, PluginSettings settings)
{
_quantizerService = quantizerService;
_inputService = inputService;
_enableActiveWindow = settings.GetSetting("EnableActiveWindow", true);
}

public override void Enable()
{
_enableActiveWindow.SettingChanged += EnableActiveWindowOnSettingChanged;

DisplayName = "General";
DisplayIcon = "Images/bow.svg";
ExpandsDataModel = true;

ModuleTabs = new List<ModuleTab> {new ModuleTab<GeneralViewModel>("General")};
AddTimedUpdate(TimeSpan.FromMilliseconds(250), _ => UpdateCurrentWindow());

ApplyEnableActiveWindow();
}

public override void Disable()
{
_enableActiveWindow.SettingChanged -= EnableActiveWindowOnSettingChanged;
}

public override void ModuleActivated(bool isOverride)
Expand All @@ -48,7 +54,6 @@ public override void Update(double deltaTime)
{
DataModel.TimeDataModel.CurrentTime = DateTimeOffset.Now;
DataModel.TimeDataModel.TimeSinceMidnight = DateTimeOffset.Now - DateTimeOffset.Now.Date;
UpdateCurrentWindow();
}

public override void Render(double deltaTime, SKCanvas canvas, SKImageInfo canvasInfo)
Expand All @@ -59,6 +64,9 @@ public override void Render(double deltaTime, SKCanvas canvas, SKImageInfo canva

public void UpdateCurrentWindow()
{
if (!_enableActiveWindow.Value)
return;

int processId = WindowUtilities.GetActiveProcessId();
if (DataModel.ActiveWindow == null || DataModel.ActiveWindow.Process.Id != processId)
DataModel.ActiveWindow = new WindowDataModel(Process.GetProcessById(processId), _quantizerService);
Expand All @@ -67,5 +75,18 @@ public void UpdateCurrentWindow()
}

#endregion

private void EnableActiveWindowOnSettingChanged(object? sender, EventArgs e)
{
ApplyEnableActiveWindow();
}

private void ApplyEnableActiveWindow()
{
if (_enableActiveWindow.Value)
ShowProperty(d => d.ActiveWindow);
else
HideProperty(d => d.ActiveWindow);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Artemis.Core;
using Artemis.UI.Shared;

namespace Artemis.Plugins.Modules.General.ViewModels
{
public class GeneralModuleConfigurationViewModel : PluginConfigurationViewModel
{
public GeneralModuleConfigurationViewModel(Plugin plugin, PluginSettings settings) : base(plugin)
{
EnableActiveWindow = settings.GetSetting("EnableActiveWindow", true);
}

public PluginSetting<bool> EnableActiveWindow { get; set; }

protected override void OnInitialActivate()
{
EnableActiveWindow.AutoSave = true;
base.OnInitialActivate();
}

protected override void OnClose()
{
EnableActiveWindow.AutoSave = false;
base.OnClose();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<UserControl x:Class="Artemis.Plugins.Modules.General.Views.GeneralModuleConfigurationView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:viewModels="clr-namespace:Artemis.Plugins.Modules.General.ViewModels"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance viewModels:GeneralModuleConfigurationViewModel}">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Background="{StaticResource MaterialDesignPaper}">
<StackPanel Margin="15" MaxWidth="800">
<!-- General settings -->
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}" Margin="0 15">General</TextBlock>
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch" Margin="0,0,5,0">
<StackPanel Margin="15">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Monitor active window</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" TextWrapping="Wrap">
Enables or disables the active window data model property. <LineBreak />
Data is not stored and is never shared. Disabling this can increase performance
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" IsChecked="{Binding EnableActiveWindow.Value}" />
</StackPanel>
</Grid>
</StackPanel>
</materialDesign:Card>
</StackPanel>
</ScrollViewer>
</UserControl>

0 comments on commit c86cd39

Please sign in to comment.