From cc2d04d5bc85bbe824548ffa4bc43992afe819a3 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 28 Nov 2014 12:40:20 -0500 Subject: [PATCH] updates for mac project --- .../BaseApplicationHost.cs | 50 +++--- MediaBrowser.Server.Mac/AppController.cs | 134 -------------- MediaBrowser.Server.Mac/AppDelegate.cs | 2 +- MediaBrowser.Server.Mac/Info.plist | 38 ++-- MediaBrowser.Server.Mac/Main.cs | 16 +- .../MediaBrowser.Server.Mac.csproj | 4 +- MediaBrowser.Server.Mac/MenuBarIcon.cs | 163 ++++++++++++++++++ .../AppIcon.appiconset/Contents.json | 58 +++++++ .../ApplicationHost.cs | 10 +- 9 files changed, 283 insertions(+), 192 deletions(-) create mode 100644 MediaBrowser.Server.Mac/MenuBarIcon.cs create mode 100644 MediaBrowser.Server.Mac/Resources/MediaBrowser.Server.Mac/Images.xcassets/AppIcon.appiconset/Contents.json diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index c44cfd4730..891a03d395 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -448,45 +448,43 @@ namespace MediaBrowser.Common.Implementations /// Task. protected virtual Task RegisterResources(IProgress progress) { - return Task.Run(() => - { - RegisterSingleInstance(ConfigurationManager); - RegisterSingleInstance(this); + RegisterSingleInstance(ConfigurationManager); + RegisterSingleInstance(this); - RegisterSingleInstance(ApplicationPaths); + RegisterSingleInstance(ApplicationPaths); - TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger); + TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger); - RegisterSingleInstance(JsonSerializer); - RegisterSingleInstance(XmlSerializer); + RegisterSingleInstance(JsonSerializer); + RegisterSingleInstance(XmlSerializer); - RegisterSingleInstance(LogManager); - RegisterSingleInstance(Logger); + RegisterSingleInstance(LogManager); + RegisterSingleInstance(Logger); - RegisterSingleInstance(TaskManager); + RegisterSingleInstance(TaskManager); - RegisterSingleInstance(FileSystemManager); + RegisterSingleInstance(FileSystemManager); - HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, FileSystemManager, ConfigurationManager); - RegisterSingleInstance(HttpClient); + HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, FileSystemManager, ConfigurationManager); + RegisterSingleInstance(HttpClient); - NetworkManager = CreateNetworkManager(LogManager.GetLogger("NetworkManager")); - RegisterSingleInstance(NetworkManager); + NetworkManager = CreateNetworkManager(LogManager.GetLogger("NetworkManager")); + RegisterSingleInstance(NetworkManager); - SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, NetworkManager, LogManager); - RegisterSingleInstance(SecurityManager); + SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, NetworkManager, LogManager); + RegisterSingleInstance(SecurityManager); - InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, NetworkManager, ConfigurationManager); - RegisterSingleInstance(InstallationManager); + InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, NetworkManager, ConfigurationManager); + RegisterSingleInstance(InstallationManager); - ZipClient = new ZipClient(); - RegisterSingleInstance(ZipClient); + ZipClient = new ZipClient(); + RegisterSingleInstance(ZipClient); - IsoManager = new IsoManager(); - RegisterSingleInstance(IsoManager); + IsoManager = new IsoManager(); + RegisterSingleInstance(IsoManager); - RegisterModules(); - }); + RegisterModules(); + return Task.FromResult (true); } private void RegisterModules() diff --git a/MediaBrowser.Server.Mac/AppController.cs b/MediaBrowser.Server.Mac/AppController.cs index 296d3f23cd..c72f3649e9 100644 --- a/MediaBrowser.Server.Mac/AppController.cs +++ b/MediaBrowser.Server.Mac/AppController.cs @@ -12,143 +12,9 @@ namespace MediaBrowser.Server.Mac [Register("AppController")] public partial class AppController : NSObject { - private NSMenuItem browseMenuItem; - private NSMenuItem configureMenuItem; - private NSMenuItem developerMenuItem; - private NSMenuItem quitMenuItem; - private NSMenuItem githubMenuItem; - private NSMenuItem apiMenuItem; - private NSMenuItem communityMenuItem; - - public static AppController Instance; - - public AppController() - { - Instance = this; - MainClass.AddDependencies (this); - } - public override void AwakeFromNib() { - var statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30); - statusItem.Menu = statusMenu; - statusItem.Image = NSImage.ImageNamed("statusicon"); - statusItem.HighlightMode = true; - statusMenu.RemoveAllItems (); - - browseMenuItem = new NSMenuItem ("Browse Media Library", "b", delegate { - Browse (this); - }); - statusMenu.AddItem (browseMenuItem); - - configureMenuItem = new NSMenuItem ("Configure Media Browser", "c", delegate { - Configure (this); - }); - statusMenu.AddItem (configureMenuItem); - - developerMenuItem = new NSMenuItem ("Developer Resources"); - statusMenu.AddItem (developerMenuItem); - - 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); - - communityMenuItem = new NSMenuItem ("Visit Community", "v", delegate { - Community (this); - }); - statusMenu.AddItem (communityMenuItem); - - quitMenuItem = new NSMenuItem ("Quit", "q", delegate { - Quit (this); - }); - statusMenu.AddItem (quitMenuItem); - - 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 void Quit(NSObject sender) - { - AppHost.Shutdown(); - } - - private void Community(NSObject sender) - { - BrowserLauncher.OpenCommunity(Logger); - } - - private void Configure(NSObject sender) - { - BrowserLauncher.OpenDashboard(AppHost, Logger); - } - - private void Browse(NSObject sender) - { - BrowserLauncher.OpenWebClient(AppHost, Logger); - } - - private void Github(NSObject sender) - { - BrowserLauncher.OpenGithub(Logger); - } - - private void ApiDocs(NSObject sender) - { - BrowserLauncher.OpenSwagger(AppHost, Logger); - } - - public void Terminate() - { - InvokeOnMainThread (() => NSApplication.SharedApplication.Terminate(this)); - } - - private string _uiCulture; - /// - /// Handles the ConfigurationUpdated event of the Instance control. - /// - /// The source of the event. - /// The instance containing the event data. - 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"); } } } diff --git a/MediaBrowser.Server.Mac/AppDelegate.cs b/MediaBrowser.Server.Mac/AppDelegate.cs index 26e6d9614f..cb63feb2ea 100644 --- a/MediaBrowser.Server.Mac/AppDelegate.cs +++ b/MediaBrowser.Server.Mac/AppDelegate.cs @@ -15,7 +15,7 @@ namespace MediaBrowser.Server.Mac public override void FinishedLaunching (NSObject notification) { - + new MenuBarIcon ().ShowIcon (); } } } diff --git a/MediaBrowser.Server.Mac/Info.plist b/MediaBrowser.Server.Mac/Info.plist index cc7aa73c13..3e058c72fb 100644 --- a/MediaBrowser.Server.Mac/Info.plist +++ b/MediaBrowser.Server.Mac/Info.plist @@ -2,27 +2,29 @@ - CFBundleIdentifier - com.MediaBrowser.MediaBrowser.Server.Mac - CFBundleName - Media Browser - CFBundleVersion - 1 - LSMinimumSystemVersion - 10.6 - LSUIElement - 1 - LSMultipleInstancesProhibited - 1 - NSMainNibFile - MainMenu - NSPrincipalClass - NSApplication - LSApplicationCategoryType - public.app-category.video CFBundleDisplayName Media Browser CFBundleIconFile appicon + CFBundleIdentifier + com.MediaBrowser.MediaBrowser.Server.Mac + CFBundleName + Media Browser + CFBundleShortVersionString + 3 + CFBundleVersion + 1 + LSApplicationCategoryType + public.app-category.video + LSMinimumSystemVersion + 10.6 + LSMultipleInstancesProhibited + 1 + LSUIElement + 1 + NSPrincipalClass + NSApplication + NSMainNibFile + MainMenu diff --git a/MediaBrowser.Server.Mac/Main.cs b/MediaBrowser.Server.Mac/Main.cs index 5618d02d5a..2edc7b6b06 100644 --- a/MediaBrowser.Server.Mac/Main.cs +++ b/MediaBrowser.Server.Mac/Main.cs @@ -18,7 +18,6 @@ using MediaBrowser.Server.Implementations; 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; @@ -57,7 +56,7 @@ namespace MediaBrowser.Server.Mac NSApplication.Main (args); } - public static void AddDependencies(AppController appController){ + public static void AddDependencies(MenuBarIcon appController){ appController.AppHost = _appHost; appController.Logger = _logger; appController.ConfigurationManager = _appHost.ServerConfigurationManager; @@ -106,13 +105,16 @@ namespace MediaBrowser.Server.Mac Console.WriteLine ("appHost.Init"); + Task.Run (() => StartServer(CancellationToken.None)); + } + + private static async void StartServer(CancellationToken cancellationToken) + { var initProgress = new Progress(); - var task = _appHost.Init(initProgress); + await _appHost.Init (initProgress).ConfigureAwait (false); - Task.WaitAll(task); - - Task.Run (() => _appHost.RunStartupTasks()); + //await _appHost.RunStartupTasks ().ConfigureAwait (false); } /// @@ -139,7 +141,7 @@ namespace MediaBrowser.Server.Mac _appHost.Dispose (); _logger.Info("AppController.Terminate"); - AppController.Instance.Terminate (); + MenuBarIcon.Instance.Terminate (); } /// diff --git a/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj b/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj index ed46ec3934..2055d797e7 100644 --- a/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj +++ b/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj @@ -86,13 +86,14 @@ AppController.cs - SharedVersion.cs + + @@ -2960,5 +2961,6 @@ 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 new file mode 100644 index 0000000000..4ed5323bda --- /dev/null +++ b/MediaBrowser.Server.Mac/MenuBarIcon.cs @@ -0,0 +1,163 @@ +using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Localization; +using MediaBrowser.Model.Logging; +using MediaBrowser.Server.Startup.Common.Browser; +using System; +using MonoMac.Foundation; +using MonoMac.AppKit; + +namespace MediaBrowser.Server.Mac +{ + public class MenuBarIcon + { + private NSMenuItem browseMenuItem; + private NSMenuItem configureMenuItem; + private NSMenuItem developerMenuItem; + private NSMenuItem quitMenuItem; + private NSMenuItem githubMenuItem; + private NSMenuItem apiMenuItem; + private NSMenuItem communityMenuItem; + + public static MenuBarIcon Instance; + + public MenuBarIcon () + { + Instance = this; + //MainClass.AddDependencies (this); + } + + public void ShowIcon() { + + NSApplication.SharedApplication.BeginInvokeOnMainThread (ShowIconInternal); + } + + private void ShowIconInternal() { + + var menu = new NSMenu (); + + var statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30); + statusItem.Menu = menu; + statusItem.Image = NSImage.ImageNamed("statusicon"); + statusItem.HighlightMode = true; + + menu.RemoveAllItems (); + + browseMenuItem = new NSMenuItem ("Browse Media Library", "b", delegate { + Browse (NSApplication.SharedApplication); + }); + menu.AddItem (browseMenuItem); + + configureMenuItem = new NSMenuItem ("Configure Media Browser", "c", delegate { + Configure (NSApplication.SharedApplication); + }); + menu.AddItem (configureMenuItem); + + developerMenuItem = new NSMenuItem ("Developer Resources"); + menu.AddItem (developerMenuItem); + + var developerMenu = new NSMenu (); + developerMenuItem.Submenu = developerMenu; + + apiMenuItem = new NSMenuItem ("Api Documentation", "a", delegate { + ApiDocs (NSApplication.SharedApplication); + }); + developerMenu.AddItem (apiMenuItem); + + githubMenuItem = new NSMenuItem ("Github", "g", delegate { + Github (NSApplication.SharedApplication); + }); + developerMenu.AddItem (githubMenuItem); + + communityMenuItem = new NSMenuItem ("Visit Community", "v", delegate { + Community (NSApplication.SharedApplication); + }); + menu.AddItem (communityMenuItem); + + quitMenuItem = new NSMenuItem ("Quit", "q", delegate { + 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 void Quit(NSObject sender) + { + AppHost.Shutdown(); + } + + private void Community(NSObject sender) + { + BrowserLauncher.OpenCommunity(Logger); + } + + private void Configure(NSObject sender) + { + BrowserLauncher.OpenDashboard(AppHost, Logger); + } + + private void Browse(NSObject sender) + { + BrowserLauncher.OpenWebClient(AppHost, Logger); + } + + private void Github(NSObject sender) + { + BrowserLauncher.OpenGithub(Logger); + } + + private void ApiDocs(NSObject sender) + { + BrowserLauncher.OpenSwagger(AppHost, Logger); + } + + public void Terminate() + { + NSApplication.SharedApplication.InvokeOnMainThread (() => NSApplication.SharedApplication.Terminate(NSApplication.SharedApplication)); + } + + private string _uiCulture; + /// + /// Handles the ConfigurationUpdated event of the Instance control. + /// + /// The source of the event. + /// The instance containing the event data. + void Instance_ConfigurationUpdated(object sender, EventArgs e) + { + if (!string.Equals(ConfigurationManager.Configuration.UICulture, _uiCulture, + StringComparison.OrdinalIgnoreCase)) + { + LocalizeText(); + } + } + + private void LocalizeText() + { + _uiCulture = ConfigurationManager.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"); + } + } +} + diff --git a/MediaBrowser.Server.Mac/Resources/MediaBrowser.Server.Mac/Images.xcassets/AppIcon.appiconset/Contents.json b/MediaBrowser.Server.Mac/Resources/MediaBrowser.Server.Mac/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000..50ab7bd32c --- /dev/null +++ b/MediaBrowser.Server.Mac/Resources/MediaBrowser.Server.Mac/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 73dcdaacbe..1d254b914a 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -356,7 +356,7 @@ namespace MediaBrowser.Server.Startup.Common { await base.RegisterResources(progress).ConfigureAwait(false); - RegisterSingleInstance(new HttpResultFactory(LogManager, FileSystemManager, JsonSerializer)); + RegisterSingleInstance(new HttpResultFactory(LogManager, FileSystemManager, JsonSerializer)); RegisterSingleInstance(this); RegisterSingleInstance(ApplicationPaths); @@ -371,7 +371,7 @@ namespace MediaBrowser.Server.Startup.Common UserDataManager = new UserDataManager(LogManager); RegisterSingleInstance(UserDataManager); - UserRepository = await GetUserRepository().ConfigureAwait(false); + UserRepository = await GetUserRepository().ConfigureAwait(false); RegisterSingleInstance(UserRepository); DisplayPreferencesRepository = new SqliteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager); @@ -412,7 +412,7 @@ namespace MediaBrowser.Server.Startup.Common RegisterSingleInstance(() => new SearchEngine(LogManager, LibraryManager, UserManager)); - HttpServer = ServerFactory.CreateServer(this, LogManager, "Media Browser", WebApplicationName, "dashboard/index.html", _supportsNativeWebSocket); + HttpServer = ServerFactory.CreateServer(this, LogManager, "Media Browser", WebApplicationName, "dashboard/index.html", _supportsNativeWebSocket); RegisterSingleInstance(HttpServer, false); progress.Report(10); @@ -506,13 +506,13 @@ namespace MediaBrowser.Server.Startup.Common RegisterSingleInstance(new SessionContext(UserManager, authContext, SessionManager)); RegisterSingleInstance(new AuthService(UserManager, authContext, ServerConfigurationManager, ConnectManager, SessionManager)); - RegisterSingleInstance(new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer)); + RegisterSingleInstance(new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer)); var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false)); var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false)); var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false)); - await ConfigureNotificationsRepository().ConfigureAwait(false); + await ConfigureNotificationsRepository().ConfigureAwait(false); progress.Report(92); await Task.WhenAll(itemsTask, displayPreferencesTask, userdataTask).ConfigureAwait(false);