Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
QOL improvements
Browse files Browse the repository at this point in the history
- InputGrabber: Stop Capture on right click
- InputGrabber: Apply Keyboard name on Enter
- QLC+ Plugin: Refetch scene list when opening slot settings
- Plugins more resistant to errors
  • Loading branch information
CShark committed Sep 13, 2021
1 parent 1c3a746 commit a9918ef
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 22 deletions.
2 changes: 1 addition & 1 deletion StreamDeck/Plugins/Keyboard/InputGrabber.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<StackPanel VerticalAlignment="Center" Margin="15">
<TextBlock Text="{Binding Key}" HorizontalAlignment="Center" />
<TextBlock Text="{Binding ReadableKeyboard}" HorizontalAlignment="Center" Visibility="{Binding EditKeyboardLabel, Converter={StaticResource BoolToVisInv}}" MouseLeftButtonUp="KeyboardLabel_OnMouseLeftButtonUp" PreviewMouseLeftButtonDown="KeyboardLabel_OnPreviewMouseLeftButtonDown"/>
<TextBox Text="{Binding ReadableKeyboard, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding EditKeyboardLabel, Converter={StaticResource BoolToVis}}" x:Name="KeyboardLabelText" LostFocus="KeyboardLabelText_OnLostFocus"/>
<TextBox Text="{Binding ReadableKeyboard, UpdateSourceTrigger=PropertyChanged}" PreviewKeyDown="KeyboardLabelText_OnPreviewKeyDown" Visibility="{Binding EditKeyboardLabel, Converter={StaticResource BoolToVis}}" x:Name="KeyboardLabelText" LostFocus="KeyboardLabelText_OnLostFocus"/>
</StackPanel>
</Grid>
</UserControl>
8 changes: 8 additions & 0 deletions StreamDeck/Plugins/Keyboard/InputGrabber.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Windows.Navigation;
using System.Windows.Shapes;
using KeyboardHooks;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;

namespace StreamDeck.Plugins.Keyboard {
/// <summary>
Expand Down Expand Up @@ -146,6 +147,7 @@ public partial class InputGrabber : UserControl {
}

private void InputGrabber_OnMouseRightButtonUp(object sender, MouseButtonEventArgs e) {
Capturing = false;
Key = null;
Keyboard = null;
}
Expand Down Expand Up @@ -196,5 +198,11 @@ public partial class InputGrabber : UserControl {
if (!Capturing)
e.Handled = true;
}

private void KeyboardLabelText_OnPreviewKeyDown(object sender, KeyEventArgs e) {
if (e.Key == System.Windows.Input.Key.Return) {
EditKeyboardLabel = false;
}
}
}
}
2 changes: 1 addition & 1 deletion StreamDeck/Plugins/qlc/QlcPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class QlcPlugin : PluginBase {
}catch{}
}

private void FetchInfo() {
public void FetchInfo() {
// Grab a list of all available functions and widgets
try {
_functions.Clear();
Expand Down
1 change: 1 addition & 0 deletions StreamDeck/Plugins/qlc/SlotSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public partial class SlotSettings : SlotSettingsControl<QlcSlotSettings> {

public SlotSettings(QlcPlugin plugin, CommandFacade commandFacade, Guid slotID) : base(commandFacade, slotID) {
Plugin = plugin;
plugin.FetchInfo();
InitializeComponent();
}

Expand Down
8 changes: 2 additions & 6 deletions StreamDeck/StreamDeck/Controls/SceneSlot.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,14 @@ public partial class SceneSlot : UserControl {
var config = new SlotConfig(_slot);
config.Owner = Window.GetWindow(this);

foreach (var plugin in _plugins.Plugins.Where(x => x.Active && x.Plugin.State != PluginState.Disabled)) {
plugin.Plugin.PausePlugin(true);
}
_plugins.PausePlugins(null, true);

if (config.ShowDialog() == true) {
LoadSlot();
_owner.PrepareObsMultiview();
}

foreach (var plugin in _plugins.Plugins.Where(x => x.Active && x.Plugin.State != PluginState.Disabled)) {
plugin.Plugin.PausePlugin(false);
}
_plugins.PausePlugins(null, false);
}

private void SceneSlot_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
Expand Down
9 changes: 3 additions & 6 deletions StreamDeck/StreamDeck/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using StreamDeck.Plugins;
using StreamDeck.Services;
using WPFLocalizeExtension.Engine;
using Exception = System.Exception;

namespace StreamDeck {
/// <summary>
Expand Down Expand Up @@ -204,9 +205,7 @@ public partial class MainWindow : Window {
}

if (ctrl != null) {
if (info.Active && info.Plugin.State != PluginState.Disabled) {
info.Plugin.PausePlugin(true);
}
_plugins.PausePlugins(info, true);

ctrl.FetchSettings();
var window = new PluginConfig(ctrl);
Expand All @@ -215,9 +214,7 @@ public partial class MainWindow : Window {
ctrl.WriteSettings();
}

if (info.Active && info.Plugin.State != PluginState.Disabled) {
info.Plugin.PausePlugin(false);
}
_plugins.PausePlugins(info, false);
}
}

Expand Down
49 changes: 41 additions & 8 deletions StreamDeck/StreamDeck/Services/PluginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,44 @@ public class PluginService {
_obs.ObsInitialized += () => {
_logger.LogInformation("Enabling active plugins");
App.Current.Dispatcher.Invoke(() => {
foreach (var plugin in Plugins.Where(x => x.Active))
plugin.Plugin.OnEnabled();
foreach (var plugin in Plugins.Where(x => x.Active)) {
try {
plugin.Plugin.OnEnabled();
} catch (Exception ex) {
_logger.LogError(ex, "Failed to activate plugin " + plugin.Plugin.Name);
}
}
});
};

_obs.ObsDisconnected += () => {
_logger.LogInformation("Disabling running plugins");
App.Current.Dispatcher.Invoke(() => {
foreach (var plugin in Plugins.Where(x => x.Active))
plugin.Plugin.OnDisabled();
foreach (var plugin in Plugins.Where(x => x.Active)) {
try {
plugin.Plugin.OnDisabled();
} catch (Exception ex) {
_logger.LogWarning(ex, $"Deactivating plugin {plugin.Plugin.Name} threw an exception");
}
}
});
};
}

public void PausePlugins(PluginInfo plugin, bool pause) {
var plugins = _availablePlugins
.Where(x => x.Active && x.Plugin.State != PluginState.Disabled)
.Where(x => plugin == null || x == plugin);

foreach (var p in plugins) {
try {
p.Plugin.PausePlugin(pause);
} catch (Exception ex) {
_logger.LogWarning(ex,$"Failed to set pause state of {p.Plugin.Name} to {pause}");
}
}
}

/// <summary>
/// Scan for Plugin implementations
/// </summary>
Expand All @@ -102,7 +126,7 @@ public class PluginService {
if (typeof(PluginBase).IsAssignableFrom(type) && !type.IsAbstract && type.IsPublic) {
try {
var plugin = Activator.CreateInstance(type) as PluginBase;

if (plugin != null) {
_logger.LogDebug("Found Plugin " + plugin.Name);

Expand All @@ -123,14 +147,23 @@ public class PluginService {
_settings.ActivePlugins.Add(plugin.Name);
if (_obs.IsInitialized) {
plugin.OnEnabled();
try {
plugin.OnEnabled();
} catch (Exception ex) {
_logger.LogError(ex, "Failed to activate plugin " + plugin.Name);
}
}
} else {
_logger.LogInformation("Deactivating plugin " + plugin.Name);
_settings.ActivePlugins.Remove(plugin.Name);
if (_obs.IsInitialized) {
plugin.OnDisabled();
try {
plugin.OnDisabled();
} catch (Exception ex) {
_logger.LogWarning(ex,
$"Deactivating plugin {plugin.Name} threw an exception");
}
}
}
};
Expand Down Expand Up @@ -189,7 +222,7 @@ private class CommandFacadeBound : CommandFacade {
}

protected override void WriteSettings(JObject settings, string subtype = null) {
_logger.LogDebug($"Writing settings for subtype {subtype??"(default)"}");
_logger.LogDebug($"Writing settings for subtype {subtype ?? "(default)"}");
subtype = string.IsNullOrWhiteSpace(subtype) ? "" : "." + subtype;
var key = _plugin.Name + subtype;
_settings.PluginSettings[key] = settings;
Expand Down

0 comments on commit a9918ef

Please sign in to comment.