Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fody NotifyChanged weaver #1997

Merged
merged 4 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project-Aurora/Project-Aurora/ConfigUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using PropertyChanged;

namespace Aurora
{
[DoNotNotify]
partial class ConfigUI : Window, INotifyPropertyChanged
{
Control_Settings settingsControl = new Control_Settings();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Aurora.Profiles;
using Aurora.Utils;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand All @@ -14,6 +15,7 @@

namespace Aurora.Controls {

[DoNotNotify]
public partial class GameStateParameterPicker : UserControl, INotifyPropertyChanged {

public event EventHandler<SelectedPathChangedEventArgs> SelectedPathChanged;
Expand Down
3 changes: 3 additions & 0 deletions Project-Aurora/Project-Aurora/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers GenerateXsd="false" >
<PropertyChanged />
</Weavers>
42 changes: 6 additions & 36 deletions Project-Aurora/Project-Aurora/Profiles/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
using Newtonsoft.Json.Serialization;
using System.Collections.ObjectModel;
using Aurora.Settings;
using System.ComponentModel;

namespace Aurora.Profiles
{
public class LightEventConfig : NotifyPropertyChangedEx
public class LightEventConfig : INotifyPropertyChanged
{
//TODO: Add NotifyPropertyChanged to properties
public string[] ProcessNames { get; set; }

/// <summary>One or more REGULAR EXPRESSIONS that can be used to match the title of an application</summary>
Expand Down Expand Up @@ -50,29 +50,18 @@ public class LightEventConfig : NotifyPropertyChangedEx

public HashSet<Type> ExtraAvailableLayers { get; } = new HashSet<Type>();

protected LightEventType? type = LightEventType.Normal;
public LightEventType? Type
{
get { return type; }
set
{
object old = type;
object newVal = value;
type = value;
InvokePropertyChanged(old, newVal);
}
}

public bool EnableByDefault { get; set; } = true;
public bool EnableOverlaysByDefault { get; set; } = true;

public event PropertyChangedEventHandler PropertyChanged;

public LightEventConfig WithLayer<T>() where T : ILayerHandler {
ExtraAvailableLayers.Add(typeof(T));
return this;
}
}

public class Application : ObjectSettings<ApplicationSettings>, IInit, ILightEvent, IDisposable
public class Application : ObjectSettings<ApplicationSettings>, IInit, ILightEvent, INotifyPropertyChanged, IDisposable
{
#region Public Properties
public bool Initialized { get; protected set; } = false;
Expand All @@ -88,19 +77,6 @@ public class Application : ObjectSettings<ApplicationSettings>, IInit, ILightEve
public Type GameStateType { get { return Config.GameStateType; } }
public bool IsEnabled { get { return Settings.IsEnabled; } }
public bool IsOverlayEnabled { get { return Settings.IsOverlayEnabled; } }
public event PropertyChangedExEventHandler PropertyChanged;
protected LightEventType type;
public LightEventType Type
{
get { return type; }
protected set
{
object old = type;
object newVal = value;
type = value;
InvokePropertyChanged(old, newVal);
}
}
#endregion

#region Internal Properties
Expand All @@ -113,8 +89,7 @@ protected set
internal Dictionary<string, IEffectScript> EffectScripts { get; set; }
#endregion

#region Private Fields/Properties
#endregion
public event PropertyChangedEventHandler PropertyChanged;

public Application(LightEventConfig config)
{
Expand Down Expand Up @@ -152,11 +127,6 @@ protected override void SettingsCreateHook() {
Settings.IsOverlayEnabled = Config.EnableOverlaysByDefault;
}

protected void InvokePropertyChanged(object oldValue, object newValue, [CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedExEventArgs(propertyName, oldValue, newValue));
}

/// <summary>Enables the use of a non-default layer for this application.</summary>
protected void AllowLayer<T>() where T : ILayerHandler => Config.WithLayer<T>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace Aurora.Profiles.EliteDangerous
{
public class EliteDangerousSettings : FirstTimeApplicationSettings
{
private string gamePath = "";

public string GamePath { get { return gamePath; } set { gamePath = value; InvokePropertyChanged(); } }
public string GamePath { get; set; } = "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ namespace Aurora.Profiles.Generic_Application
{
public class GenericApplicationSettings : ApplicationSettings
{
#region Private Properties
private string applicationName = "New Application Profile";
#endregion

#region Public Properties
public string ApplicationName { get { return applicationName; } set { applicationName = value; InvokePropertyChanged(); } }
#endregion
public string ApplicationName { get; set; } = "New Application Profile";

public GenericApplicationSettings()
{
Expand All @@ -24,8 +18,7 @@ public GenericApplicationSettings()

public GenericApplicationSettings(string appname) : base()
{
applicationName = appname;
ApplicationName = appname;
}

}
}
109 changes: 3 additions & 106 deletions Project-Aurora/Project-Aurora/Profiles/LightingStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Windows;
using System.Windows.Data;
using System.Globalization;
using System.ComponentModel;

namespace Aurora.Profiles
{
Expand All @@ -44,10 +45,6 @@ public class LightingStateManager : ObjectSettings<ProfilesManagerSettings>, IIn

public Desktop.Desktop DesktopProfile { get { return (Desktop.Desktop)Events["desktop"]; } }

private List<string> Underlays = new List<string>();
private List<string> Normal = new List<string>();
private List<string> Overlays = new List<string>();

private List<ILightEvent> StartedEvents = new List<ILightEvent>();
private List<ILightEvent> UpdatedEvents = new List<ILightEvent>();

Expand Down Expand Up @@ -176,63 +173,6 @@ public bool RegisterProfile(LightEventConfig config)
return RegisterEvent(new Application(config));
}

private List<string> GetEventTable(LightEventType type)
{
List<string> events;
switch (type)
{
case LightEventType.Normal:
events = Normal;
break;
case LightEventType.Overlay:
events = Overlays;
break;
case LightEventType.Underlay:
events = Underlays;
break;
default:
throw new NotImplementedException();
}
return events;
}

private bool InsertLightEvent(ILightEvent lightEvent, LightEventType? old = null)
{
LightEventType type = lightEvent.Config.Type ?? LightEventType.Normal;
lightEvent.Config.Type = type;

if (old == null)
{
lightEvent.Config.PropertyChanged += LightEvent_PropertyChanged;
}
else
{
var oldEvents = GetEventTable((LightEventType)old);
oldEvents.Remove(lightEvent.Config.ID);
}

var events = GetEventTable(type);

events.Add(lightEvent.Config.ID);

return true;
}

private void LightEvent_PropertyChanged(object sender, PropertyChangedExEventArgs e)
{
ILightEvent lightEvent = (ILightEvent)sender;
if (e.PropertyName.Equals(nameof(LightEventConfig.Type)))
{
LightEventType old = (LightEventType)e.OldValue;
LightEventType newVal = (LightEventType)e.NewValue;

if (!old.Equals(newVal))
{
InsertLightEvent(lightEvent, old);
}
}
}

public bool RegisterEvent(ILightEvent @event)
{
string key = @event.Config.ID;
Expand Down Expand Up @@ -263,8 +203,6 @@ public bool RegisterEvent(ILightEvent @event)
Global.Configuration.ProfileOrder.Add(key);
}

this.InsertLightEvent(@event);

if (Initialized)
@event.Initialize();

Expand Down Expand Up @@ -529,51 +467,10 @@ private void Update()
else
Global.dev_manager.InitializeOnce();

if (Global.Configuration.OverlaysInPreview || !preview)
{
foreach (var underlay in Underlays)
{
ILightEvent @event = Events[underlay];
if (@event.IsEnabled && (@event.Config.ProcessNames == null || ProcessUtils.AnyProcessExists(@event.Config.ProcessNames)))
UpdateEvent(@event, newFrame);
}
}

//Need to do another check in case Desktop is disabled or the selected preview is disabled
if (profile.IsEnabled)
UpdateEvent(profile, newFrame);

if (Global.Configuration.OverlaysInPreview || !preview)
{
// Update any overlays registered in the Overlays array. This includes applications with type set to Overlay and things such as skype overlay
foreach (var overlay in Overlays)
{
ILightEvent @event = Events[overlay];
if (@event.IsEnabled && (@event.Config.ProcessNames == null || ProcessUtils.AnyProcessExists(@event.Config.ProcessNames)))
UpdateEvent(@event, newFrame);
}

// Update any overlays that are timer-based (e.g. the volume overlay that appears for a few seconds at a time)
TimedListObject[] overlay_events = overlays.ToArray();
foreach (TimedListObject evnt in overlay_events)
{
if ((evnt.item as LightEvent).IsEnabled)
UpdateEvent((evnt.item as LightEvent), newFrame);
}

// Update any applications that have overlay layers if that application is open
var events = GetOverlayActiveProfiles().ToList();

//Add the Light event that we're previewing to be rendered as an overlay
if (preview && Global.Configuration.OverlaysInPreview && !events.Contains(profile))
events.Add(profile);

foreach (var @event in events)
@event.UpdateOverlayLights(newFrame);

UpdateIdleEffects(newFrame);
}

Global.effengine.PushFrame(newFrame);

StopUnUpdatedEvents();
Expand All @@ -590,13 +487,13 @@ public ILightEvent GetCurrentProfile(out bool preview) {
preview = false;

//TODO: GetProfile that checks based on event type
if ((tempProfile = GetProfileFromProcessData(process_name, process_title)) != null && tempProfile.Config.Type == LightEventType.Normal && tempProfile.IsEnabled)
if ((tempProfile = GetProfileFromProcessData(process_name, process_title)) != null && tempProfile.IsEnabled)
profile = tempProfile;
else if ((tempProfile = GetProfileFromProcessName(previewModeProfileKey)) != null) //Don't check for it being Enabled as a preview should always end-up with the previewed profile regardless of it being disabled
{
profile = tempProfile;
preview = true;
} else if (Global.Configuration.allow_wrappers_in_background && Global.net_listener != null && Global.net_listener.IsWrapperConnected && ((tempProfile = GetProfileFromProcessName(Global.net_listener.WrappedProcess)) != null) && tempProfile.Config.Type == LightEventType.Normal && tempProfile.IsEnabled)
} else if (Global.Configuration.allow_wrappers_in_background && Global.net_listener != null && Global.net_listener.IsWrapperConnected && ((tempProfile = GetProfileFromProcessName(Global.net_listener.WrappedProcess)) != null) && tempProfile.IsEnabled)
profile = tempProfile;

profile = profile ?? DesktopProfile;
Expand Down
9 changes: 8 additions & 1 deletion Project-Aurora/Project-Aurora/Project-Aurora.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,6 @@
<Compile Include="Settings\Control_ScriptManager.xaml.cs">
<DependentUpon>Control_ScriptManager.xaml</DependentUpon>
</Compile>
<Compile Include="Settings\INotifyPropertyChangedEx.cs" />
<Compile Include="Settings\Keybind.cs" />
<Compile Include="Settings\Layers\Control_GlitchLayer.xaml.cs">
<DependentUpon>Control_GlitchLayer.xaml</DependentUpon>
Expand Down Expand Up @@ -2527,6 +2526,11 @@
<PackageReference Include="DotNetZip">
<Version>1.13.7</Version>
</PackageReference>
<PackageReference Include="Fody">
<Version>6.1.1</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="hidlibrary">
<Version>3.2.46</Version>
</PackageReference>
Expand All @@ -2551,6 +2555,9 @@
<PackageReference Include="Octokit">
<Version>0.47.0</Version>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody">
<Version>3.2.8</Version>
</PackageReference>
<PackageReference Include="RGB.NET.Devices.Asus">
<Version>0.1.32</Version>
</PackageReference>
Expand Down
Loading