Plugins - Implemented enabling/disabling (doesnt work for devices)

Plugins - Disable plugins that caused a crash
Tray icon - Added menu items for quick access
This commit is contained in:
SpoinkyNL committed 2020-03-02 22:15:25 +01:00
1 parent fbc9d20db7
commit 73245a3d4b
29 files changed
+442 -164

No files matched your search

@@ -23,6 +23,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
private readonly ICoreService _coreService;
private readonly List<LayerPropertyViewModel> _layerPropertyViewModels;
private readonly ILayerPropertyVmFactory _layerPropertyVmFactory;
private readonly IPropertyTreeVmFactory _propertyTreeVmFactory;
private readonly IPropertyTimelineVmFactory _propertyTimelineVmFactory;
private readonly IProfileEditorService _profileEditorService;
private readonly ISettingsService _settingsService;
@@ -37,14 +39,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
_coreService = coreService;
_settingsService = settingsService;
_layerPropertyVmFactory = layerPropertyVmFactory;
_propertyTreeVmFactory = propertyTreeVmFactory;
_propertyTimelineVmFactory = propertyTimelineVmFactory;
_layerPropertyViewModels = new List<LayerPropertyViewModel>();
PixelsPerSecond = 31;
PropertyTree = propertyTreeVmFactory.Create(this);
PropertyTimeline = propertyTimelineVmFactory.Create(this);
PopulateProperties(_profileEditorService.SelectedProfileElement, null);
}
}
public bool Playing { get; set; }
public bool RepeatAfterLastKeyframe { get; set; }
@@ -71,6 +71,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
protected override void OnInitialActivate()
{
PropertyTree = _propertyTreeVmFactory.Create(this);
PropertyTimeline = _propertyTimelineVmFactory.Create(this);
PopulateProperties(_profileEditorService.SelectedProfileElement, null);
_profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
_profileEditorService.CurrentTimeChanged += ProfileEditorServiceOnCurrentTimeChanged;
-1
View File
@@ -2,7 +2,6 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Artemis.Core.Services;
using Artemis.UI.Events;
using Artemis.UI.Screens.Sidebar;
using Artemis.UI.Utilities;
@@ -186,10 +186,9 @@ namespace Artemis.UI.Screens.Settings
foreach (var device in _surfaceService.ActiveSurface.Devices)
DeviceSettingsViewModels.Add(_deviceSettingsVmFactory.Create(device));
// TODO: GetPluginsOfType isn't ideal here as it doesn't include disabled plugins
Plugins.Clear();
foreach (var plugin in _pluginService.GetPluginsOfType<Plugin>())
Plugins.Add(new PluginSettingsViewModel(plugin, _windowManager, _dialogService));
foreach (var pluginInfo in _pluginService.GetAllPluginInfo())
Plugins.Add(new PluginSettingsViewModel(pluginInfo.Instance, _windowManager, _dialogService, _pluginService));
base.OnInitialActivate();
}
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Shared.Services.Interfaces;
using Stylet;
@@ -10,21 +11,27 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
{
private readonly IDialogService _dialogService;
private readonly Plugin _plugin;
private readonly IPluginService _pluginService;
private readonly IWindowManager _windowManager;
public PluginSettingsViewModel(Plugin plugin, IWindowManager windowManager, IDialogService dialogService)
public PluginSettingsViewModel(Plugin plugin, IWindowManager windowManager, IDialogService dialogService, IPluginService pluginService)
{
_plugin = plugin;
_windowManager = windowManager;
_dialogService = dialogService;
IsEnabled = true;
_pluginService = pluginService;
}
public string Type => _plugin.GetType().BaseType?.Name ?? _plugin.GetType().Name;
public string Name => _plugin.PluginInfo.Name;
public string Description => _plugin.PluginInfo.Description;
public Version Version => _plugin.PluginInfo.Version;
public bool IsEnabled { get; set; }
public bool IsEnabled
{
get => _plugin.PluginInfo.Enabled;
set => Task.Run(() => UpdateEnabled(value));
}
public bool CanOpenSettings => IsEnabled && _plugin.HasConfigurationViewModel;
@@ -42,5 +49,16 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
throw;
}
}
private void UpdateEnabled(in bool enable)
{
if (_plugin.PluginInfo.Enabled == enable)
return;
if (enable)
_pluginService.EnablePlugin(_plugin);
else
_pluginService.DisablePlugin(_plugin);
}
}
}
@@ -25,7 +25,7 @@
</ComboBox>
</StackPanel>
<controls:SideNavigation Items="{Binding SidebarItems}" WillSelectNavigationItemCommand="{s:Action SelectItem}" />
<controls:SideNavigation Items="{Binding SidebarItems}" SelectedItem="{Binding SelectedItem}" WillSelectNavigationItemCommand="{s:Action SelectItem}" />
</StackPanel>
</UserControl>
@@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
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;
@@ -18,13 +19,13 @@ using Stylet;
namespace Artemis.UI.Screens.Sidebar
{
public class SidebarViewModel : PropertyChangedBase
public class SidebarViewModel : PropertyChangedBase, IHandle<RequestSelectSidebarItemEvent>
{
private readonly IKernel _kernel;
private readonly IModuleVmFactory _moduleVmFactory;
private readonly IPluginService _pluginService;
public SidebarViewModel(IKernel kernel, IModuleVmFactory moduleVmFactory, IPluginService pluginService)
public SidebarViewModel(IKernel kernel, IEventAggregator eventAggregator, IModuleVmFactory moduleVmFactory, IPluginService pluginService)
{
_kernel = kernel;
_moduleVmFactory = moduleVmFactory;
@@ -36,6 +37,8 @@ namespace Artemis.UI.Screens.Sidebar
SetupSidebar();
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
eventAggregator.Subscribe(this);
}
public BindableCollection<INavigationItem> SidebarItems { get; set; }
@@ -66,53 +69,6 @@ namespace Artemis.UI.Screens.Sidebar
Task.Run(() => SelectSidebarItem(SidebarItems[1]));
}
private async Task SelectSidebarItem(INavigationItem sidebarItem)
{
// A module was selected if the dictionary contains the selected item
if (SidebarModules.ContainsKey(sidebarItem))
await ActivateModule(sidebarItem);
else if (sidebarItem is FirstLevelNavigationItem navigationItem)
{
if (navigationItem.Label == "Home")
await ActivateViewModel<HomeViewModel>();
else if (navigationItem.Label == "News")
await ActivateViewModel<NewsViewModel>();
else if (navigationItem.Label == "Workshop")
await ActivateViewModel<WorkshopViewModel>();
else if (navigationItem.Label == "Surface Editor")
await ActivateViewModel<SurfaceEditorViewModel>();
else if (navigationItem.Label == "Settings")
await ActivateViewModel<SettingsViewModel>();
}
else if (await CloseCurrentItem())
SelectedItem = null;
}
private async Task<bool> CloseCurrentItem()
{
if (SelectedItem == null)
return true;
var canClose = await SelectedItem.CanCloseAsync();
if (!canClose)
return false;
SelectedItem.Close();
return true;
}
private async Task ActivateViewModel<T>()
{
if (await CloseCurrentItem())
SelectedItem = (IScreen) _kernel.Get<T>();
}
private async Task ActivateModule(INavigationItem sidebarItem)
{
if (await CloseCurrentItem())
SelectedItem = SidebarModules.ContainsKey(sidebarItem) ? _moduleVmFactory.Create(SidebarModules[sidebarItem]) : null;
}
// ReSharper disable once UnusedMember.Global - Called by view
public async Task SelectItem(WillSelectNavigationItemEventArgs args)
{
@@ -151,6 +107,56 @@ namespace Artemis.UI.Screens.Sidebar
SidebarModules.Remove(existing.Key);
}
private async Task SelectSidebarItem(INavigationItem sidebarItem)
{
// A module was selected if the dictionary contains the selected item
if (SidebarModules.ContainsKey(sidebarItem))
await ActivateModule(sidebarItem);
else if (sidebarItem is FirstLevelNavigationItem navigationItem)
await ActivateViewModel(navigationItem.Label);
else if (await CloseCurrentItem())
SelectedItem = null;
}
private async Task<bool> CloseCurrentItem()
{
if (SelectedItem == null)
return true;
var canClose = await SelectedItem.CanCloseAsync();
if (!canClose)
return false;
SelectedItem.Close();
return true;
}
private async Task ActivateViewModel(string label)
{
if (label == "Home")
await ActivateViewModel<HomeViewModel>();
else if (label == "News")
await ActivateViewModel<NewsViewModel>();
else if (label == "Workshop")
await ActivateViewModel<WorkshopViewModel>();
else if (label == "Surface Editor")
await ActivateViewModel<SurfaceEditorViewModel>();
else if (label == "Settings")
await ActivateViewModel<SettingsViewModel>();
}
private async Task ActivateViewModel<T>()
{
if (await CloseCurrentItem())
SelectedItem = (IScreen) _kernel.Get<T>();
}
private async Task ActivateModule(INavigationItem sidebarItem)
{
if (await CloseCurrentItem())
SelectedItem = SidebarModules.ContainsKey(sidebarItem) ? _moduleVmFactory.Create(SidebarModules[sidebarItem]) : null;
}
#region Event handlers
private void PluginServiceOnPluginEnabled(object sender, PluginEventArgs e)
@@ -165,6 +171,11 @@ namespace Artemis.UI.Screens.Sidebar
RemoveModule(module);
}
public void Handle(RequestSelectSidebarItemEvent message)
{
Execute.OnUIThread(async () => await ActivateViewModel(message.Label));
}
#endregion
}
}
+22 -2
View File
@@ -20,9 +20,29 @@
DoubleClickCommand="{s:Action TrayBringToForeground}">
<tb:TaskbarIcon.ContextMenu>
<ContextMenu>
<MenuItem Header="Bring to foreground" Command="{s:Action TrayBringToForeground}">
<MenuItem Header="Home" Command="{s:Action TrayActivateSidebarItem}" CommandParameter="Home">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ArrangeBringToFront" />
<materialDesign:PackIcon Kind="Home" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="News" Command="{s:Action TrayActivateSidebarItem}" CommandParameter="News">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Newspaper" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Workshop" Command="{s:Action TrayActivateSidebarItem}" CommandParameter="Workshop">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="TestTube" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Surface Editor" Command="{s:Action TrayActivateSidebarItem}" CommandParameter="Surface Editor">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Edit" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Settings" Command="{s:Action TrayActivateSidebarItem}" CommandParameter="Settings">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Settings" />
</MenuItem.Icon>
</MenuItem>
<Separator />
+17 -7
View File
@@ -1,6 +1,7 @@
using System.Windows;
using Artemis.Core.Services;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Events;
using Artemis.UI.Screens.Splash;
using Ninject;
using Stylet;
@@ -9,15 +10,16 @@ namespace Artemis.UI.Screens
{
public class TrayViewModel : Screen
{
private readonly ICoreService _coreService;
private readonly IKernel _kernel;
private readonly IWindowManager _windowManager;
private readonly IEventAggregator _eventAggregator;
private SplashViewModel _splashViewModel;
public TrayViewModel(IKernel kernel, IWindowManager windowManager, ICoreService coreService, ISettingsService settingsService)
public TrayViewModel(IKernel kernel, IWindowManager windowManager, IEventAggregator eventAggregator, ICoreService coreService, ISettingsService settingsService)
{
_kernel = kernel;
_windowManager = windowManager;
_coreService = coreService;
_eventAggregator = eventAggregator;
CanShowRootViewModel = true;
var autoRunning = Bootstrapper.StartupArguments.Contains("-autorun");
@@ -25,7 +27,7 @@ namespace Artemis.UI.Screens
if (!autoRunning || showOnAutoRun)
{
ShowSplashScreen();
_coreService.Initialized += (sender, args) => TrayBringToForeground();
coreService.Initialized += (sender, args) => TrayBringToForeground();
}
}
@@ -35,16 +37,24 @@ namespace Artemis.UI.Screens
{
if (!CanShowRootViewModel)
return;
CanShowRootViewModel = false;
CanShowRootViewModel = false;
Execute.OnUIThread(() =>
{
_splashViewModel?.RequestClose();
_splashViewModel = null;
var rootViewModel = _kernel.Get<RootViewModel>();
rootViewModel.Closed += RootViewModelOnClosed;
_windowManager.ShowWindow(rootViewModel);
});
}
public void TrayActivateSidebarItem(string sidebarItem)
{
TrayBringToForeground();
_eventAggregator.Publish(new RequestSelectSidebarItemEvent(sidebarItem));
}
public void TrayExit()
{
Application.Current.Shutdown();
@@ -54,8 +64,8 @@ namespace Artemis.UI.Screens
{
Execute.OnUIThread(() =>
{
var splashViewModel = _kernel.Get<SplashViewModel>();
_windowManager.ShowWindow(splashViewModel);
_splashViewModel = _kernel.Get<SplashViewModel>();
_windowManager.ShowWindow(_splashViewModel);
});
}