AppController.cs 4.2 KB

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