implemented mono tray icon
This commit is contained in:
parent
ce3e881c10
commit
51a6ee5650
|
@ -1,18 +1,15 @@
|
|||
<Properties>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="d:\Development\MediaBrowser\MediaBrowser.ServerApplication\ApplicationHost.cs">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Server.Mono\Program.cs">
|
||||
<Files>
|
||||
<File FileName="d:\Development\MediaBrowser\MediaBrowser.ServerApplication\ApplicationHost.cs" Line="506" Column="29" />
|
||||
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="192" Column="1" />
|
||||
<File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="24" Column="1" />
|
||||
<File FileName="d:\Development\MediaBrowser\MediaBrowser.Common.Implementations\Logging\NLogger.cs" Line="72" Column="1" />
|
||||
<File FileName="d:\Development\MediaBrowser\MediaBrowser.Common.Implementations\BaseApplicationHost.cs" Line="530" Column="1" />
|
||||
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="3" Column="40" />
|
||||
<File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="1" Column="1" />
|
||||
<File FileName="d:\Development\MediaBrowser\MediaBrowser.Common.Implementations\Logging\NLogger.cs" Line="1" Column="1" />
|
||||
<File FileName="d:\Development\MediaBrowser\MediaBrowser.Common.Implementations\BaseApplicationHost.cs" Line="1" Column="1" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore>
|
||||
<Breakpoint file="D:\Development\MediaBrowser\MediaBrowser.Server.Mono\Program.cs" line="177" column="1" />
|
||||
<Breakpoint file="D:\Development\MediaBrowser\MediaBrowser.Server.Mono\Program.cs" line="189" column="1" />
|
||||
<Breakpoint file="D:\Development\MediaBrowser\MediaBrowser.Server.Mono\Native\NativeApp.cs" line="23" column="1" />
|
||||
<Breakpoint file="D:\Development\MediaBrowser\MediaBrowser.Server.Mono\Native\NativeApp.cs" line="15" column="1" />
|
||||
</BreakpointStore>
|
||||
|
|
|
@ -127,5 +127,8 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="tray.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -4,6 +4,7 @@ using MediaBrowser.Common.Implementations.Updates;
|
|||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Server.Implementations;
|
||||
using MediaBrowser.ServerApplication;
|
||||
using MediaBrowser.ServerApplication.Native;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
@ -11,6 +12,7 @@ using System.IO;
|
|||
using System.Threading;
|
||||
using System.Windows;
|
||||
using Gtk;
|
||||
using Gdk;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Server.Mono
|
||||
|
@ -25,6 +27,9 @@ namespace MediaBrowser.Server.Mono
|
|||
|
||||
private static MainWindow _mainWindow;
|
||||
|
||||
// The tray Icon
|
||||
private static StatusIcon trayIcon;
|
||||
|
||||
public static void Main (string[] args)
|
||||
{
|
||||
Application.Init ();
|
||||
|
@ -46,9 +51,10 @@ namespace MediaBrowser.Server.Mono
|
|||
|
||||
//_singleInstanceMutex = new Mutex(true, @"Local\" + runningPath, out createdNew);
|
||||
createdNew = true;
|
||||
|
||||
if (!createdNew)
|
||||
{
|
||||
//_singleInstanceMutex = null;
|
||||
_singleInstanceMutex = null;
|
||||
logger.Info("Shutting down because another instance of Media Browser Server is already running.");
|
||||
return;
|
||||
}
|
||||
|
@ -67,7 +73,7 @@ namespace MediaBrowser.Server.Mono
|
|||
{
|
||||
logger.Info("Shutting down");
|
||||
|
||||
//ReleaseMutex(logger);
|
||||
ReleaseMutex(logger);
|
||||
|
||||
_appHost.Dispose();
|
||||
}
|
||||
|
@ -95,11 +101,70 @@ namespace MediaBrowser.Server.Mono
|
|||
// TODO: Hide splash here
|
||||
_mainWindow = new MainWindow ();
|
||||
|
||||
_mainWindow.Show ();
|
||||
// Creation of the Icon
|
||||
// Creation of the Icon
|
||||
trayIcon = new StatusIcon(new Pixbuf ("tray.png"));
|
||||
trayIcon.Visible = true;
|
||||
|
||||
// When the TrayIcon has been clicked.
|
||||
trayIcon.Activate += delegate { };
|
||||
// Show a pop up menu when the icon has been right clicked.
|
||||
trayIcon.PopupMenu += OnTrayIconPopup;
|
||||
|
||||
// A Tooltip for the Icon
|
||||
trayIcon.Tooltip = "Media Browser Server";
|
||||
|
||||
_mainWindow.ShowAll ();
|
||||
_mainWindow.Visible = false;
|
||||
|
||||
Application.Run ();
|
||||
}
|
||||
|
||||
// Create the popup menu, on right click.
|
||||
static void OnTrayIconPopup (object o, EventArgs args) {
|
||||
|
||||
Menu popupMenu = new Menu();
|
||||
|
||||
var menuItemBrowse = new ImageMenuItem ("Browse Library");
|
||||
menuItemBrowse.Image = new Gtk.Image(Stock.MediaPlay, IconSize.Menu);
|
||||
popupMenu.Add(menuItemBrowse);
|
||||
menuItemBrowse.Activated += delegate {
|
||||
BrowserLauncher.OpenWebClient(_appHost.UserManager, _appHost.ServerConfigurationManager, _appHost, _logger);
|
||||
};
|
||||
|
||||
var menuItemConfigure = new ImageMenuItem ("Configure Media Browser");
|
||||
menuItemConfigure.Image = new Gtk.Image(Stock.Edit, IconSize.Menu);
|
||||
popupMenu.Add(menuItemConfigure);
|
||||
menuItemConfigure.Activated += delegate {
|
||||
BrowserLauncher.OpenDashboard(_appHost.UserManager, _appHost.ServerConfigurationManager, _appHost, _logger);
|
||||
};
|
||||
|
||||
var menuItemApi = new ImageMenuItem ("View Api Docs");
|
||||
menuItemApi.Image = new Gtk.Image(Stock.Network, IconSize.Menu);
|
||||
popupMenu.Add(menuItemApi);
|
||||
menuItemApi.Activated += delegate {
|
||||
BrowserLauncher.OpenSwagger(_appHost.ServerConfigurationManager, _appHost, _logger);
|
||||
};
|
||||
|
||||
var menuItemCommunity = new ImageMenuItem ("Visit Community");
|
||||
menuItemCommunity.Image = new Gtk.Image(Stock.Help, IconSize.Menu);
|
||||
popupMenu.Add(menuItemCommunity);
|
||||
menuItemCommunity.Activated += delegate { BrowserLauncher.OpenCommunity(_logger); };
|
||||
|
||||
var menuItemGithub = new ImageMenuItem ("Visit Github");
|
||||
menuItemGithub.Image = new Gtk.Image(Stock.Network, IconSize.Menu);
|
||||
popupMenu.Add(menuItemGithub);
|
||||
menuItemGithub.Activated += delegate { BrowserLauncher.OpenGithub(_logger); };
|
||||
|
||||
var menuItemQuit = new ImageMenuItem ("Exit");
|
||||
menuItemQuit.Image = new Gtk.Image(Stock.Quit, IconSize.Menu);
|
||||
popupMenu.Add(menuItemQuit);
|
||||
menuItemQuit.Activated += delegate { Shutdown(); };
|
||||
|
||||
popupMenu.ShowAll();
|
||||
popupMenu.Popup();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SessionEnding event of the SystemEvents control.
|
||||
/// </summary>
|
||||
|
@ -174,20 +239,40 @@ namespace MediaBrowser.Server.Mono
|
|||
|
||||
public static void Shutdown()
|
||||
{
|
||||
_mainWindow.Hide ();
|
||||
if (trayIcon != null) {
|
||||
trayIcon.Visible = false;
|
||||
trayIcon.Dispose ();
|
||||
trayIcon = null;
|
||||
}
|
||||
|
||||
if (_mainWindow != null) {
|
||||
_mainWindow.HideAll ();
|
||||
_mainWindow.Dispose ();
|
||||
_mainWindow = null;
|
||||
}
|
||||
|
||||
Application.Quit ();
|
||||
}
|
||||
|
||||
public static void Restart()
|
||||
{
|
||||
// Second instance will start first, so release the mutex and dispose the http server ahead of time
|
||||
//ReleaseMutex (_logger);
|
||||
ReleaseMutex (_logger);
|
||||
|
||||
_appHost.Dispose();
|
||||
|
||||
_mainWindow.Hide ();
|
||||
if (trayIcon != null) {
|
||||
trayIcon.Visible = false;
|
||||
trayIcon.Dispose ();
|
||||
trayIcon = null;
|
||||
}
|
||||
|
||||
if (_mainWindow != null) {
|
||||
_mainWindow.HideAll ();
|
||||
_mainWindow.Dispose ();
|
||||
_mainWindow = null;
|
||||
}
|
||||
|
||||
Application.Quit ();
|
||||
}
|
||||
}
|
||||
|
|
BIN
MediaBrowser.Server.Mono/tray.png
Normal file
BIN
MediaBrowser.Server.Mono/tray.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
|
@ -189,19 +189,17 @@ namespace MediaBrowser.ServerApplication
|
|||
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
|
||||
void cmdApiDocs_Click(object sender, EventArgs e)
|
||||
{
|
||||
BrowserLauncher.OpenUrl("http://localhost:" + _configurationManager.Configuration.HttpServerPortNumber + "/" +
|
||||
_appHost.WebApplicationName + "/metadata", _logger);
|
||||
BrowserLauncher.OpenStandardApiDocumentation(_configurationManager, _appHost, _logger);
|
||||
}
|
||||
|
||||
void cmdSwaggerApiDocs_Click(object sender, EventArgs e)
|
||||
{
|
||||
BrowserLauncher.OpenUrl("http://localhost:" + _configurationManager.Configuration.HttpServerPortNumber + "/" +
|
||||
_appHost.WebApplicationName + "/swagger-ui/index.html", _logger);
|
||||
BrowserLauncher.OpenSwagger(_configurationManager, _appHost, _logger);
|
||||
}
|
||||
|
||||
void cmdGithubWiki_Click(object sender, EventArgs e)
|
||||
{
|
||||
BrowserLauncher.OpenUrl("https://github.com/MediaBrowser/MediaBrowser/wiki", _logger);
|
||||
BrowserLauncher.OpenGithub(_logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -246,16 +244,7 @@ namespace MediaBrowser.ServerApplication
|
|||
/// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
|
||||
private void cmOpenDashboard_click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var user = _userManager.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
|
||||
OpenDashboard(user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the dashboard.
|
||||
/// </summary>
|
||||
private void OpenDashboard(User loggedInUser)
|
||||
{
|
||||
BrowserLauncher.OpenDashboardPage("dashboard.html", loggedInUser, _configurationManager, _appHost, _logger);
|
||||
BrowserLauncher.OpenDashboard(_userManager, _configurationManager, _appHost, _logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -265,7 +254,7 @@ namespace MediaBrowser.ServerApplication
|
|||
/// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
|
||||
private void cmVisitCT_click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BrowserLauncher.OpenUrl("http://community.mediabrowser.tv/", _logger);
|
||||
BrowserLauncher.OpenCommunity(_logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -275,8 +264,7 @@ namespace MediaBrowser.ServerApplication
|
|||
/// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
|
||||
private void cmdBrowseLibrary_click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var user = _userManager.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
|
||||
BrowserLauncher.OpenDashboardPage("index.html", user, _configurationManager, _appHost, _logger);
|
||||
BrowserLauncher.OpenWebClient(_userManager, _configurationManager, _appHost, _logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MediaBrowser.ServerApplication.Native
|
||||
{
|
||||
/// <summary>
|
||||
/// Class BrowserLauncher
|
||||
/// </summary>
|
||||
public static class BrowserLauncher
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -17,6 +22,7 @@ namespace MediaBrowser.ServerApplication.Native
|
|||
/// <param name="loggedInUser">The logged in user.</param>
|
||||
/// <param name="configurationManager">The configuration manager.</param>
|
||||
/// <param name="appHost">The app host.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public static void OpenDashboardPage(string page, User loggedInUser, IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger)
|
||||
{
|
||||
var url = "http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" +
|
||||
|
@ -25,11 +31,80 @@ namespace MediaBrowser.ServerApplication.Native
|
|||
OpenUrl(url, logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the github.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public static void OpenGithub(ILogger logger)
|
||||
{
|
||||
OpenUrl("https://github.com/MediaBrowser/MediaBrowser", logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the community.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public static void OpenCommunity(ILogger logger)
|
||||
{
|
||||
OpenUrl("http://community.mediabrowser.tv/", logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the web client.
|
||||
/// </summary>
|
||||
/// <param name="userManager">The user manager.</param>
|
||||
/// <param name="configurationManager">The configuration manager.</param>
|
||||
/// <param name="appHost">The app host.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public static void OpenWebClient(IUserManager userManager, IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger)
|
||||
{
|
||||
var user = userManager.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
|
||||
OpenDashboardPage("index.html", user, configurationManager, appHost, logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the dashboard.
|
||||
/// </summary>
|
||||
/// <param name="userManager">The user manager.</param>
|
||||
/// <param name="configurationManager">The configuration manager.</param>
|
||||
/// <param name="appHost">The app host.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public static void OpenDashboard(IUserManager userManager, IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger)
|
||||
{
|
||||
var user = userManager.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
|
||||
OpenDashboardPage("dashboard.html", user, configurationManager, appHost, logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the swagger.
|
||||
/// </summary>
|
||||
/// <param name="configurationManager">The configuration manager.</param>
|
||||
/// <param name="appHost">The app host.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public static void OpenSwagger(IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger)
|
||||
{
|
||||
OpenUrl("http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" +
|
||||
appHost.WebApplicationName + "/swagger-ui/index.html", logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the standard API documentation.
|
||||
/// </summary>
|
||||
/// <param name="configurationManager">The configuration manager.</param>
|
||||
/// <param name="appHost">The app host.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public static void OpenStandardApiDocumentation(IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger)
|
||||
{
|
||||
OpenUrl("http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" +
|
||||
appHost.WebApplicationName + "/metadata", logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the URL.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
public static void OpenUrl(string url, ILogger logger)
|
||||
/// <param name="logger">The logger.</param>
|
||||
private static void OpenUrl(string url, ILogger logger)
|
||||
{
|
||||
var process = new Process
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user