App.xaml.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Windows;
  5. using MediaBrowser.Common.Kernel;
  6. using MediaBrowser.Common.UI;
  7. using MediaBrowser.Controller;
  8. using Microsoft.Shell;
  9. namespace MediaBrowser.ServerApplication
  10. {
  11. /// <summary>
  12. /// Interaction logic for App.xaml
  13. /// </summary>
  14. public partial class App : BaseApplication, ISingleInstanceApp
  15. {
  16. private const string Unique = "MediaBrowser3";
  17. [STAThread]
  18. public static void Main()
  19. {
  20. if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
  21. {
  22. var application = new App();
  23. application.InitializeComponent();
  24. application.Run();
  25. // Allow single instance code to perform cleanup operations
  26. SingleInstance<App>.Cleanup();
  27. }
  28. }
  29. #region ISingleInstanceApp Members
  30. public bool SignalExternalCommandLineArgs(IList<string> args)
  31. {
  32. OpenDashboard();
  33. return true;
  34. }
  35. #endregion
  36. public static void OpenDashboard()
  37. {
  38. OpenUrl("http://localhost:" + Kernel.Instance.Configuration.HttpServerPortNumber +
  39. "/mediabrowser/dashboard/index.html");
  40. }
  41. public static void OpenUrl(string url)
  42. {
  43. var process = new Process
  44. {
  45. StartInfo = new ProcessStartInfo
  46. {
  47. FileName = url
  48. },
  49. EnableRaisingEvents = true
  50. };
  51. process.Exited += ProcessExited;
  52. process.Start();
  53. }
  54. static void ProcessExited(object sender, EventArgs e)
  55. {
  56. (sender as Process).Dispose();
  57. }
  58. protected override IKernel InstantiateKernel()
  59. {
  60. return new Kernel();
  61. }
  62. protected override Window InstantiateMainWindow()
  63. {
  64. return new MainWindow();
  65. }
  66. }
  67. }