updates for mac project

This commit is contained in:
Luke 2014-11-28 12:40:20 -05:00
parent 9875c3a7e9
commit cc2d04d5bc
9 changed files with 283 additions and 192 deletions

View file

@ -447,8 +447,6 @@ namespace MediaBrowser.Common.Implementations
/// </summary>
/// <returns>Task.</returns>
protected virtual Task RegisterResources(IProgress<double> progress)
{
return Task.Run(() =>
{
RegisterSingleInstance(ConfigurationManager);
RegisterSingleInstance<IApplicationHost>(this);
@ -486,7 +484,7 @@ namespace MediaBrowser.Common.Implementations
RegisterSingleInstance(IsoManager);
RegisterModules();
});
return Task.FromResult (true);
}
private void RegisterModules()

View file

@ -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");
}
}
}

View file

@ -15,7 +15,7 @@ namespace MediaBrowser.Server.Mac
public override void FinishedLaunching (NSObject notification)
{
new MenuBarIcon ().ShowIcon ();
}
}
}

View file

@ -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>CFBundleIdentifier</key>
<string>com.MediaBrowser.MediaBrowser.Server.Mac</string>
<key>CFBundleName</key>
<string>Media Browser</string>
<key>CFBundleVersion</key>
<string>1</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>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>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>LSMultipleInstancesProhibited</key>
<string>1</string>
<key>LSUIElement</key>
<string>1</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
</dict>
</plist>

View file

@ -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<double>();
var task = _appHost.Init(initProgress);
await _appHost.Init (initProgress).ConfigureAwait (false);
Task.WaitAll(task);
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>

View file

@ -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>

View file

@ -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");
}
}
}

View file

@ -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"
}
}