mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Device visualiser - (probably) Fixed a NaN crash
General UI - Apply change in default render scale everywhere Plugin settings - Added restart later option when disabling device providers Plugin settings - Added support for disabling plugins that failed to load
This commit is contained in:
parent
20e6aa1135
commit
c98fc51623
@ -281,6 +281,15 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
// A device provider may be queued for disable on next restart, this undoes that
|
||||
if (plugin is DeviceProvider && plugin.Enabled && !plugin.PluginInfo.Enabled)
|
||||
{
|
||||
plugin.PluginInfo.Enabled = true;
|
||||
plugin.PluginInfo.ApplyToEntity();
|
||||
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.SetEnabled(true, isAutoEnable);
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -312,16 +321,13 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
_logger.Debug("Disabling plugin {pluginInfo}", plugin.PluginInfo);
|
||||
|
||||
// Device providers cannot be disabled at runtime, restart the application
|
||||
// Device providers cannot be disabled at runtime simply queue a disable for next restart
|
||||
if (plugin is DeviceProvider)
|
||||
{
|
||||
// Don't call SetEnabled(false) but simply update enabled state and save it
|
||||
plugin.PluginInfo.Enabled = false;
|
||||
plugin.PluginInfo.ApplyToEntity();
|
||||
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
|
||||
|
||||
_logger.Debug("Shutting down for device provider disable {pluginInfo}", plugin.PluginInfo);
|
||||
ApplicationUtilities.Shutdown(2, true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ namespace Artemis.Core.Services
|
||||
_rgbService = rgbService;
|
||||
_pluginService = pluginService;
|
||||
_surfaceConfigurations = new List<ArtemisSurface>();
|
||||
_renderScaleSetting = settingsService.GetSetting("Core.RenderScale", 1.0);
|
||||
_renderScaleSetting = settingsService.GetSetting("Core.RenderScale", 0.5);
|
||||
|
||||
LoadFromRepository();
|
||||
|
||||
|
||||
@ -142,14 +142,13 @@ namespace Artemis.UI.Shared
|
||||
private static Size ResizeKeepAspect(Size src, double maxWidth, double maxHeight)
|
||||
{
|
||||
double scale;
|
||||
// ??
|
||||
if (double.IsPositiveInfinity(maxWidth) && !double.IsPositiveInfinity(maxHeight))
|
||||
scale = maxHeight / src.Height;
|
||||
else if (!double.IsPositiveInfinity(maxWidth) && double.IsPositiveInfinity(maxHeight))
|
||||
scale = maxWidth / src.Width;
|
||||
else if (double.IsPositiveInfinity(maxWidth) && double.IsPositiveInfinity(maxHeight))
|
||||
return src;
|
||||
|
||||
else
|
||||
scale = Math.Min(maxWidth / src.Width, maxHeight / src.Height);
|
||||
|
||||
return new Size(src.Width * scale, src.Height * scale);
|
||||
|
||||
@ -6,6 +6,9 @@ using Ninject.Parameters;
|
||||
|
||||
namespace Artemis.UI.Shared.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides different ways of showing confirmation dialogs and custom dialogs
|
||||
/// </summary>
|
||||
public interface IDialogService : IArtemisSharedUIService
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@ -132,11 +132,11 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
|
||||
|
||||
public double RenderScale
|
||||
{
|
||||
get => _settingsService.GetSetting("Core.RenderScale", 1.0).Value;
|
||||
get => _settingsService.GetSetting("Core.RenderScale", 0.5).Value;
|
||||
set
|
||||
{
|
||||
_settingsService.GetSetting("Core.RenderScale", 1.0).Value = value;
|
||||
_settingsService.GetSetting("Core.RenderScale", 1.0).Save();
|
||||
_settingsService.GetSetting("Core.RenderScale", 0.5).Value = value;
|
||||
_settingsService.GetSetting("Core.RenderScale", 0.5).Save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -47,6 +47,16 @@
|
||||
Command="{s:Action ShowLoadException}">
|
||||
<TextBlock FontSize="11">LOAD FAILED</TextBlock>
|
||||
</Button>
|
||||
<Button Grid.Column="2" Grid.Row="0"
|
||||
Height="22"
|
||||
Padding="4"
|
||||
Margin="0 -18 0 0"
|
||||
Visibility="{Binding RequiresRestart, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
ToolTip="Click to restart"
|
||||
Command="{s:Action Restart}">
|
||||
<TextBlock FontSize="11">NEEDS RESTART</TextBlock>
|
||||
</Button>
|
||||
|
||||
<TextBlock Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
@ -13,6 +14,7 @@ using Artemis.UI.Shared.Services;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Ninject;
|
||||
using Ninject.Parameters;
|
||||
using Serilog;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
@ -21,6 +23,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
{
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IKernel _kernel;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly ISnackbarMessageQueue _snackbarMessageQueue;
|
||||
private readonly IWindowManager _windowManager;
|
||||
@ -30,6 +33,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
public PluginSettingsViewModel(Plugin plugin,
|
||||
IKernel kernel,
|
||||
ILogger logger,
|
||||
IWindowManager windowManager,
|
||||
IDialogService dialogService,
|
||||
IPluginService pluginService,
|
||||
@ -39,6 +43,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
PluginInfo = plugin.PluginInfo;
|
||||
|
||||
_kernel = kernel;
|
||||
_logger = logger;
|
||||
_windowManager = windowManager;
|
||||
_dialogService = dialogService;
|
||||
_pluginService = pluginService;
|
||||
@ -67,10 +72,11 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
public string Type => Plugin.GetType().BaseType?.Name ?? Plugin.GetType().Name;
|
||||
public bool CanOpenSettings => IsEnabled && Plugin.ConfigurationDialog != null;
|
||||
public bool DisplayLoadFailed => !Enabling && PluginInfo.LoadException != null;
|
||||
public bool RequiresRestart => Plugin.Enabled && !PluginInfo.Enabled;
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => Plugin.Enabled;
|
||||
get => Plugin.PluginInfo.Enabled;
|
||||
set => Task.Run(() => UpdateEnabled(value));
|
||||
}
|
||||
|
||||
@ -113,6 +119,15 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
_dialogService.ShowExceptionDialog("The plugin failed to load: " + PluginInfo.LoadException.Message, PluginInfo.LoadException);
|
||||
}
|
||||
|
||||
public async Task Restart()
|
||||
{
|
||||
_logger.Debug("Restarting for device provider disable {pluginInfo}", Plugin.PluginInfo);
|
||||
|
||||
// Give the logger a chance to write, might not always be enough but oh well
|
||||
await Task.Delay(500);
|
||||
ApplicationUtilities.Shutdown(2, true);
|
||||
}
|
||||
|
||||
private PackIconKind GetIconKind()
|
||||
{
|
||||
if (PluginInfo.Icon != null)
|
||||
@ -143,7 +158,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
private async Task UpdateEnabled(bool enable)
|
||||
{
|
||||
if (Plugin.Enabled == enable)
|
||||
if (IsEnabled == enable)
|
||||
{
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
return;
|
||||
@ -151,16 +166,9 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
if (!enable && Plugin is DeviceProvider)
|
||||
{
|
||||
var confirm = await _dialogService.ShowConfirmDialog(
|
||||
"Disable device provider",
|
||||
"You are disabling a device provider, this requires that Artemis restarts, please confirm."
|
||||
);
|
||||
if (!confirm)
|
||||
{
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
await DisableDeviceProvider();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (enable)
|
||||
{
|
||||
@ -178,14 +186,46 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
finally
|
||||
{
|
||||
Enabling = false;
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
NotifyOfPropertyChange(nameof(DisplayLoadFailed));
|
||||
}
|
||||
}
|
||||
else
|
||||
_pluginService.DisablePlugin(Plugin);
|
||||
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
NotifyOfPropertyChange(nameof(RequiresRestart));
|
||||
NotifyOfPropertyChange(nameof(DisplayLoadFailed));
|
||||
}
|
||||
|
||||
private async Task DisableDeviceProvider()
|
||||
{
|
||||
var restart = false;
|
||||
|
||||
// If any plugin already requires a restart, don't ask the user again
|
||||
var restartQueued = _pluginService.GetAllPluginInfo().Any(p => p.Instance != null && !p.Enabled && p.Instance.Enabled);
|
||||
// If the plugin isn't enabled (load failed), it can be disabled without a restart
|
||||
if (!restartQueued && Plugin.Enabled)
|
||||
{
|
||||
restart = await _dialogService.ShowConfirmDialog(
|
||||
"Disable device provider",
|
||||
"You are disabling a device provider, Artemis has to restart to \r\nfully disable this type of plugin",
|
||||
"Restart now",
|
||||
"Restart later"
|
||||
);
|
||||
}
|
||||
|
||||
_pluginService.DisablePlugin(Plugin);
|
||||
if (restart)
|
||||
{
|
||||
_logger.Debug("Restarting for device provider disable {pluginInfo}", Plugin.PluginInfo);
|
||||
|
||||
// Give the logger a chance to write, might not always be enough but oh well
|
||||
await Task.Delay(500);
|
||||
ApplicationUtilities.Shutdown(2, true);
|
||||
}
|
||||
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
NotifyOfPropertyChange(nameof(RequiresRestart));
|
||||
NotifyOfPropertyChange(nameof(DisplayLoadFailed));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,7 @@ namespace Artemis.UI.Services
|
||||
public Rect GetLayerBounds(Layer layer)
|
||||
{
|
||||
// Adjust the render rectangle for the difference in render scale
|
||||
var renderScale = _settingsService.GetSetting("Core.RenderScale", 1.0).Value;
|
||||
var renderScale = _settingsService.GetSetting("Core.RenderScale", 0.5).Value;
|
||||
return new Rect(
|
||||
layer.Bounds.Left / renderScale * 1,
|
||||
layer.Bounds.Top / renderScale * 1,
|
||||
@ -105,7 +105,7 @@ namespace Artemis.UI.Services
|
||||
/// <inheritdoc />
|
||||
public SKPoint GetScaledPoint(Layer layer, SKPoint point, bool absolute)
|
||||
{
|
||||
var renderScale = _settingsService.GetSetting("Core.RenderScale", 1.0).Value;
|
||||
var renderScale = _settingsService.GetSetting("Core.RenderScale", 0.5).Value;
|
||||
if (absolute)
|
||||
{
|
||||
return new SKPoint(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user