AppController.cs 4.1 KB

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