diff options
| author | Luke <luke.pulverenti@gmail.com> | 2014-11-28 12:40:20 -0500 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2014-11-28 12:40:20 -0500 |
| commit | cc2d04d5bc85bbe824548ffa4bc43992afe819a3 (patch) | |
| tree | d423019bdeb7184d8d4250d0c414381b378f976d /MediaBrowser.Server.Mac | |
| parent | 9875c3a7e986382213b3c97b5da9a6cc9acff677 (diff) | |
updates for mac project
Diffstat (limited to 'MediaBrowser.Server.Mac')
| -rw-r--r-- | MediaBrowser.Server.Mac/AppController.cs | 134 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mac/AppDelegate.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mac/Info.plist | 22 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mac/Main.cs | 16 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj | 4 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mac/MenuBarIcon.cs | 163 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mac/Resources/MediaBrowser.Server.Mac/Images.xcassets/AppIcon.appiconset/Contents.json | 58 |
7 files changed, 246 insertions, 153 deletions
diff --git a/MediaBrowser.Server.Mac/AppController.cs b/MediaBrowser.Server.Mac/AppController.cs index 296d3f23c..c72f3649e 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; - /// <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"); } } } diff --git a/MediaBrowser.Server.Mac/AppDelegate.cs b/MediaBrowser.Server.Mac/AppDelegate.cs index 26e6d9614..cb63feb2e 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 cc7aa73c1..3e058c72f 100644 --- a/MediaBrowser.Server.Mac/Info.plist +++ b/MediaBrowser.Server.Mac/Info.plist @@ -2,27 +2,29 @@ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> + <key>CFBundleDisplayName</key> + <string>Media Browser</string> + <key>CFBundleIconFile</key> + <string>appicon</string> <key>CFBundleIdentifier</key> <string>com.MediaBrowser.MediaBrowser.Server.Mac</string> <key>CFBundleName</key> <string>Media Browser</string> + <key>CFBundleShortVersionString</key> + <string>3</string> <key>CFBundleVersion</key> <string>1</string> + <key>LSApplicationCategoryType</key> + <string>public.app-category.video</string> <key>LSMinimumSystemVersion</key> <string>10.6</string> - <key>LSUIElement</key> - <string>1</string> <key>LSMultipleInstancesProhibited</key> <string>1</string> - <key>NSMainNibFile</key> - <string>MainMenu</string> + <key>LSUIElement</key> + <string>1</string> <key>NSPrincipalClass</key> <string>NSApplication</string> - <key>LSApplicationCategoryType</key> - <string>public.app-category.video</string> - <key>CFBundleDisplayName</key> - <string>Media Browser</string> - <key>CFBundleIconFile</key> - <string>appicon</string> + <key>NSMainNibFile</key> + <string>MainMenu</string> </dict> </plist> diff --git a/MediaBrowser.Server.Mac/Main.cs b/MediaBrowser.Server.Mac/Main.cs index 5618d02d5..2edc7b6b0 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"); - var initProgress = new Progress<double>(); + Task.Run (() => StartServer(CancellationToken.None)); + } - var task = _appHost.Init(initProgress); + private static async void StartServer(CancellationToken cancellationToken) + { + var initProgress = new Progress<double>(); - Task.WaitAll(task); + await _appHost.Init (initProgress).ConfigureAwait (false); - Task.Run (() => _appHost.RunStartupTasks()); + //await _appHost.RunStartupTasks ().ConfigureAwait (false); } /// <summary> @@ -139,7 +141,7 @@ namespace MediaBrowser.Server.Mac _appHost.Dispose (); _logger.Info("AppController.Terminate"); - AppController.Instance.Terminate (); + MenuBarIcon.Instance.Terminate (); } /// <summary> diff --git a/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj b/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj index ed46ec393..2055d797e 100644 --- a/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj +++ b/MediaBrowser.Server.Mac/MediaBrowser.Server.Mac.csproj @@ -86,13 +86,14 @@ <Compile Include="AppController.designer.cs">
<DependentUpon>AppController.cs</DependentUpon>
</Compile>
- <Compile Include="Main.cs" />
<Compile Include="Native\NativeApp.cs" />
<Compile Include="Native\BaseMonoApp.cs" />
<Compile Include="Native\NetworkManager.cs" />
<Compile Include="..\SharedVersion.cs">
<Link>SharedVersion.cs</Link>
</Compile>
+ <Compile Include="Main.cs" />
+ <Compile Include="MenuBarIcon.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="MainMenu.xib" />
@@ -2960,5 +2961,6 @@ <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>
\ 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 000000000..4ed5323bd --- /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; + /// <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; + + 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 000000000..50ab7bd32 --- /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 |
