mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 03:26:07 +02:00
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
This commit is contained in:
commit
7e4e9d6644
3 changed files with 208 additions and 6 deletions
|
@ -20,9 +20,11 @@ namespace MediaBrowser.Server.Mac
|
|||
private NSMenuItem apiMenuItem;
|
||||
private NSMenuItem communityMenuItem;
|
||||
|
||||
public static AppController Instance;
|
||||
|
||||
public AppController()
|
||||
{
|
||||
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void AwakeFromNib()
|
||||
|
@ -71,13 +73,14 @@ namespace MediaBrowser.Server.Mac
|
|||
statusItem.Menu.AddItem (quitMenuItem);
|
||||
}
|
||||
|
||||
private IServerApplicationHost AppHost{ get; set;}
|
||||
private ILogger Logger{ get; set;}
|
||||
public IServerApplicationHost AppHost{ get; set;}
|
||||
public IServerConfigurationManager ConfigurationManager { get; set;}
|
||||
public ILogger Logger{ get; set;}
|
||||
public ILocalizationManager Localization { get; set;}
|
||||
|
||||
private void Quit(NSObject sender)
|
||||
{
|
||||
NSApplication.SharedApplication.Terminate(this);
|
||||
//AppHost.Shutdown();
|
||||
AppHost.Shutdown();
|
||||
}
|
||||
|
||||
private void Community(NSObject sender)
|
||||
|
@ -104,6 +107,44 @@ namespace MediaBrowser.Server.Mac
|
|||
{
|
||||
BrowserLauncher.OpenSwagger(AppHost, Logger);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,171 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using MonoMac.Foundation;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Implementations.IO;
|
||||
using MediaBrowser.Common.Implementations.Logging;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Server.Implementations;
|
||||
using MediaBrowser.Server.Mono.Native;
|
||||
using MediaBrowser.Server.Startup.Common;
|
||||
using MediaBrowser.Server.Startup.Common.Browser;
|
||||
using Microsoft.Win32;
|
||||
using Microsoft.Win32;
|
||||
using MonoMac.AppKit;
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.ObjCRuntime;
|
||||
|
||||
namespace MediaBrowser.Server.Mac
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
private static ApplicationHost _appHost;
|
||||
|
||||
private static ILogger _logger;
|
||||
|
||||
static void Main (string[] args)
|
||||
{
|
||||
var applicationPath = Assembly.GetEntryAssembly().Location;
|
||||
|
||||
var options = new StartupOptions();
|
||||
|
||||
// Allow this to be specified on the command line.
|
||||
var customProgramDataPath = options.GetOption("-programdata");
|
||||
|
||||
var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath);
|
||||
|
||||
var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");
|
||||
logManager.ReloadLogger(LogSeverity.Info);
|
||||
logManager.AddConsoleOutput();
|
||||
|
||||
var logger = _logger = logManager.GetLogger("Main");
|
||||
|
||||
ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
|
||||
StartApplication(appPaths, logManager, options);
|
||||
RunNSApp (args);
|
||||
}
|
||||
|
||||
private static void RunNSApp(string[] args) {
|
||||
|
||||
NSApplication.Init ();
|
||||
|
||||
AppController.Instance.AppHost = _appHost;
|
||||
AppController.Instance.Logger = _logger;
|
||||
AppController.Instance.ConfigurationManager = _appHost.ServerConfigurationManager;
|
||||
AppController.Instance.Localization = _appHost.LocalizationManager;
|
||||
|
||||
NSApplication.Main (args);
|
||||
}
|
||||
|
||||
private static ServerApplicationPaths CreateApplicationPaths(string applicationPath, string programDataPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(programDataPath))
|
||||
{
|
||||
return new ServerApplicationPaths(applicationPath);
|
||||
}
|
||||
|
||||
return new ServerApplicationPaths(programDataPath, applicationPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the application.
|
||||
/// </summary>
|
||||
/// <param name="appPaths">The app paths.</param>
|
||||
/// <param name="logManager">The log manager.</param>
|
||||
/// <param name="options">The options.</param>
|
||||
private static void StartApplication(ServerApplicationPaths appPaths,
|
||||
ILogManager logManager,
|
||||
StartupOptions options)
|
||||
{
|
||||
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
|
||||
|
||||
// Allow all https requests
|
||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
|
||||
|
||||
var fileSystem = new CommonFileSystem(logManager.GetLogger("FileSystem"), false, true);
|
||||
|
||||
var nativeApp = new NativeApp();
|
||||
|
||||
_appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "MBServer.Mono", false, nativeApp);
|
||||
|
||||
if (options.ContainsOption("-v")) {
|
||||
Console.WriteLine (_appHost.ApplicationVersion.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine ("appHost.Init");
|
||||
|
||||
var initProgress = new Progress<double>();
|
||||
|
||||
var task = _appHost.Init(initProgress);
|
||||
task = task.ContinueWith(new Action<Task>(a => _appHost.RunStartupTasks()));
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SessionEnding event of the SystemEvents control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="SessionEndingEventArgs"/> instance containing the event data.</param>
|
||||
static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
|
||||
{
|
||||
if (e.Reason == SessionEndReasons.SystemShutdown)
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Shutdown()
|
||||
{
|
||||
ShutdownApp();
|
||||
}
|
||||
|
||||
private static void ShutdownApp()
|
||||
{
|
||||
_logger.Info ("Calling ApplicationHost.Dispose");
|
||||
_appHost.Dispose ();
|
||||
|
||||
_logger.Info("AppController.Terminate");
|
||||
AppController.Instance.Terminate ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the UnhandledException event of the CurrentDomain control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="UnhandledExceptionEventArgs"/> instance containing the event data.</param>
|
||||
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
var exception = (Exception)e.ExceptionObject;
|
||||
|
||||
new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager).Log(exception);
|
||||
|
||||
if (!Debugger.IsAttached)
|
||||
{
|
||||
Environment.Exit(System.Runtime.InteropServices.Marshal.GetHRForException(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NoCheckCertificatePolicy : ICertificatePolicy
|
||||
{
|
||||
public bool CheckValidationResult (ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -112,6 +112,14 @@
|
|||
<Project>{9142EEFA-7570-41E1-BFCC-468BB571AF2F}</Project>
|
||||
<Name>MediaBrowser.Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\MediaBrowser.Common.Implementations\MediaBrowser.Common.Implementations.csproj">
|
||||
<Project>{C4D2573A-3FD3-441F-81AF-174AC4CD4E1D}</Project>
|
||||
<Name>MediaBrowser.Common.Implementations</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\MediaBrowser.Server.Implementations\MediaBrowser.Server.Implementations.csproj">
|
||||
<Project>{2E781478-814D-4A48-9D80-BFF206441A65}</Project>
|
||||
<Name>MediaBrowser.Server.Implementations</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="touchicon.png" />
|
||||
|
|
Loading…
Reference in a new issue