App.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Microsoft.Win32;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Threading;
  5. using System.Windows;
  6. namespace FastGithub.UI
  7. {
  8. /// <summary>
  9. /// App.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class App : Application
  12. {
  13. private Mutex mutex;
  14. private Process fastGithub;
  15. protected override void OnStartup(StartupEventArgs e)
  16. {
  17. this.mutex = new Mutex(true, "Global\\FastGithub.UI", out var firstInstance);
  18. if (firstInstance == false)
  19. {
  20. this.Shutdown();
  21. return;
  22. }
  23. this.fastGithub = StartFastGithub();
  24. SetWebBrowserVersion();
  25. base.OnStartup(e);
  26. }
  27. protected override void OnExit(ExitEventArgs e)
  28. {
  29. this.mutex.Dispose();
  30. if (this.fastGithub != null && this.fastGithub.HasExited == false)
  31. {
  32. this.fastGithub.Kill();
  33. }
  34. base.OnExit(e);
  35. }
  36. private static Process StartFastGithub()
  37. {
  38. const string fileName = "fastgithub.exe";
  39. if (File.Exists(fileName) == false)
  40. {
  41. return default;
  42. }
  43. var startInfo = new ProcessStartInfo
  44. {
  45. FileName = fileName,
  46. UseShellExecute = false,
  47. CreateNoWindow = true
  48. };
  49. return Process.Start(startInfo);
  50. }
  51. private static void SetWebBrowserVersion()
  52. {
  53. var emulation = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
  54. var key = $"{Process.GetCurrentProcess().ProcessName}.exe";
  55. emulation.SetValue(key, 9000, RegistryValueKind.DWord);
  56. }
  57. }
  58. }