Skip to content

Commit

Permalink
Add a way to identify profile via process name and title - Fixes #1923
Browse files Browse the repository at this point in the history
Cleanup process requirements for Minecraft
  • Loading branch information
stuntguy3000 committed Feb 29, 2020
1 parent 3e60355 commit 99e49ef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion Project-Aurora/Project-Aurora/Profiles/LightingStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,31 @@ public void RemoveGenericProfile(string key)
}
}

// Used to match a process's name and optional window title to a profile
public ILightEvent GetProfileFromProcessData(string processName, string processTitle = null)
{
var processNameProfile = GetProfileFromProcessName(processName);

if (processNameProfile == null)
return null;

// Is title matching required?
if (processNameProfile.Config.ProcessTitles != null)
{
var processTitleProfile = GetProfileFromProcessTitle(processTitle);

if (processTitleProfile != null && processTitleProfile.Equals(processNameProfile))
{
return processTitleProfile;
}
} else
{
return processNameProfile;
}

return null;
}

public ILightEvent GetProfileFromProcessName(string process)
{
if (EventProcesses.ContainsKey(process))
Expand Down Expand Up @@ -686,7 +711,7 @@ public ILightEvent GetCurrentProfile(out bool preview) {
preview = false;

//TODO: GetProfile that checks based on event type
if ((((tempProfile = GetProfileFromProcessName(process_name)) != null) || ((tempProfile = GetProfileFromProcessTitle(process_title)) != null)) && tempProfile.Config.Type == LightEventType.Normal && tempProfile.IsEnabled)
if ((tempProfile = GetProfileFromProcessData(process_name, process_title)) != null && tempProfile.Config.Type == LightEventType.Normal && 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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class Minecraft : Application {
public Minecraft() : base(new LightEventConfig {
Name = "Minecraft",
ID = "minecraft",
//ProcessNames = new[] { "java.exe", "javaw.exe" },
ProcessTitles = new[] { @"^Minecraft\*? [0-9.]*" }, // Match anything that has a title like "Minecraft* 1.12.2" or "Minecraft 1.5"
ProcessNames = new[] { "javaw.exe" }, // Require the process to a Java application
ProcessTitles = new[] { @"^Minecraft" }, // Match any window title that starts with Minecraft
ProfileType = typeof(MinecraftProfile),
OverviewControlType = typeof(Control_Minecraft),
GameStateType = typeof(GSI.GameState_Minecraft),
Expand Down

0 comments on commit 99e49ef

Please sign in to comment.