mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Started implementing EventAggregator
This commit is contained in:
parent
bf729b64fd
commit
7d6fa17d34
@ -152,6 +152,7 @@
|
||||
<Compile Include="Converters\InverseBooleanConverter.cs" />
|
||||
<Compile Include="Converters\NullToImageConverter.cs" />
|
||||
<Compile Include="Converters\NullToVisibilityConverter.cs" />
|
||||
<Compile Include="Events\MainWindowFocusChangedEvent.cs" />
|
||||
<Compile Include="Utilities\BindableSelectedItemBehavior.cs" />
|
||||
<Compile Include="Utilities\TriggerTracing.cs" />
|
||||
<Compile Include="Exceptions\ArtemisCoreException.cs" />
|
||||
|
||||
14
src/Artemis.UI/Events/MainWindowFocusChangedEvent.cs
Normal file
14
src/Artemis.UI/Events/MainWindowFocusChangedEvent.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.UI.Events
|
||||
{
|
||||
public class MainWindowFocusChangedEvent : EventArgs
|
||||
{
|
||||
public MainWindowFocusChangedEvent(bool isFocused)
|
||||
{
|
||||
IsFocused = isFocused;
|
||||
}
|
||||
|
||||
public bool IsFocused { get; }
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,7 @@ namespace Artemis.UI.Ninject
|
||||
{
|
||||
if (Kernel == null)
|
||||
throw new ArgumentNullException("Kernel shouldn't be null here.");
|
||||
|
||||
|
||||
// Bind all built-in VMs
|
||||
Kernel.Bind(x =>
|
||||
{
|
||||
|
||||
@ -9,6 +9,7 @@ using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Screens.Shared;
|
||||
using Artemis.UI.Screens.SurfaceEditor;
|
||||
@ -19,12 +20,12 @@ using Point = System.Windows.Point;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
{
|
||||
public class ProfileViewModel : ProfileEditorPanelViewModel
|
||||
public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>
|
||||
{
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly TimerUpdateTrigger _updateTrigger;
|
||||
|
||||
public ProfileViewModel(ISurfaceService surfaceService, ISettingsService settingsService)
|
||||
public ProfileViewModel(ISurfaceService surfaceService, ISettingsService settingsService, IEventAggregator eventAggregator)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
Devices = new ObservableCollection<ProfileDeviceViewModel>();
|
||||
@ -248,5 +249,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void Handle(MainWindowFocusChangedEvent message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,15 +9,17 @@
|
||||
xmlns:abstract="clr-namespace:Artemis.Core.Plugins.Abstract;assembly=Artemis.Core"
|
||||
xmlns:screens="clr-namespace:Artemis.UI.Screens"
|
||||
mc:Ignorable="d"
|
||||
Icon="/Artemis.UI;component/Resources/logo-512.png"
|
||||
Title="Artemis"
|
||||
GlowBrush="{DynamicResource AccentColorBrush}"
|
||||
FontFamily="{StaticResource DefaultFont}"
|
||||
Title="Artemis"
|
||||
SaveWindowPosition="True"
|
||||
UseLayoutRounding="True"
|
||||
Deactivated="{s:Action WindowDeactivated}"
|
||||
Activated="{s:Action WindowActivated}"
|
||||
d:DesignHeight="640"
|
||||
d:DesignWidth="1200"
|
||||
d:DataContext="{d:DesignInstance screens:RootViewModel}"
|
||||
SaveWindowPosition="True"
|
||||
Icon="/Artemis.UI;component/Resources/logo-512.png"
|
||||
UseLayoutRounding="True">
|
||||
d:DataContext="{d:DesignInstance screens:RootViewModel}">
|
||||
<metro:MetroWindow.Resources>
|
||||
<Style TargetType="ContentControl" x:Key="InitializingFade">
|
||||
<Style.Triggers>
|
||||
|
||||
@ -4,9 +4,11 @@ using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Home;
|
||||
using Artemis.UI.Screens.News;
|
||||
@ -22,13 +24,19 @@ namespace Artemis.UI.Screens
|
||||
{
|
||||
private readonly ICollection<IScreenViewModel> _artemisViewModels;
|
||||
private readonly IModuleViewModelFactory _moduleViewModelFactory;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IPluginService _pluginService;
|
||||
private bool _lostFocus;
|
||||
|
||||
public RootViewModel(ICollection<IScreenViewModel> artemisViewModels, IPluginService pluginService, IModuleViewModelFactory moduleViewModelFactory)
|
||||
public RootViewModel(ICollection<IScreenViewModel> artemisViewModels,
|
||||
IPluginService pluginService,
|
||||
IModuleViewModelFactory moduleViewModelFactory,
|
||||
IEventAggregator eventAggregator)
|
||||
{
|
||||
_artemisViewModels = artemisViewModels;
|
||||
_pluginService = pluginService;
|
||||
_moduleViewModelFactory = moduleViewModelFactory;
|
||||
_eventAggregator = eventAggregator;
|
||||
|
||||
// Activate the home item
|
||||
ActiveItem = _artemisViewModels.First(v => v.GetType() == typeof(HomeViewModel));
|
||||
@ -127,5 +135,24 @@ namespace Artemis.UI.Screens
|
||||
|
||||
ActiveItemReady = true;
|
||||
}
|
||||
|
||||
public void WindowDeactivated()
|
||||
{
|
||||
var windowState = ((Window) View).WindowState;
|
||||
if (windowState == WindowState.Minimized)
|
||||
return;
|
||||
|
||||
_lostFocus = true;
|
||||
_eventAggregator.Publish(new MainWindowFocusChangedEvent(false));
|
||||
}
|
||||
|
||||
public void WindowActivated()
|
||||
{
|
||||
if (!_lostFocus)
|
||||
return;
|
||||
|
||||
_lostFocus = false;
|
||||
_eventAggregator.Publish(new MainWindowFocusChangedEvent(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user