mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Profile editor - Fixed play on focus loss functionality
This commit is contained in:
parent
b82db7f453
commit
563389cab6
@ -321,7 +321,7 @@ public class DeviceVisualizer : Control
|
|||||||
{
|
{
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
}, DispatcherPriority.Background);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -14,6 +14,11 @@ public interface IMainWindowProvider
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
bool IsMainWindowOpen { get; }
|
bool IsMainWindowOpen { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a boolean indicating whether the main window is currently focused
|
||||||
|
/// </summary>
|
||||||
|
bool IsMainWindowFocused { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens the main window
|
/// Opens the main window
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -33,4 +38,14 @@ public interface IMainWindowProvider
|
|||||||
/// Occurs when the main window has been closed
|
/// Occurs when the main window has been closed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler? MainWindowClosed;
|
public event EventHandler? MainWindowClosed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the main window has been focused
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler? MainWindowFocused;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the main window has been unfocused
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler? MainWindowUnfocused;
|
||||||
}
|
}
|
||||||
@ -37,4 +37,14 @@ public interface IMainWindowService : IArtemisSharedUIService
|
|||||||
/// Occurs when the main window has been closed
|
/// Occurs when the main window has been closed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler? MainWindowClosed;
|
public event EventHandler? MainWindowClosed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the main window has been focused
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler? MainWindowFocused;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the main window has been unfocused
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler? MainWindowUnfocused;
|
||||||
}
|
}
|
||||||
@ -15,6 +15,16 @@ internal class MainWindowService : IMainWindowService
|
|||||||
{
|
{
|
||||||
MainWindowClosed?.Invoke(this, EventArgs.Empty);
|
MainWindowClosed?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void OnMainWindowFocused()
|
||||||
|
{
|
||||||
|
MainWindowFocused?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnMainWindowUnfocused()
|
||||||
|
{
|
||||||
|
MainWindowUnfocused?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
private void SyncWithManager()
|
private void SyncWithManager()
|
||||||
{
|
{
|
||||||
@ -43,6 +53,16 @@ internal class MainWindowService : IMainWindowService
|
|||||||
{
|
{
|
||||||
SyncWithManager();
|
SyncWithManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleMainWindowFocused(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
OnMainWindowFocused();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleMainWindowUnfocused(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
OnMainWindowUnfocused();
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsMainWindowOpen { get; private set; }
|
public bool IsMainWindowOpen { get; private set; }
|
||||||
|
|
||||||
@ -54,12 +74,16 @@ internal class MainWindowService : IMainWindowService
|
|||||||
{
|
{
|
||||||
_mainWindowManager.MainWindowOpened -= HandleMainWindowOpened;
|
_mainWindowManager.MainWindowOpened -= HandleMainWindowOpened;
|
||||||
_mainWindowManager.MainWindowClosed -= HandleMainWindowClosed;
|
_mainWindowManager.MainWindowClosed -= HandleMainWindowClosed;
|
||||||
|
_mainWindowManager.MainWindowFocused -= HandleMainWindowFocused;
|
||||||
|
_mainWindowManager.MainWindowUnfocused -= HandleMainWindowUnfocused;
|
||||||
}
|
}
|
||||||
|
|
||||||
_mainWindowManager = mainWindowProvider;
|
_mainWindowManager = mainWindowProvider;
|
||||||
_mainWindowManager.MainWindowOpened += HandleMainWindowOpened;
|
_mainWindowManager.MainWindowOpened += HandleMainWindowOpened;
|
||||||
_mainWindowManager.MainWindowClosed += HandleMainWindowClosed;
|
_mainWindowManager.MainWindowClosed += HandleMainWindowClosed;
|
||||||
|
_mainWindowManager.MainWindowFocused += HandleMainWindowFocused;
|
||||||
|
_mainWindowManager.MainWindowUnfocused += HandleMainWindowUnfocused;
|
||||||
|
|
||||||
// Sync up with the new manager's state
|
// Sync up with the new manager's state
|
||||||
SyncWithManager();
|
SyncWithManager();
|
||||||
}
|
}
|
||||||
@ -76,4 +100,7 @@ internal class MainWindowService : IMainWindowService
|
|||||||
|
|
||||||
public event EventHandler? MainWindowOpened;
|
public event EventHandler? MainWindowOpened;
|
||||||
public event EventHandler? MainWindowClosed;
|
public event EventHandler? MainWindowClosed;
|
||||||
|
|
||||||
|
public event EventHandler? MainWindowFocused;
|
||||||
|
public event EventHandler? MainWindowUnfocused;
|
||||||
}
|
}
|
||||||
@ -16,6 +16,8 @@ public class MainWindow : ReactiveCoreWindow<RootViewModel>
|
|||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
Opened += OnOpened;
|
Opened += OnOpened;
|
||||||
|
Activated += OnActivated;
|
||||||
|
Deactivated += OnDeactivated;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_rootPanel = this.Get<Panel>("RootPanel");
|
_rootPanel = this.Get<Panel>("RootPanel");
|
||||||
_sidebarContentControl = this.Get<ContentControl>("SidebarContentControl");
|
_sidebarContentControl = this.Get<ContentControl>("SidebarContentControl");
|
||||||
@ -42,6 +44,16 @@ public class MainWindow : ReactiveCoreWindow<RootViewModel>
|
|||||||
SetTitleBar(this.Get<Border>("DragHandle"));
|
SetTitleBar(this.Get<Border>("DragHandle"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnActivated(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ViewModel.Focused();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDeactivated(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ViewModel.Unfocused();
|
||||||
|
}
|
||||||
|
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public class VisualEditorViewModel : ActivatableViewModelBase
|
|||||||
.Bind(out ReadOnlyObservableCollection<IVisualizerViewModel> visualizers)
|
.Bind(out ReadOnlyObservableCollection<IVisualizerViewModel> visualizers)
|
||||||
.Subscribe();
|
.Subscribe();
|
||||||
|
|
||||||
Devices = new ObservableCollection<ArtemisDevice>(rgbService.EnabledDevices);
|
Devices = new ObservableCollection<ArtemisDevice>(rgbService.EnabledDevices.OrderBy(d => d.ZIndex));
|
||||||
Visualizers = visualizers;
|
Visualizers = visualizers;
|
||||||
|
|
||||||
this.WhenActivated(d =>
|
this.WhenActivated(d =>
|
||||||
|
|||||||
@ -11,6 +11,7 @@ using Artemis.UI.Screens.ProfileEditor.ProfileTree;
|
|||||||
using Artemis.UI.Screens.ProfileEditor.Properties;
|
using Artemis.UI.Screens.ProfileEditor.Properties;
|
||||||
using Artemis.UI.Screens.ProfileEditor.StatusBar;
|
using Artemis.UI.Screens.ProfileEditor.StatusBar;
|
||||||
using Artemis.UI.Screens.ProfileEditor.VisualEditor;
|
using Artemis.UI.Screens.ProfileEditor.VisualEditor;
|
||||||
|
using Artemis.UI.Shared.Services.MainWindow;
|
||||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using DynamicData;
|
using DynamicData;
|
||||||
@ -23,6 +24,7 @@ public class ProfileEditorViewModel : MainScreenViewModel
|
|||||||
{
|
{
|
||||||
private readonly IProfileEditorService _profileEditorService;
|
private readonly IProfileEditorService _profileEditorService;
|
||||||
private readonly ISettingsService _settingsService;
|
private readonly ISettingsService _settingsService;
|
||||||
|
private readonly IMainWindowService _mainWindowService;
|
||||||
private readonly SourceList<IToolViewModel> _tools;
|
private readonly SourceList<IToolViewModel> _tools;
|
||||||
private DisplayConditionScriptViewModel? _displayConditionScriptViewModel;
|
private DisplayConditionScriptViewModel? _displayConditionScriptViewModel;
|
||||||
private ObservableAsPropertyHelper<ProfileEditorHistory?>? _history;
|
private ObservableAsPropertyHelper<ProfileEditorHistory?>? _history;
|
||||||
@ -43,11 +45,13 @@ public class ProfileEditorViewModel : MainScreenViewModel
|
|||||||
PropertiesViewModel propertiesViewModel,
|
PropertiesViewModel propertiesViewModel,
|
||||||
DisplayConditionScriptViewModel displayConditionScriptViewModel,
|
DisplayConditionScriptViewModel displayConditionScriptViewModel,
|
||||||
StatusBarViewModel statusBarViewModel,
|
StatusBarViewModel statusBarViewModel,
|
||||||
IEnumerable<IToolViewModel> toolViewModels)
|
IEnumerable<IToolViewModel> toolViewModels,
|
||||||
|
IMainWindowService mainWindowService)
|
||||||
: base(hostScreen, "profile-editor")
|
: base(hostScreen, "profile-editor")
|
||||||
{
|
{
|
||||||
_profileEditorService = profileEditorService;
|
_profileEditorService = profileEditorService;
|
||||||
_settingsService = settingsService;
|
_settingsService = settingsService;
|
||||||
|
_mainWindowService = mainWindowService;
|
||||||
|
|
||||||
_tools = new SourceList<IToolViewModel>();
|
_tools = new SourceList<IToolViewModel>();
|
||||||
_tools.AddRange(toolViewModels);
|
_tools.AddRange(toolViewModels);
|
||||||
@ -65,7 +69,16 @@ public class ProfileEditorViewModel : MainScreenViewModel
|
|||||||
_profileConfiguration = profileEditorService.ProfileConfiguration.ToProperty(this, vm => vm.ProfileConfiguration).DisposeWith(d);
|
_profileConfiguration = profileEditorService.ProfileConfiguration.ToProperty(this, vm => vm.ProfileConfiguration).DisposeWith(d);
|
||||||
_history = profileEditorService.History.ToProperty(this, vm => vm.History).DisposeWith(d);
|
_history = profileEditorService.History.ToProperty(this, vm => vm.History).DisposeWith(d);
|
||||||
_suspendedEditing = profileEditorService.SuspendedEditing.ToProperty(this, vm => vm.SuspendedEditing).DisposeWith(d);
|
_suspendedEditing = profileEditorService.SuspendedEditing.ToProperty(this, vm => vm.SuspendedEditing).DisposeWith(d);
|
||||||
|
|
||||||
|
mainWindowService.MainWindowFocused += MainWindowServiceOnMainWindowFocused;
|
||||||
|
mainWindowService.MainWindowUnfocused += MainWindowServiceOnMainWindowUnfocused;
|
||||||
|
|
||||||
|
Disposable.Create(() =>
|
||||||
|
{
|
||||||
|
mainWindowService.MainWindowFocused -= MainWindowServiceOnMainWindowFocused;
|
||||||
|
mainWindowService.MainWindowUnfocused -= MainWindowServiceOnMainWindowUnfocused;
|
||||||
|
}).DisposeWith(d);
|
||||||
|
|
||||||
// Slow and steady wins the race (and doesn't lock up the entire UI)
|
// Slow and steady wins the race (and doesn't lock up the entire UI)
|
||||||
Dispatcher.UIThread.Post(() => StatusBarViewModel = statusBarViewModel, DispatcherPriority.Loaded);
|
Dispatcher.UIThread.Post(() => StatusBarViewModel = statusBarViewModel, DispatcherPriority.Loaded);
|
||||||
Dispatcher.UIThread.Post(() => VisualEditorViewModel = visualEditorViewModel, DispatcherPriority.Loaded);
|
Dispatcher.UIThread.Post(() => VisualEditorViewModel = visualEditorViewModel, DispatcherPriority.Loaded);
|
||||||
@ -152,4 +165,16 @@ public class ProfileEditorViewModel : MainScreenViewModel
|
|||||||
toolViewModel.IsSelected = false;
|
toolViewModel.IsSelected = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MainWindowServiceOnMainWindowFocused(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_settingsService.GetSetting("ProfileEditor.AutoSuspend", true).Value)
|
||||||
|
_profileEditorService.ChangeSuspendedEditing(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindowServiceOnMainWindowUnfocused(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_settingsService.GetSetting("ProfileEditor.AutoSuspend", true).Value)
|
||||||
|
_profileEditorService.ChangeSuspendedEditing(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -157,6 +157,9 @@ public class RootViewModel : ActivatableViewModelBase, IScreen, IMainWindowProvi
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsMainWindowOpen => _lifeTime.MainWindow != null;
|
public bool IsMainWindowOpen => _lifeTime.MainWindow != null;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool IsMainWindowFocused { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void OpenMainWindow()
|
public void OpenMainWindow()
|
||||||
{
|
{
|
||||||
@ -181,12 +184,30 @@ public class RootViewModel : ActivatableViewModelBase, IScreen, IMainWindowProvi
|
|||||||
{
|
{
|
||||||
Dispatcher.UIThread.Post(() => { _lifeTime.MainWindow?.Close(); });
|
Dispatcher.UIThread.Post(() => { _lifeTime.MainWindow?.Close(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Focused()
|
||||||
|
{
|
||||||
|
IsMainWindowFocused = true;
|
||||||
|
OnMainWindowFocused();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Unfocused()
|
||||||
|
{
|
||||||
|
IsMainWindowFocused = false;
|
||||||
|
OnMainWindowUnfocused();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public event EventHandler? MainWindowOpened;
|
public event EventHandler? MainWindowOpened;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public event EventHandler? MainWindowClosed;
|
public event EventHandler? MainWindowClosed;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public event EventHandler? MainWindowFocused;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public event EventHandler? MainWindowUnfocused;
|
||||||
|
|
||||||
protected virtual void OnMainWindowOpened()
|
protected virtual void OnMainWindowOpened()
|
||||||
{
|
{
|
||||||
@ -197,6 +218,16 @@ public class RootViewModel : ActivatableViewModelBase, IScreen, IMainWindowProvi
|
|||||||
{
|
{
|
||||||
MainWindowClosed?.Invoke(this, EventArgs.Empty);
|
MainWindowClosed?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void OnMainWindowFocused()
|
||||||
|
{
|
||||||
|
MainWindowFocused?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnMainWindowUnfocused()
|
||||||
|
{
|
||||||
|
MainWindowUnfocused?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user