Skip to content

Commit aee6fe0

Browse files
committed
1.7.13
[New] - Added support for Hosted UWP apps (e.g. Netflix) [Bug fixes] - All Displays selection didn't worked in some situations
1 parent e061e15 commit aee6fe0

File tree

10 files changed

+220
-79
lines changed

10 files changed

+220
-79
lines changed

Source/HDRProfile/Applications/ApplicationItem.cs

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ namespace AutoHDR
2121
public class ApplicationItem : BaseViewModel, IEquatable<ApplicationItem>
2222
{
2323
private bool _isUWP = false;
24+
private bool _isUWPWebApp = false;
25+
2426
private string displayName;
2527
private string _applicationFilePath;
2628
private string _applicationName;
2729
private System.Drawing.Bitmap icon = null;
2830
//private bool _restartProcess = false;
29-
private string _uwpFamilyPackageName;
30-
private string _uwpApplicationID;
31-
private string _uwpIconPath;
31+
private string _uwpFamilyPackageName = string.Empty;
32+
private string _uwpApplicationID = string.Empty;
33+
private string _uwpIconPath = string.Empty;
34+
private string _uwpIdentity = string.Empty;
35+
3236

3337
[JsonProperty]
3438
public string DisplayName { get => displayName; set { displayName = value; OnPropertyChanged(); } }
@@ -39,15 +43,18 @@ public class ApplicationItem : BaseViewModel, IEquatable<ApplicationItem>
3943
// public bool RestartProcess { get => _restartProcess; set { _restartProcess = value; OnPropertyChanged(); } }
4044
[JsonProperty]
4145
public bool IsUWP { get => _isUWP; set { _isUWP = value; OnPropertyChanged(); } }
42-
46+
[JsonProperty]
47+
public bool IsUWPWepApp { get => _isUWPWebApp; set { _isUWPWebApp = value; OnPropertyChanged(); } }
4348
public Bitmap Icon { get => icon; set { icon = value; OnPropertyChanged(); } }
4449
[JsonProperty]
4550
public string UWPFamilyPackageName { get => _uwpFamilyPackageName; set { _uwpFamilyPackageName = value; OnPropertyChanged(); } }
4651
[JsonProperty]
4752
public string UWPApplicationID { get => _uwpApplicationID; set { _uwpApplicationID = value; OnPropertyChanged(); } }
4853
[JsonProperty]
4954
public string UWPIconPath { get => _uwpIconPath; set { _uwpIconPath = value; try { Icon = new Bitmap(Bitmap.FromFile(value)); } catch { }OnPropertyChanged(); } }
50-
55+
56+
[JsonProperty]
57+
public string UWPIdentity { get => _uwpIdentity; set { _uwpIdentity = value; OnPropertyChanged(); } }
5158

5259
private ApplicationItem()
5360
{
@@ -60,38 +67,18 @@ public ApplicationItem(string displayName, string applicationFilePath)
6067
ApplicationName = new FileInfo(ApplicationFilePath).Name.Replace(".exe", "");
6168
}
6269

63-
public ApplicationItem(string displayName, string applicationFilePath, string uwpFamilyPackageName, string uwpApplicationID, string iconPath = "") : this(displayName, applicationFilePath)
70+
public ApplicationItem(UWP.UWPApp uwpApp) : this(uwpApp.Name, uwpApp.ExecutablePath)
6471
{
6572
IsUWP = true;
66-
UWPFamilyPackageName = uwpFamilyPackageName;
67-
UWPApplicationID = uwpApplicationID;
68-
UWPIconPath = iconPath;
73+
IsUWPWepApp = true;
74+
UWPFamilyPackageName = uwpApp.FamilyPackageName;
75+
UWPApplicationID = uwpApp.ApplicationID;
76+
UWPIconPath = uwpApp.IconPath;
77+
UWPIdentity = uwpApp.Identity;
6978
}
7079

71-
7280
Dictionary<ApplicationItem, ApplicationState> _lastAppStates = new Dictionary<ApplicationItem, ApplicationState>();
7381

74-
75-
//private void UpdateRestartAppStates(IDictionary<ApplicationItem, ApplicationState> applicationStates, bool restartApps)
76-
//{
77-
// Dictionary<ApplicationItem, ApplicationState> newLastAppStates = new Dictionary<ApplicationItem, ApplicationState>();
78-
// Globals.Logs.Add($"Updating application states...", false);
79-
// foreach (var applicationState in applicationStates)
80-
// {
81-
// newLastAppStates.Add(applicationState.Key, applicationState.Value);
82-
83-
// if (applicationState.Key.RestartProcess && restartApps)
84-
// {
85-
// if (!_lastAppStates.ContainsKey(applicationState.Key) && applicationState.Value != ApplicationState.None)
86-
// RestartProcess(applicationState.Key);
87-
// else if (_lastAppStates.ContainsKey(applicationState.Key) && applicationState.Value != ApplicationState.None && _lastAppStates[applicationState.Key] == ApplicationState.None)
88-
// RestartProcess(applicationState.Key);
89-
// }
90-
// }
91-
// _lastAppStates.Clear();
92-
// _lastAppStates = newLastAppStates;
93-
//}
94-
9582
public void Restart()
9683
{
9784
try

Source/HDRProfile/AutoHDR.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@
182182
<ItemGroup>
183183
<Compile Include="Theming\ThemeResourceDirectory.cs" />
184184
<Compile Include="Theming\Theme.cs" />
185+
<Compile Include="UWP\WWAHostHandler.cs" />
186+
<Compile Include="WinAPIFunctions.cs" />
185187
<Compile Include="Windows\UI.cs" />
186188
<Page Include="App.xaml">
187189
<Generator>MSBuild:Compile</Generator>

Source/HDRProfile/Displays/Display.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,18 @@ internal void SetColorDepth(int colorDepth)
9191
DisplayManager.Instance.SetColorDepth(ID, colorDepth);
9292
}
9393

94+
public bool IsAllDisplay()
95+
{
96+
return UID.Equals(AllDisplays.UID);
97+
}
98+
9499
public override bool Equals(object obj)
95100
{
96101
if (obj.GetType().Equals(typeof(Display)))
97102
{
98103
Display display = (Display)obj;
99104
return
100105
Managed == display.Managed &&
101-
Name == display.Name &&
102106
UID == display.UID &&
103107
ID == display.ID &&
104108
_hdrState == display._hdrState &&
@@ -113,11 +117,11 @@ public override bool Equals(object obj)
113117

114118
}
115119

120+
116121
public override int GetHashCode()
117122
{
118123
int hashCode = -254808592;
119124
hashCode = hashCode * -1521134295 + Managed.GetHashCode();
120-
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Name);
121125
hashCode = hashCode * -1521134295 + UID.GetHashCode();
122126
hashCode = hashCode * -1521134295 + ID.GetHashCode();
123127
hashCode = hashCode * -1521134295 + _hdrState.GetHashCode();

Source/HDRProfile/ProcessWatcher.cs

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using AutoHDR.UWP;
2+
using System;
23
using System.Collections.Generic;
34
using System.Collections.ObjectModel;
45
using System.Diagnostics;
@@ -143,15 +144,23 @@ private void UpdateApplications()
143144
bool callClosed = false;
144145
ApplicationState state = ApplicationState.None;
145146
ApplicationState oldState = _applications[application];
146-
foreach (var process in processes.Select(p => p.ProcessName))
147+
foreach (var process in processes)
147148
{
148-
if (process.ToUpperInvariant().Equals(application.ApplicationName.ToUpperInvariant()))
149+
string processName;
150+
if (process.ProcessName == "WWAHost")
149151
{
152+
processName = UWP.WWAHostHandler.GetProcessName(process.Id);
153+
}
154+
else
155+
processName = process.ProcessName;
156+
if (application.ApplicationName.ToUpperInvariant().Equals(processName.ToUpperInvariant())
157+
|| (application.IsUWP && !string.IsNullOrEmpty(application.UWPIdentity) && processName.Contains(application.UWPIdentity)))
158+
{
159+
150160
state = ApplicationState.Running;
151161

152162
if (oldState == ApplicationState.None)
153163
callNewRunning = true;
154-
155164
if (IsFocusedApplication(process))
156165
{
157166
state = ApplicationState.Focused;
@@ -182,45 +191,38 @@ private void UpdateApplications()
182191
}
183192
}
184193

185-
private bool IsFocusedApplication(string processName)
194+
private bool IsFocusedApplication(Process process)
186195
{
187-
string currentProcessName = GetForegroundProcessName().ToUpperInvariant();
188-
return processName.ToUpperInvariant().Equals(currentProcessName);
196+
Process currentProcess = GetForegroundProcess();
197+
return process.Id.Equals(currentProcess.Id);
189198
}
190199

191200

192-
193-
// The GetForegroundWindow function returns a handle to the foreground window
194-
// (the window with which the user is currently working).
195-
[System.Runtime.InteropServices.DllImport("user32.dll")]
196-
private static extern IntPtr GetForegroundWindow();
197-
198-
// The GetWindowThreadProcessId function retrieves the identifier of the thread
199-
// that created the specified window and, optionally, the identifier of the
200-
// process that created the window.
201-
[System.Runtime.InteropServices.DllImport("user32.dll")]
202-
private static extern Int32 GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
203-
204-
// Returns the name of the process owning the foreground window.
205-
private string GetForegroundProcessName()
201+
private Process GetForegroundProcess()
206202
{
207-
IntPtr hwnd = GetForegroundWindow();
208-
209-
// The foreground window can be NULL in certain circumstances,
210-
// such as when a window is losing activation.
211-
if (hwnd == null)
212-
return "Unknown";
213-
214-
uint pid;
215-
GetWindowThreadProcessId(hwnd, out pid);
216-
217-
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
203+
var foregroundProcess = Process.GetProcessById(WinAPIFunctions.GetWindowProcessId(WinAPIFunctions.GetforegroundWindow()));
204+
if (foregroundProcess.ProcessName == "ApplicationFrameHost")
218205
{
219-
if (p.Id == pid)
220-
return p.ProcessName.ToUpperInvariant();
206+
foregroundProcess = GetRealProcess(foregroundProcess);
221207
}
208+
return foregroundProcess;
209+
}
210+
211+
private Process GetRealProcess(Process foregroundProcess)
212+
{
213+
Process realActiveProcess = null;
222214

223-
return "Unknown";
215+
WinAPIFunctions.WindowEnumProc callback = (hwnd, lparam) =>
216+
{
217+
var process = Process.GetProcessById(WinAPIFunctions.GetWindowProcessId(hwnd));
218+
if (process.ProcessName != "ApplicationFrameHost")
219+
{
220+
realActiveProcess = process;
221+
}
222+
return true;
223+
};
224+
WinAPIFunctions.EnumChildWindows(foregroundProcess.MainWindowHandle, callback, IntPtr.Zero);
225+
return realActiveProcess;
224226
}
225227
}
226228
}

Source/HDRProfile/Profiles/Actions/DisplayAction.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Displays.Display Display {
3434
{
3535
_display = value;
3636
OnPropertyChanged();
37-
if (value.Equals(Displays.Display.AllDisplays))
37+
if (value.IsAllDisplay())
3838
{
3939
Resolution = AllDisplays[1].Resolution;
4040
RefreshRate = AllDisplays[1].RefreshRate;
@@ -114,7 +114,7 @@ public override ActionEndResult RunAction(params object[] parameters)
114114
try
115115
{
116116
if (SetHDR)
117-
if (Display.Equals(Displays.Display.AllDisplays))
117+
if (Display.IsAllDisplay())
118118
{
119119
CallNewLog(new CodectoryCore.Logging.LogEntry($"{(EnableHDR ? "Activating" : "Deactivating")} HDR for all displays."));
120120
if (EnableHDR)
@@ -129,7 +129,7 @@ public override ActionEndResult RunAction(params object[] parameters)
129129
}
130130
System.Threading.Thread.Sleep(100);
131131
if (SetResolution)
132-
if (Display.Equals(Displays.Display.AllDisplays))
132+
if (Display.IsAllDisplay())
133133
{
134134
CallNewLog(new CodectoryCore.Logging.LogEntry($"Setting resolution {Resolution} for all displays."));
135135
foreach (Displays.Display display in AutoHDR.Displays.DisplayManager.GetActiveMonitors())
@@ -142,7 +142,7 @@ public override ActionEndResult RunAction(params object[] parameters)
142142
}
143143
System.Threading.Thread.Sleep(100);
144144
if (SetRefreshRate)
145-
if (Display.Equals(Displays.Display.AllDisplays))
145+
if (Display.IsAllDisplay())
146146
{
147147
CallNewLog(new CodectoryCore.Logging.LogEntry($"Setting refresh rate {RefreshRate} for all displays."));
148148

@@ -156,7 +156,7 @@ public override ActionEndResult RunAction(params object[] parameters)
156156
}
157157
System.Threading.Thread.Sleep(100);
158158
if (SetColorDepth)
159-
if (Display.Equals(Displays.Display.AllDisplays))
159+
if (Display.IsAllDisplay())
160160
{
161161
CallNewLog(new CodectoryCore.Logging.LogEntry($"Setting color depth {ColorDepth} for all displays."));
162162

Source/HDRProfile/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@
5252
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
5353
// indem Sie "*" wie unten gezeigt eingeben:
5454
// [assembly: AssemblyVersion("1.0.*")]
55-
[assembly: AssemblyVersion("1.7.12.0")]
56-
[assembly: AssemblyFileVersion("1.7.12.0")]
55+
[assembly: AssemblyVersion("1.7.13.0")]
56+
[assembly: AssemblyFileVersion("1.7.13.0")]

Source/HDRProfile/UWP/UWPApp.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,27 @@ public class UWPApp
1515
{
1616
public string Name { get; private set; } = string.Empty;
1717
public string Executable { get; private set; } = string.Empty;
18+
19+
20+
21+
public string ExecutablePath
22+
{
23+
get
24+
{
25+
if (IsWebApp)
26+
return @"C:\Windows\System32\WWAHost.exe";
27+
else
28+
return Path.Combine(InstallLocation, Executable);
29+
30+
31+
}
32+
}
33+
34+
public bool IsWebApp { get; private set; } = false;
1835
public string InstallLocation { get; private set; } = string.Empty;
1936
public string FamilyPackageName { get; private set; } = string.Empty;
2037
public string ApplicationID { get; private set; } = string.Empty;
38+
public string Identity { get; private set; } = string.Empty;
2139

2240
public string IconPath { get; private set; } = string.Empty;
2341

@@ -60,8 +78,11 @@ private void ReadAppxManifest(Package package)
6078
Executable = string.Empty;
6179
if (appxManifest.Applications != null && appxManifest.Applications.Application != null)
6280
Executable = appxManifest.Applications.Application.Executable;
81+
if (Executable == null)
82+
IsWebApp = true;
6383
FamilyPackageName = package.Id.FamilyName;
6484
ApplicationID = appxManifest.Applications.Application.Id;
85+
Identity = appxManifest.Identity.Name;
6586
IconPath = GetIconPath(Path.Combine(InstallLocation, ((XmlNode[])(appxManifest.Properties.Logo))[0].Value));
6687
}
6788
}
@@ -71,6 +92,7 @@ private void ReadAppxManifest(Package package)
7192
if (File.Exists(appxManifestPath))
7293
manifestContent = File.ReadAllText(appxManifestPath);
7394
Globals.Logs.AddException($"Error while retrieving UWP app ({appxManifestPath})\r\n\r\nContent: {manifestContent}.", ex);
95+
throw ex;
7496
}
7597
}
7698

Source/HDRProfile/UWP/UWPAppsManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ public static List<ApplicationItem> GetUWPApps()
5353

5454
try
5555
{
56-
UWPApp uwpApp = new UWPApp(package);
57-
if (!string.IsNullOrEmpty(uwpApp.Executable) /*&& !uwpApp.Name.Contains("ms-resource:")*/)
58-
uwpApps.Add(new ApplicationItem(uwpApp.Name, Path.Combine(uwpApp.InstallLocation, uwpApp.Executable), uwpApp.FamilyPackageName, uwpApp.ApplicationID, uwpApp.IconPath));
59-
}
56+
uwpApps.Add(new ApplicationItem(new UWPApp(package)));
57+
}
6058
catch
6159
{
6260
continue;

0 commit comments

Comments
 (0)