Program.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System;
 6  using System.Threading;
 7  
 8  using ManagedCommon;
 9  using Microsoft.UI.Dispatching;
10  using Microsoft.Windows.AppLifecycle;
11  
12  namespace AdvancedPaste
13  {
14      public static class Program
15      {
16          [STAThread]
17          public static void Main(string[] args)
18          {
19              Logger.InitializeLogger("\\AdvancedPaste\\Logs");
20  
21              WinRT.ComWrappersSupport.InitializeComWrappers();
22  
23              if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredAdvancedPasteEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
24              {
25                  Logger.LogWarning("Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
26                  return;
27              }
28  
29              var instanceKey = AppInstance.FindOrRegisterForKey("PowerToys_AdvancedPaste_Instance");
30  
31              if (instanceKey.IsCurrent)
32              {
33                  Microsoft.UI.Xaml.Application.Start((p) =>
34                  {
35                      var context = new DispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread());
36                      SynchronizationContext.SetSynchronizationContext(context);
37                      _ = new App();
38                  });
39              }
40              else
41              {
42                  Logger.LogWarning("Another instance of AdvancedPasteUI is running. Exiting.");
43              }
44          }
45      }
46  }