jellyfin/MediaBrowser.Server.Mac/AppController.cs

156 lines
4.3 KiB
C#
Raw Normal View History

2014-11-23 13:57:25 -07:00
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Startup.Common.Browser;
2014-11-21 10:13:21 -07:00
using System;
using MonoMac.Foundation;
using MonoMac.AppKit;
2014-11-21 10:20:28 -07:00
namespace MediaBrowser.Server.Mac
2014-11-21 10:13:21 -07:00
{
[Register("AppController")]
public partial class AppController : NSObject
{
2014-11-23 13:57:25 -07:00
private NSMenuItem browseMenuItem;
private NSMenuItem configureMenuItem;
private NSMenuItem developerMenuItem;
private NSMenuItem quitMenuItem;
private NSMenuItem githubMenuItem;
private NSMenuItem apiMenuItem;
private NSMenuItem communityMenuItem;
2014-11-23 17:02:01 -07:00
public static AppController Instance;
2014-11-21 10:13:21 -07:00
public AppController()
{
2014-11-23 17:02:01 -07:00
Instance = this;
2014-11-25 21:27:55 -07:00
MainClass.AddDependencies (this);
2014-11-21 10:13:21 -07:00
}
public override void AwakeFromNib()
{
2014-11-22 09:38:48 -07:00
var statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
statusItem.Menu = statusMenu;
2014-11-26 18:56:14 -07:00
statusItem.Image = NSImage.ImageNamed("statusicon");
2014-11-22 09:38:48 -07:00
statusItem.HighlightMode = true;
2014-11-21 10:13:21 -07:00
2014-11-26 18:56:14 -07:00
statusMenu.RemoveAllItems ();
2014-11-22 10:15:33 -07:00
2014-11-23 13:57:25 -07:00
browseMenuItem = new NSMenuItem ("Browse Media Library", "b", delegate {
Browse (this);
});
2014-11-26 18:56:14 -07:00
statusMenu.AddItem (browseMenuItem);
2014-11-22 10:15:33 -07:00
2014-11-23 13:57:25 -07:00
configureMenuItem = new NSMenuItem ("Configure Media Browser", "c", delegate {
Configure (this);
});
2014-11-26 18:56:14 -07:00
statusMenu.AddItem (configureMenuItem);
2014-11-22 10:15:33 -07:00
2014-11-23 13:57:25 -07:00
developerMenuItem = new NSMenuItem ("Developer Resources");
2014-11-26 18:56:14 -07:00
statusMenu.AddItem (developerMenuItem);
2014-11-22 10:15:33 -07:00
2014-11-23 13:57:25 -07:00
var developerMenu = new NSMenu ();
developerMenuItem.Submenu = developerMenu;
apiMenuItem = new NSMenuItem ("Api Documentation", "a", delegate {
ApiDocs (this);
});
developerMenu.AddItem (apiMenuItem);
githubMenuItem = new NSMenuItem ("Github", "g", delegate {
Github (this);
});
developerMenu.AddItem (githubMenuItem);
2014-11-22 10:15:33 -07:00
2014-11-23 13:57:25 -07:00
communityMenuItem = new NSMenuItem ("Visit Community", "v", delegate {
Community (this);
});
2014-11-26 18:56:14 -07:00
statusMenu.AddItem (communityMenuItem);
2014-11-23 13:57:25 -07:00
quitMenuItem = new NSMenuItem ("Quit", "q", delegate {
Quit (this);
});
2014-11-26 18:56:14 -07:00
statusMenu.AddItem (quitMenuItem);
2014-11-26 23:02:59 -07:00
ConfigurationManager.ConfigurationUpdated -= Instance_ConfigurationUpdated;
LocalizeText ();
ConfigurationManager.ConfigurationUpdated += Instance_ConfigurationUpdated;
2014-11-22 10:15:33 -07:00
}
2014-11-23 17:02:01 -07:00
public IServerApplicationHost AppHost{ get; set;}
public IServerConfigurationManager ConfigurationManager { get; set;}
public ILogger Logger{ get; set;}
public ILocalizationManager Localization { get; set;}
2014-11-23 13:57:25 -07:00
private void Quit(NSObject sender)
2014-11-22 10:15:33 -07:00
{
2014-11-23 17:02:01 -07:00
AppHost.Shutdown();
2014-11-23 13:57:25 -07:00
}
2014-11-22 10:15:33 -07:00
2014-11-23 13:57:25 -07:00
private void Community(NSObject sender)
{
BrowserLauncher.OpenCommunity(Logger);
2014-11-22 10:15:33 -07:00
}
2014-11-23 13:57:25 -07:00
private void Configure(NSObject sender)
2014-11-22 10:15:33 -07:00
{
2014-11-23 13:57:25 -07:00
BrowserLauncher.OpenDashboard(AppHost, Logger);
}
2014-11-22 10:15:33 -07:00
2014-11-23 13:57:25 -07:00
private void Browse(NSObject sender)
{
BrowserLauncher.OpenWebClient(AppHost, Logger);
2014-11-22 10:15:33 -07:00
}
2014-11-23 13:57:25 -07:00
private void Github(NSObject sender)
2014-11-22 10:15:33 -07:00
{
2014-11-23 13:57:25 -07:00
BrowserLauncher.OpenGithub(Logger);
}
2014-11-22 10:15:33 -07:00
2014-11-23 13:57:25 -07:00
private void ApiDocs(NSObject sender)
{
BrowserLauncher.OpenSwagger(AppHost, Logger);
2014-11-21 10:13:21 -07:00
}
2014-11-23 17:02:01 -07:00
public void Terminate()
{
InvokeOnMainThread (() => NSApplication.SharedApplication.Terminate(this));
}
private string _uiCulture;
/// <summary>
/// Handles the ConfigurationUpdated event of the Instance control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
void Instance_ConfigurationUpdated(object sender, EventArgs e)
{
if (!string.Equals(ConfigurationManager.Configuration.UICulture, _uiCulture,
StringComparison.OrdinalIgnoreCase))
{
LocalizeText();
}
}
private void LocalizeText()
{
_uiCulture = ConfigurationManager.Configuration.UICulture;
BeginInvokeOnMainThread (LocalizeInternal);
}
private void LocalizeInternal() {
quitMenuItem.Title = Localization.GetLocalizedString("LabelExit");
communityMenuItem.Title = Localization.GetLocalizedString("LabelVisitCommunity");
githubMenuItem.Title = Localization.GetLocalizedString("LabelGithub");
apiMenuItem.Title = Localization.GetLocalizedString("LabelApiDocumentation");
developerMenuItem.Title = Localization.GetLocalizedString("LabelDeveloperResources");
browseMenuItem.Title = Localization.GetLocalizedString("LabelBrowseLibrary");
configureMenuItem.Title = Localization.GetLocalizedString("LabelConfigureMediaBrowser");
}
2014-11-21 10:13:21 -07:00
}
}