Windows - Fix crash when clicking on update notification

Meta - Code cleanup
This commit is contained in:
Robert committed 2022-09-03 10:34:53 +02:00
1 parent cdd814d920
commit 3994b49f08
36 files changed
+201 -193

No files matched your search

+5 -5
View File
@@ -91,11 +91,6 @@ public static class Constants
/// </summary>
public static readonly Plugin CorePlugin = new(CorePluginInfo, new DirectoryInfo(ApplicationFolder), null);
/// <summary>
/// Gets the startup arguments provided to the application
/// </summary>
public static ReadOnlyCollection<string> StartupArguments { get; set; } = null!;
internal static readonly CorePluginFeature CorePluginFeature = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Core")};
internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Effect Placeholder")};
@@ -153,6 +148,11 @@ public static class Constants
typeof(decimal)
};
/// <summary>
/// Gets the startup arguments provided to the application
/// </summary>
public static ReadOnlyCollection<string> StartupArguments { get; set; } = null!;
/// <summary>
/// Gets the graphics context to be used for rendering by SkiaSharp. Can be set via
/// <see cref="IRgbService.UpdateGraphicsContext" />.
@@ -1,20 +1,19 @@
using System;
namespace Artemis.Core
{
/// <summary>
/// Provides data for layer property events.
/// </summary>
public class LayerPropertyKeyframeEventArgs : EventArgs
{
internal LayerPropertyKeyframeEventArgs(ILayerPropertyKeyframe keyframe)
{
Keyframe = keyframe;
}
namespace Artemis.Core;
/// <summary>
/// Gets the keyframe this event is related to
/// </summary>
public ILayerPropertyKeyframe Keyframe { get; }
/// <summary>
/// Provides data for layer property events.
/// </summary>
public class LayerPropertyKeyframeEventArgs : EventArgs
{
internal LayerPropertyKeyframeEventArgs(ILayerPropertyKeyframe keyframe)
{
Keyframe = keyframe;
}
/// <summary>
/// Gets the keyframe this event is related to
/// </summary>
public ILayerPropertyKeyframe Keyframe { get; }
}
+3 -3
View File
@@ -69,16 +69,16 @@ public abstract class BreakableModel : CorePropertyChanged, IBreakableModel
/// <inheritdoc />
public void ClearBrokenState(string state)
{
if (state == null)
if (state == null)
throw new ArgumentNullException(nameof(state));
// If there was no broken state to begin with, done!
if (BrokenState == null)
return;
// Only clear similar broken states
if (BrokenState != state)
return;
BrokenState = null;
BrokenStateException = null;
OnBrokenStateChanged();
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.Services;
@@ -27,7 +26,7 @@ public interface ICoreService : IArtemisService, IDisposable
/// Gets or sets whether profiles are rendered each frame by calling their Render method
/// </summary>
bool ProfileRenderingDisabled { get; set; }
/// <summary>
/// Gets a boolean indicating whether Artemis is running in an elevated environment (admin permissions)
/// </summary>
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Diagnostics;
namespace Artemis.Core.Services;
internal class ProcessComparer : IEqualityComparer<Process>
{
public bool Equals(Process? x, Process? y)
{
if (x == null && y == null) return true;
if (x == null || y == null) return false;
return x.Id == y.Id && x.ProcessName == y.ProcessName && x.SessionId == y.SessionId;
}
public int GetHashCode(Process? obj)
{
if (obj == null) return 0;
return obj.Id;
}
}
@@ -4,7 +4,6 @@ using System.Diagnostics;
using System.Linq;
using System.Timers;
using Artemis.Core.Modules;
using Serilog;
namespace Artemis.Core.Services;
@@ -42,20 +41,4 @@ internal class ProcessMonitorService : IProcessMonitorService
{
return _lastScannedProcesses;
}
}
internal class ProcessComparer : IEqualityComparer<Process>
{
public bool Equals(Process? x, Process? y)
{
if (x == null && y == null) return true;
if (x == null || y == null) return false;
return x.Id == y.Id && x.ProcessName == y.ProcessName && x.SessionId == y.SessionId;
}
public int GetHashCode(Process? obj)
{
if (obj == null) return 0;
return obj.Id;
}
}
@@ -38,6 +38,24 @@ internal class WebServerService : IWebServerService, IDisposable
StartWebServer();
}
public event EventHandler? WebServerStopped;
public event EventHandler? WebServerStarted;
protected virtual void OnWebServerStopped()
{
WebServerStopped?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnWebServerStarting()
{
WebServerStarting?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnWebServerStarted()
{
WebServerStarted?.Invoke(this, EventArgs.Empty);
}
private void WebServerEnabledSettingOnSettingChanged(object? sender, EventArgs e)
{
StartWebServer();
@@ -76,6 +94,7 @@ internal class WebServerService : IWebServerService, IDisposable
public WebServer? Server { get; private set; }
public PluginsModule PluginsModule { get; }
public event EventHandler? WebServerStarting;
#region Web server managament
@@ -129,7 +148,7 @@ internal class WebServerService : IWebServerService, IDisposable
if (!_webServerEnabledSetting.Value)
return;
if (Constants.StartupArguments.Contains("--disable-webserver"))
{
_logger.Warning("Artemis launched with --disable-webserver, not enabling the webserver");
@@ -302,27 +321,4 @@ internal class WebServerService : IWebServerService, IDisposable
}
#endregion
#region Events
protected virtual void OnWebServerStopped()
{
WebServerStopped?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnWebServerStarting()
{
WebServerStarting?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnWebServerStarted()
{
WebServerStarted?.Invoke(this, EventArgs.Empty);
}
public event EventHandler? WebServerStopped;
public event EventHandler? WebServerStarting;
public event EventHandler? WebServerStarted;
#endregion
}
+20 -5
View File
@@ -48,7 +48,7 @@ public readonly struct Numeric : IComparable<Numeric>, IConvertible
{
_value = value;
}
/// <summary>
/// Creates a new instance of <see cref="Numeric" /> from a <see cref="long" />
/// </summary>
@@ -160,10 +160,25 @@ public readonly struct Numeric : IComparable<Numeric>, IConvertible
return (byte) Math.Clamp(p._value, 0, 255);
}
public static implicit operator Numeric(double d) => new(d);
public static implicit operator Numeric(float f) => new(f);
public static implicit operator Numeric(int i) => new(i);
public static implicit operator Numeric(byte b) => new(b);
public static implicit operator Numeric(double d)
{
return new(d);
}
public static implicit operator Numeric(float f)
{
return new(f);
}
public static implicit operator Numeric(int i)
{
return new(i);
}
public static implicit operator Numeric(byte b)
{
return new(b);
}
public static implicit operator long(Numeric p)
{
+5 -3
View File
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace Artemis.Core;
@@ -96,7 +94,7 @@ public sealed class InputPin : Pin
{
if (type == _type)
return;
base.ChangeType(type, ref _type);
Value = type.GetDefault();
}
@@ -111,9 +109,13 @@ public sealed class InputPin : Pin
Value = Type.GetDefault()!;
}
else if (ConnectedTo.Count > 0)
{
Value = ConnectedTo[0].PinValue;
}
else
{
Value = null;
}
}
#endregion
@@ -59,7 +59,7 @@ public interface INode : INotifyPropertyChanged, IBreakableModel
/// Called when the node resets
/// </summary>
event EventHandler Resetting;
/// <summary>
/// Occurs when a pin was added to the node
/// </summary>
@@ -69,7 +69,7 @@ public interface INode : INotifyPropertyChanged, IBreakableModel
/// Occurs when a pin was removed from the node
/// </summary>
event EventHandler<SingleValueEventArgs<IPin>> PinRemoved;
/// <summary>
/// Occurs when a pin collection was added to the node
/// </summary>
@@ -85,7 +85,10 @@ public interface IPin
/// Determines whether this pin is compatible with the given type
/// </summary>
/// <param name="type">The type to check for compatibility</param>
/// <param name="forgivingEnumMatching">A boolean indicating whether or not enums should be exactly equal or just both be enums</param>
/// <param name="forgivingEnumMatching">
/// A boolean indicating whether or not enums should be exactly equal or just both be
/// enums
/// </param>
/// <returns><see langword="true" /> if the type is compatible, otherwise <see langword="false" />.</returns>
public bool IsTypeCompatible(Type type, bool forgivingEnumMatching = true);
}
@@ -26,6 +26,17 @@ internal class DataBindingExitNode<TLayerProperty> : Node, IExitNode
property.SetValue(pendingValue);
}
public override void Evaluate()
{
foreach ((IDataBindingProperty? property, InputPin? inputPin) in _propertyPins)
{
if (inputPin.ConnectedTo.Any())
_propertyValues[property] = inputPin.Value!;
else
_propertyValues.Remove(property);
}
}
private void ClearInputPins()
{
while (Pins.Any())
@@ -59,15 +70,4 @@ internal class DataBindingExitNode<TLayerProperty> : Node, IExitNode
}
public override bool IsExitNode => true;
public override void Evaluate()
{
foreach ((IDataBindingProperty? property, InputPin? inputPin) in _propertyPins)
{
if (inputPin.ConnectedTo.Any())
_propertyValues[property] = inputPin.Value!;
else
_propertyValues.Remove(property);
}
}
}
+2 -2
View File
@@ -97,7 +97,7 @@ public abstract class Node : BreakableModel, INode
/// <inheritdoc />
public override string BrokenDisplayName => Name;
#endregion
#region Construtors
@@ -373,7 +373,7 @@ public abstract class Node : BreakableModel, INode
{
TryOrBreak(Evaluate, "Failed to evaluate");
}
/// <summary>
/// Called whenever the node must show it's custom view model, if <see langword="null" />, no custom view model is used
/// </summary>
+13 -13
View File
@@ -14,6 +14,19 @@ namespace Artemis.Core;
/// </summary>
public abstract class NodeScript : CorePropertyChanged, INodeScript
{
private void NodeTypeStoreOnNodeTypeAdded(object? sender, NodeTypeStoreEvent e)
{
if (Entity.Nodes.Any(n => e.TypeRegistration.MatchesEntity(n)))
Load();
}
private void NodeTypeStoreOnNodeTypeRemoved(object? sender, NodeTypeStoreEvent e)
{
List<INode> nodes = Nodes.Where(n => n.GetType() == e.TypeRegistration.NodeData.Type).ToList();
foreach (INode node in nodes)
RemoveNode(node);
}
/// <inheritdoc />
public event EventHandler<SingleValueEventArgs<INode>>? NodeAdded;
@@ -374,19 +387,6 @@ public abstract class NodeScript : CorePropertyChanged, INodeScript
}
#endregion
private void NodeTypeStoreOnNodeTypeAdded(object? sender, NodeTypeStoreEvent e)
{
if (Entity.Nodes.Any(n => e.TypeRegistration.MatchesEntity(n)))
Load();
}
private void NodeTypeStoreOnNodeTypeRemoved(object? sender, NodeTypeStoreEvent e)
{
List<INode> nodes = Nodes.Where(n => n.GetType() == e.TypeRegistration.NodeData.Type).ToList();
foreach (INode node in nodes)
RemoveNode(node);
}
}
/// <summary>
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace Artemis.Core;
-1
View File
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core.Events;
namespace Artemis.Core;