2
0

MenuBarIcon.cs 4.7 KB

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