AppController.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using MediaBrowser.Controller;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.Localization;
  4. using MediaBrowser.Model.Logging;
  5. using MediaBrowser.Server.Startup.Common.Browser;
  6. using System;
  7. using MonoMac.Foundation;
  8. using MonoMac.AppKit;
  9. namespace MediaBrowser.Server.Mac
  10. {
  11. [Register("AppController")]
  12. public partial class AppController : NSObject
  13. {
  14. private NSMenuItem browseMenuItem;
  15. private NSMenuItem configureMenuItem;
  16. private NSMenuItem developerMenuItem;
  17. private NSMenuItem quitMenuItem;
  18. private NSMenuItem githubMenuItem;
  19. private NSMenuItem apiMenuItem;
  20. private NSMenuItem communityMenuItem;
  21. public static AppController Instance;
  22. public AppController()
  23. {
  24. Instance = this;
  25. MainClass.AddDependencies (this);
  26. }
  27. public override void AwakeFromNib()
  28. {
  29. var statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
  30. statusItem.Menu = statusMenu;
  31. statusItem.Image = NSImage.ImageNamed("statusicon");
  32. statusItem.HighlightMode = true;
  33. statusMenu.RemoveAllItems ();
  34. browseMenuItem = new NSMenuItem ("Browse Media Library", "b", delegate {
  35. Browse (this);
  36. });
  37. statusMenu.AddItem (browseMenuItem);
  38. configureMenuItem = new NSMenuItem ("Configure Media Browser", "c", delegate {
  39. Configure (this);
  40. });
  41. statusMenu.AddItem (configureMenuItem);
  42. developerMenuItem = new NSMenuItem ("Developer Resources");
  43. statusMenu.AddItem (developerMenuItem);
  44. var developerMenu = new NSMenu ();
  45. developerMenuItem.Submenu = developerMenu;
  46. apiMenuItem = new NSMenuItem ("Api Documentation", "a", delegate {
  47. ApiDocs (this);
  48. });
  49. developerMenu.AddItem (apiMenuItem);
  50. githubMenuItem = new NSMenuItem ("Github", "g", delegate {
  51. Github (this);
  52. });
  53. developerMenu.AddItem (githubMenuItem);
  54. communityMenuItem = new NSMenuItem ("Visit Community", "v", delegate {
  55. Community (this);
  56. });
  57. statusMenu.AddItem (communityMenuItem);
  58. quitMenuItem = new NSMenuItem ("Quit", "q", delegate {
  59. Quit (this);
  60. });
  61. statusMenu.AddItem (quitMenuItem);
  62. ConfigurationManager.ConfigurationUpdated -= Instance_ConfigurationUpdated;
  63. LocalizeText ();
  64. ConfigurationManager.ConfigurationUpdated += Instance_ConfigurationUpdated;
  65. }
  66. public IServerApplicationHost AppHost{ get; set;}
  67. public IServerConfigurationManager ConfigurationManager { get; set;}
  68. public ILogger Logger{ get; set;}
  69. public ILocalizationManager Localization { get; set;}
  70. private void Quit(NSObject sender)
  71. {
  72. AppHost.Shutdown();
  73. }
  74. private void Community(NSObject sender)
  75. {
  76. BrowserLauncher.OpenCommunity(Logger);
  77. }
  78. private void Configure(NSObject sender)
  79. {
  80. BrowserLauncher.OpenDashboard(AppHost, Logger);
  81. }
  82. private void Browse(NSObject sender)
  83. {
  84. BrowserLauncher.OpenWebClient(AppHost, Logger);
  85. }
  86. private void Github(NSObject sender)
  87. {
  88. BrowserLauncher.OpenGithub(Logger);
  89. }
  90. private void ApiDocs(NSObject sender)
  91. {
  92. BrowserLauncher.OpenSwagger(AppHost, Logger);
  93. }
  94. public void Terminate()
  95. {
  96. InvokeOnMainThread (() => NSApplication.SharedApplication.Terminate(this));
  97. }
  98. private string _uiCulture;
  99. /// <summary>
  100. /// Handles the ConfigurationUpdated event of the Instance control.
  101. /// </summary>
  102. /// <param name="sender">The source of the event.</param>
  103. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  104. void Instance_ConfigurationUpdated(object sender, EventArgs e)
  105. {
  106. if (!string.Equals(ConfigurationManager.Configuration.UICulture, _uiCulture,
  107. StringComparison.OrdinalIgnoreCase))
  108. {
  109. LocalizeText();
  110. }
  111. }
  112. private void LocalizeText()
  113. {
  114. _uiCulture = ConfigurationManager.Configuration.UICulture;
  115. BeginInvokeOnMainThread (LocalizeInternal);
  116. }
  117. private void LocalizeInternal() {
  118. quitMenuItem.Title = Localization.GetLocalizedString("LabelExit");
  119. communityMenuItem.Title = Localization.GetLocalizedString("LabelVisitCommunity");
  120. githubMenuItem.Title = Localization.GetLocalizedString("LabelGithub");
  121. apiMenuItem.Title = Localization.GetLocalizedString("LabelApiDocumentation");
  122. developerMenuItem.Title = Localization.GetLocalizedString("LabelDeveloperResources");
  123. browseMenuItem.Title = Localization.GetLocalizedString("LabelBrowseLibrary");
  124. configureMenuItem.Title = Localization.GetLocalizedString("LabelConfigureMediaBrowser");
  125. }
  126. }
  127. }