From 7f376fde27debda261ec9655392302aef27ebe26 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 28 Nov 2014 23:03:47 -0500 Subject: [PATCH] update mac project --- MediaBrowser.Server.Mac/AppController.cs | 2 +- MediaBrowser.Server.Mac/AppDelegate.cs | 3 +- MediaBrowser.Server.Mac/Main.cs | 26 ++++--- .../MediaBrowser.Server.Mac.csproj | 6 +- MediaBrowser.Server.Mac/MenuBarIcon.cs | 71 +++++++++++-------- 5 files changed, 61 insertions(+), 47 deletions(-) diff --git a/MediaBrowser.Server.Mac/AppController.cs b/MediaBrowser.Server.Mac/AppController.cs index c72f3649e..8d690b813 100644 --- a/MediaBrowser.Server.Mac/AppController.cs +++ b/MediaBrowser.Server.Mac/AppController.cs @@ -14,7 +14,7 @@ namespace MediaBrowser.Server.Mac { public override void AwakeFromNib() { - + //new MenuBarIcon ().ShowIcon (); } } } diff --git a/MediaBrowser.Server.Mac/AppDelegate.cs b/MediaBrowser.Server.Mac/AppDelegate.cs index cb63feb2e..6cf183aa5 100644 --- a/MediaBrowser.Server.Mac/AppDelegate.cs +++ b/MediaBrowser.Server.Mac/AppDelegate.cs @@ -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 (); } } } diff --git a/MediaBrowser.Server.Mac/Main.cs b/MediaBrowser.Server.Mac/Main.cs index 2edc7b6b0..33f870aee 100644 --- a/MediaBrowser.Server.Mac/Main.cs +++ b/MediaBrowser.Server.Mac/Main.cs @@ -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(); - 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 (); + } } /// @@ -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) { diff --git a/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj b/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj index 2055d797e..0860d5b86 100644 --- a/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj +++ b/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj @@ -12,6 +12,7 @@ ..\MediaBrowser.WebDashboard\dashboard-ui\css\images\favicon.ico + MediaBrowser.Server.Mac.MainClass true @@ -31,7 +32,6 @@ Developer ID Installer - full true bin\Release prompt @@ -254,6 +254,8 @@ Resources\swagger-ui\lib\shred\content.js + + Resources\dashboard-ui\.DS_Store @@ -2960,7 +2962,5 @@ Resources\dashboard-ui\thirdparty\swipebox-master\js\jquery.swipebox.min.js - - \ No newline at end of file diff --git a/MediaBrowser.Server.Mac/MenuBarIcon.cs b/MediaBrowser.Server.Mac/MenuBarIcon.cs index 4ed5323bd..c5c4d92de 100644 --- a/MediaBrowser.Server.Mac/MenuBarIcon.cs +++ b/MediaBrowser.Server.Mac/MenuBarIcon.cs @@ -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 /// The instance containing the event data. 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"); } } }