From 33689931caab8a75860385978cf386b67ae39a62 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sun, 20 Dec 2020 12:45:50 +1300 Subject: [PATCH] Moved AUMID to Shared project And also added it to the LogReporter project. --- DisplayMagician.LogReporter/Program.cs | 9 ++++++++ .../DisplayMagician.Shared.csproj | 1 + DisplayMagician.Shared/ShellUtils.cs | 23 +++++++++++++++++++ DisplayMagician/Program.cs | 15 ++++-------- 4 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 DisplayMagician.Shared/ShellUtils.cs diff --git a/DisplayMagician.LogReporter/Program.cs b/DisplayMagician.LogReporter/Program.cs index c6ed01d..280b680 100644 --- a/DisplayMagician.LogReporter/Program.cs +++ b/DisplayMagician.LogReporter/Program.cs @@ -10,11 +10,13 @@ using WindowsDisplayAPI.DisplayConfig; using NvAPIWrapper.GPU; using NvAPIWrapper.Mosaic; using AudioSwitcher.AudioApi.CoreAudio; +using DisplayMagician.Shared; namespace DisplayMagician.LogReporter { internal class Program { + private static StreamWriter _writer; internal static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician"); @@ -87,6 +89,13 @@ namespace DisplayMagician.LogReporter private static void Main(string[] args) { + // This sets the Application User Model ID to "LittleBitBig.DisplayMagician" so that + // Windows 10 recognises the application, and allows features such as Toasts, + // taskbar pinning and similar. + // This is a helper function that sets the AUMID to a static default defined + // within ShellUtils under the DisplayMagician.Shared project. + ShellUtils.SetDefaultProcessExplicitAppUserModelID(); + Console.WriteLine("DisplayMagician LogReporter"); Console.WriteLine("======================"); Console.WriteLine(); diff --git a/DisplayMagician.Shared/DisplayMagician.Shared.csproj b/DisplayMagician.Shared/DisplayMagician.Shared.csproj index 13c3497..98aff7e 100644 --- a/DisplayMagician.Shared/DisplayMagician.Shared.csproj +++ b/DisplayMagician.Shared/DisplayMagician.Shared.csproj @@ -68,6 +68,7 @@ + diff --git a/DisplayMagician.Shared/ShellUtils.cs b/DisplayMagician.Shared/ShellUtils.cs new file mode 100644 index 0000000..70a409c --- /dev/null +++ b/DisplayMagician.Shared/ShellUtils.cs @@ -0,0 +1,23 @@ +using System.Runtime.InteropServices; + +namespace DisplayMagician.Shared +{ + public class ShellUtils + { + public static string AUMID = "LittleBitBig.DisplayMagician"; + + // Add the ability to set an Application AUMID so that Windows 10+ recognises the + // application and things like Toasts, Tasbar pinning and similar functionality + // works as intended. This DLL import avoids the need to package the app as an MSIX + // or moving to a WiX based installer at this stage, or the need to add this to the + // Windows Store. + [DllImport("shell32.dll", SetLastError = true)] + public static extern void SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID); + + public static void SetDefaultProcessExplicitAppUserModelID() + { + SetCurrentProcessExplicitAppUserModelID(AUMID); + } + + } +} diff --git a/DisplayMagician/Program.cs b/DisplayMagician/Program.cs index 675dc08..69789f5 100644 --- a/DisplayMagician/Program.cs +++ b/DisplayMagician/Program.cs @@ -13,7 +13,7 @@ using DisplayMagician.Shared; using DisplayMagician.UIForms; using System.Text.RegularExpressions; using System.Drawing; -using System.Runtime.InteropServices; +//using System.Runtime.InteropServices; namespace DisplayMagician { @@ -26,7 +26,6 @@ namespace DisplayMagician { internal static class Program { - internal static string AUMID = "LittleBitBig.DisplayMagician"; internal static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician"); public static string AppIconPath = Path.Combine(Program.AppDataPath, $"Icons"); public static string AppProfilePath = Path.Combine(Program.AppDataPath, $"Profiles"); @@ -52,7 +51,9 @@ namespace DisplayMagician { // This sets the Application User Model ID to "LittleBitBig.DisplayMagician" so that // Windows 10 recognises the application, and allows features such as Toasts, // taskbar pinning and similar. - SetCurrentProcessExplicitAppUserModelID(AUMID); + // This is a helper function that sets the AUMID to a static default defined + // within ShellUtils under the DisplayMagician.Shared project. + ShellUtils.SetDefaultProcessExplicitAppUserModelID(); // Prepare NLog for logging var config = new NLog.Config.LoggingConfiguration(); @@ -608,14 +609,6 @@ namespace DisplayMagician { } - // Add the ability to set an Application AUMID so that Windows 10+ recognises the - // application and things like Toasts, Tasbar pinning and similar functionality - // works as intended. This DLL import avoids the need to package the app as an MSIX - // or moving to a WiX based installer at this stage, or the need to add this to the - // Windows Store. - [DllImport("shell32.dll", SetLastError = true)] - static extern void SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID); - }