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
|
||||
}
|
||||
}, DispatcherPriority.Background);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -14,6 +14,11 @@ public interface IMainWindowProvider
|
||||
/// </summary>
|
||||
bool IsMainWindowOpen { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the main window is currently focused
|
||||
/// </summary>
|
||||
bool IsMainWindowFocused { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Opens the main window
|
||||
/// </summary>
|
||||
@ -33,4 +38,14 @@ public interface IMainWindowProvider
|
||||
/// Occurs when the main window has been closed
|
||||
/// </summary>
|
||||
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
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
protected virtual void OnMainWindowFocused()
|
||||
{
|
||||
MainWindowFocused?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnMainWindowUnfocused()
|
||||
{
|
||||
MainWindowUnfocused?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void SyncWithManager()
|
||||
{
|
||||
@ -43,6 +53,16 @@ internal class MainWindowService : IMainWindowService
|
||||
{
|
||||
SyncWithManager();
|
||||
}
|
||||
|
||||
private void HandleMainWindowFocused(object? sender, EventArgs e)
|
||||
{
|
||||
OnMainWindowFocused();
|
||||
}
|
||||
|
||||
private void HandleMainWindowUnfocused(object? sender, EventArgs e)
|
||||
{
|
||||
OnMainWindowUnfocused();
|
||||
}
|
||||
|
||||
public bool IsMainWindowOpen { get; private set; }
|
||||
|
||||
@ -54,12 +74,16 @@ internal class MainWindowService : IMainWindowService
|
||||
{
|
||||
_mainWindowManager.MainWindowOpened -= HandleMainWindowOpened;
|
||||
_mainWindowManager.MainWindowClosed -= HandleMainWindowClosed;
|
||||
_mainWindowManager.MainWindowFocused -= HandleMainWindowFocused;
|
||||
_mainWindowManager.MainWindowUnfocused -= HandleMainWindowUnfocused;
|
||||
}
|
||||
|
||||
_mainWindowManager = mainWindowProvider;
|
||||
_mainWindowManager.MainWindowOpened += HandleMainWindowOpened;
|
||||
_mainWindowManager.MainWindowClosed += HandleMainWindowClosed;
|
||||
|
||||
_mainWindowManager.MainWindowFocused += HandleMainWindowFocused;
|
||||
_mainWindowManager.MainWindowUnfocused += HandleMainWindowUnfocused;
|
||||
|
||||
// Sync up with the new manager's state
|
||||
SyncWithManager();
|
||||
}
|
||||
@ -76,4 +100,7 @@ internal class MainWindowService : IMainWindowService
|
||||
|
||||
public event EventHandler? MainWindowOpened;
|
||||
public event EventHandler? MainWindowClosed;
|
||||
|
||||
public event EventHandler? MainWindowFocused;
|
||||
public event EventHandler? MainWindowUnfocused;
|
||||
}
|
||||
@ -16,6 +16,8 @@ public class MainWindow : ReactiveCoreWindow<RootViewModel>
|
||||
public MainWindow()
|
||||
{
|
||||
Opened += OnOpened;
|
||||
Activated += OnActivated;
|
||||
Deactivated += OnDeactivated;
|
||||
InitializeComponent();
|
||||
_rootPanel = this.Get<Panel>("RootPanel");
|
||||
_sidebarContentControl = this.Get<ContentControl>("SidebarContentControl");
|
||||
@ -42,6 +44,16 @@ public class MainWindow : ReactiveCoreWindow<RootViewModel>
|
||||
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()
|
||||
{
|
||||
|
||||
@ -34,7 +34,7 @@ public class VisualEditorViewModel : ActivatableViewModelBase
|
||||
.Bind(out ReadOnlyObservableCollection<IVisualizerViewModel> visualizers)
|
||||
.Subscribe();
|
||||
|
||||
Devices = new ObservableCollection<ArtemisDevice>(rgbService.EnabledDevices);
|
||||
Devices = new ObservableCollection<ArtemisDevice>(rgbService.EnabledDevices.OrderBy(d => d.ZIndex));
|
||||
Visualizers = visualizers;
|
||||
|
||||
this.WhenActivated(d =>
|
||||
|
||||
@ -11,6 +11,7 @@ using Artemis.UI.Screens.ProfileEditor.ProfileTree;
|
||||
using Artemis.UI.Screens.ProfileEditor.Properties;
|
||||
using Artemis.UI.Screens.ProfileEditor.StatusBar;
|
||||
using Artemis.UI.Screens.ProfileEditor.VisualEditor;
|
||||
using Artemis.UI.Shared.Services.MainWindow;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Avalonia.Threading;
|
||||
using DynamicData;
|
||||
@ -23,6 +24,7 @@ public class ProfileEditorViewModel : MainScreenViewModel
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly IMainWindowService _mainWindowService;
|
||||
private readonly SourceList<IToolViewModel> _tools;
|
||||
private DisplayConditionScriptViewModel? _displayConditionScriptViewModel;
|
||||
private ObservableAsPropertyHelper<ProfileEditorHistory?>? _history;
|
||||
@ -43,11 +45,13 @@ public class ProfileEditorViewModel : MainScreenViewModel
|
||||
PropertiesViewModel propertiesViewModel,
|
||||
DisplayConditionScriptViewModel displayConditionScriptViewModel,
|
||||
StatusBarViewModel statusBarViewModel,
|
||||
IEnumerable<IToolViewModel> toolViewModels)
|
||||
IEnumerable<IToolViewModel> toolViewModels,
|
||||
IMainWindowService mainWindowService)
|
||||
: base(hostScreen, "profile-editor")
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_settingsService = settingsService;
|
||||
_mainWindowService = mainWindowService;
|
||||
|
||||
_tools = new SourceList<IToolViewModel>();
|
||||
_tools.AddRange(toolViewModels);
|
||||
@ -65,7 +69,16 @@ public class ProfileEditorViewModel : MainScreenViewModel
|
||||
_profileConfiguration = profileEditorService.ProfileConfiguration.ToProperty(this, vm => vm.ProfileConfiguration).DisposeWith(d);
|
||||
_history = profileEditorService.History.ToProperty(this, vm => vm.History).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)
|
||||
Dispatcher.UIThread.Post(() => StatusBarViewModel = statusBarViewModel, DispatcherPriority.Loaded);
|
||||
Dispatcher.UIThread.Post(() => VisualEditorViewModel = visualEditorViewModel, DispatcherPriority.Loaded);
|
||||
@ -152,4 +165,16 @@ public class ProfileEditorViewModel : MainScreenViewModel
|
||||
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 />
|
||||
public bool IsMainWindowOpen => _lifeTime.MainWindow != null;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMainWindowFocused { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void OpenMainWindow()
|
||||
{
|
||||
@ -181,12 +184,30 @@ public class RootViewModel : ActivatableViewModelBase, IScreen, IMainWindowProvi
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => { _lifeTime.MainWindow?.Close(); });
|
||||
}
|
||||
|
||||
public void Focused()
|
||||
{
|
||||
IsMainWindowFocused = true;
|
||||
OnMainWindowFocused();
|
||||
}
|
||||
|
||||
public void Unfocused()
|
||||
{
|
||||
IsMainWindowFocused = false;
|
||||
OnMainWindowUnfocused();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? MainWindowOpened;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? MainWindowClosed;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? MainWindowFocused;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? MainWindowUnfocused;
|
||||
|
||||
protected virtual void OnMainWindowOpened()
|
||||
{
|
||||
@ -197,6 +218,16 @@ public class RootViewModel : ActivatableViewModelBase, IScreen, IMainWindowProvi
|
||||
{
|
||||
MainWindowClosed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnMainWindowFocused()
|
||||
{
|
||||
MainWindowFocused?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnMainWindowUnfocused()
|
||||
{
|
||||
MainWindowUnfocused?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user