update mac project

This commit is contained in:
Luke 2014-11-28 23:03:47 -05:00
parent 97ece5bd6f
commit 7f376fde27
5 changed files with 61 additions and 47 deletions

View File

@ -14,7 +14,7 @@ namespace MediaBrowser.Server.Mac
{
public override void AwakeFromNib()
{
//new MenuBarIcon ().ShowIcon ();
}
}
}

View File

@ -15,7 +15,8 @@ namespace MediaBrowser.Server.Mac
public override void FinishedLaunching (NSObject notification)
{
new MenuBarIcon ().ShowIcon ();
new MenuBarIcon (MainClass.AppHost.LogManager.GetLogger("Tray"))
.ShowIcon ();
}
}
}

View File

@ -26,7 +26,7 @@ namespace MediaBrowser.Server.Mac
{
class MainClass
{
private static ApplicationHost _appHost;
internal static ApplicationHost AppHost;
private static ILogger _logger;
@ -56,13 +56,6 @@ namespace MediaBrowser.Server.Mac
NSApplication.Main (args);
}
public static void AddDependencies(MenuBarIcon appController){
appController.AppHost = _appHost;
appController.Logger = _logger;
appController.ConfigurationManager = _appHost.ServerConfigurationManager;
appController.Localization = _appHost.LocalizationManager;
}
private static ServerApplicationPaths CreateApplicationPaths(string applicationPath, string programDataPath)
{
if (string.IsNullOrEmpty(programDataPath))
@ -96,10 +89,10 @@ namespace MediaBrowser.Server.Mac
var nativeApp = new NativeApp();
_appHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "MBServer.Mono", false, nativeApp);
AppHost = new ApplicationHost(appPaths, logManager, options, fileSystem, "MBServer.Mono", false, nativeApp);
if (options.ContainsOption("-v")) {
Console.WriteLine (_appHost.ApplicationVersion.ToString());
Console.WriteLine (AppHost.ApplicationVersion.ToString());
return;
}
@ -112,9 +105,14 @@ namespace MediaBrowser.Server.Mac
{
var initProgress = new Progress<double>();
await _appHost.Init (initProgress).ConfigureAwait (false);
await AppHost.Init (initProgress).ConfigureAwait (false);
//await _appHost.RunStartupTasks ().ConfigureAwait (false);
await AppHost.RunStartupTasks ().ConfigureAwait (false);
if (MenuBarIcon.Instance != null)
{
MenuBarIcon.Instance.Localize ();
}
}
/// <summary>
@ -138,7 +136,7 @@ namespace MediaBrowser.Server.Mac
private static void ShutdownApp()
{
_logger.Info ("Calling ApplicationHost.Dispose");
_appHost.Dispose ();
AppHost.Dispose ();
_logger.Info("AppController.Terminate");
MenuBarIcon.Instance.Terminate ();
@ -153,7 +151,7 @@ namespace MediaBrowser.Server.Mac
{
var exception = (Exception)e.ExceptionObject;
new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager).Log(exception);
new UnhandledExceptionWriter(AppHost.ServerConfigurationManager.ApplicationPaths, _logger, AppHost.LogManager).Log(exception);
if (!Debugger.IsAttached)
{

View File

@ -12,6 +12,7 @@
<ApplicationIcon>..\MediaBrowser.WebDashboard\dashboard-ui\css\images\favicon.ico</ApplicationIcon>
<ReleaseVersion>
</ReleaseVersion>
<StartupObject>MediaBrowser.Server.Mac.MainClass</StartupObject>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -31,7 +32,6 @@
<PackageSigningKey>Developer ID Installer</PackageSigningKey>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
@ -254,6 +254,8 @@
<BundleResource Include="..\ThirdParty\ServiceStack\swagger-ui\lib\shred\content.js">
<Link>Resources\swagger-ui\lib\shred\content.js</Link>
</BundleResource>
<BundleResource Include="Resources\appicon.icns" />
<BundleResource Include="Resources\MediaBrowser.Server.Mac\Images.xcassets\AppIcon.appiconset\Contents.json" />
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\.DS_Store">
<Link>Resources\dashboard-ui\.DS_Store</Link>
</BundleResource>
@ -2960,7 +2962,5 @@
<BundleResource Include="..\MediaBrowser.WebDashboard\dashboard-ui\thirdparty\swipebox-master\js\jquery.swipebox.min.js">
<Link>Resources\dashboard-ui\thirdparty\swipebox-master\js\jquery.swipebox.min.js</Link>
</BundleResource>
<BundleResource Include="Resources\appicon.icns" />
<BundleResource Include="Resources\MediaBrowser.Server.Mac\Images.xcassets\AppIcon.appiconset\Contents.json" />
</ItemGroup>
</Project>

View File

@ -21,22 +21,40 @@ namespace MediaBrowser.Server.Mac
public static MenuBarIcon Instance;
public MenuBarIcon ()
public MenuBarIcon (ILogger logger)
{
Instance = this;
//MainClass.AddDependencies (this);
Logger = logger;
}
public void ShowIcon() {
NSApplication.SharedApplication.BeginInvokeOnMainThread (ShowIconInternal);
NSApplication.SharedApplication.BeginInvokeOnMainThread (CreateMenus);
}
private void ShowIconInternal() {
private void CreateMenus() {
CreateNsMenu ();
}
public void Localize()
{
NSApplication.SharedApplication.BeginInvokeOnMainThread (() => {
var configManager = MainClass.AppHost.ServerConfigurationManager;
configManager.ConfigurationUpdated -= Instance_ConfigurationUpdated;
LocalizeText ();
configManager.ConfigurationUpdated += Instance_ConfigurationUpdated;
});
}
private NSStatusItem statusItem;
private void CreateNsMenu() {
var menu = new NSMenu ();
var statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
statusItem.Menu = menu;
statusItem.Image = NSImage.ImageNamed("statusicon");
statusItem.HighlightMode = true;
@ -78,22 +96,13 @@ namespace MediaBrowser.Server.Mac
Quit (NSApplication.SharedApplication);
});
menu.AddItem (quitMenuItem);
NSApplication.SharedApplication.MainMenu = menu;
//ConfigurationManager.ConfigurationUpdated -= Instance_ConfigurationUpdated;
//LocalizeText ();
//ConfigurationManager.ConfigurationUpdated += Instance_ConfigurationUpdated;
}
public IServerApplicationHost AppHost{ get; set;}
public IServerConfigurationManager ConfigurationManager { get; set;}
public ILogger Logger{ get; set;}
public ILocalizationManager Localization { get; set;}
private ILogger Logger{ get; set;}
private void Quit(NSObject sender)
{
AppHost.Shutdown();
MainClass.AppHost.Shutdown();
}
private void Community(NSObject sender)
@ -103,12 +112,12 @@ namespace MediaBrowser.Server.Mac
private void Configure(NSObject sender)
{
BrowserLauncher.OpenDashboard(AppHost, Logger);
BrowserLauncher.OpenDashboard(MainClass.AppHost, Logger);
}
private void Browse(NSObject sender)
{
BrowserLauncher.OpenWebClient(AppHost, Logger);
BrowserLauncher.OpenWebClient(MainClass.AppHost, Logger);
}
private void Github(NSObject sender)
@ -118,7 +127,7 @@ namespace MediaBrowser.Server.Mac
private void ApiDocs(NSObject sender)
{
BrowserLauncher.OpenSwagger(AppHost, Logger);
BrowserLauncher.OpenSwagger(MainClass.AppHost, Logger);
}
public void Terminate()
@ -134,7 +143,9 @@ namespace MediaBrowser.Server.Mac
/// <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,
var configManager = MainClass.AppHost.ServerConfigurationManager;
if (!string.Equals(configManager.Configuration.UICulture, _uiCulture,
StringComparison.OrdinalIgnoreCase))
{
LocalizeText();
@ -143,20 +154,24 @@ namespace MediaBrowser.Server.Mac
private void LocalizeText()
{
_uiCulture = ConfigurationManager.Configuration.UICulture;
var configManager = MainClass.AppHost.ServerConfigurationManager;
_uiCulture = configManager.Configuration.UICulture;
NSApplication.SharedApplication.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");
var localization = MainClass.AppHost.LocalizationManager;
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");
}
}
}