convert tray icon

This commit is contained in:
Luke Pulverenti 2014-02-15 15:26:21 -05:00
parent 46f668fbd8
commit b2397d598c
6 changed files with 5254 additions and 33 deletions

View file

@ -0,0 +1,192 @@
namespace MediaBrowser.ServerApplication
{
partial class MainForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.cmdExit = new System.Windows.Forms.ToolStripMenuItem();
this.cmdCommunity = new System.Windows.Forms.ToolStripMenuItem();
this.cmdLogWindow = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.cmdRestart = new System.Windows.Forms.ToolStripMenuItem();
this.cmdLibraryExplorer = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.cmdConfigure = new System.Windows.Forms.ToolStripMenuItem();
this.cmdBrowse = new System.Windows.Forms.ToolStripMenuItem();
this.cmdApiDocs = new System.Windows.Forms.ToolStripMenuItem();
this.cmdStandardDocs = new System.Windows.Forms.ToolStripMenuItem();
this.cmdSwagger = new System.Windows.Forms.ToolStripMenuItem();
this.cmdGtihub = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// notifyIcon1
//
this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "Media Browser";
this.notifyIcon1.Visible = true;
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.cmdBrowse,
this.cmdConfigure,
this.toolStripSeparator2,
this.cmdLibraryExplorer,
this.cmdRestart,
this.toolStripSeparator1,
this.cmdApiDocs,
this.cmdLogWindow,
this.cmdCommunity,
this.cmdExit});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.ShowCheckMargin = true;
this.contextMenuStrip1.ShowImageMargin = false;
this.contextMenuStrip1.Size = new System.Drawing.Size(209, 214);
//
// cmdExit
//
this.cmdExit.Name = "cmdExit";
this.cmdExit.Size = new System.Drawing.Size(208, 22);
this.cmdExit.Text = "Exit";
//
// cmdCommunity
//
this.cmdCommunity.Name = "cmdCommunity";
this.cmdCommunity.Size = new System.Drawing.Size(208, 22);
this.cmdCommunity.Text = "Visit Community";
//
// cmdLogWindow
//
this.cmdLogWindow.CheckOnClick = true;
this.cmdLogWindow.Name = "cmdLogWindow";
this.cmdLogWindow.Size = new System.Drawing.Size(208, 22);
this.cmdLogWindow.Text = "Show Log Window";
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(205, 6);
//
// cmdRestart
//
this.cmdRestart.Name = "cmdRestart";
this.cmdRestart.Size = new System.Drawing.Size(208, 22);
this.cmdRestart.Text = "Restart Server";
//
// cmdLibraryExplorer
//
this.cmdLibraryExplorer.Name = "cmdLibraryExplorer";
this.cmdLibraryExplorer.Size = new System.Drawing.Size(208, 22);
this.cmdLibraryExplorer.Text = "Open Library Explorer";
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(205, 6);
//
// cmdConfigure
//
this.cmdConfigure.Name = "cmdConfigure";
this.cmdConfigure.Size = new System.Drawing.Size(208, 22);
this.cmdConfigure.Text = "Configure Media Browser";
//
// cmdBrowse
//
this.cmdBrowse.Name = "cmdBrowse";
this.cmdBrowse.Size = new System.Drawing.Size(208, 22);
this.cmdBrowse.Text = "Browse Library";
//
// cmdApiDocs
//
this.cmdApiDocs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.cmdStandardDocs,
this.cmdSwagger,
this.cmdGtihub});
this.cmdApiDocs.Name = "cmdApiDocs";
this.cmdApiDocs.Size = new System.Drawing.Size(208, 22);
this.cmdApiDocs.Text = "View Api Documentation";
//
// cmdStandardDocs
//
this.cmdStandardDocs.Name = "cmdStandardDocs";
this.cmdStandardDocs.Size = new System.Drawing.Size(136, 22);
this.cmdStandardDocs.Text = "Standard";
//
// cmdSwagger
//
this.cmdSwagger.Name = "cmdSwagger";
this.cmdSwagger.Size = new System.Drawing.Size(136, 22);
this.cmdSwagger.Text = "Swagger";
//
// cmdGtihub
//
this.cmdGtihub.Name = "cmdGtihub";
this.cmdGtihub.Size = new System.Drawing.Size(136, 22);
this.cmdGtihub.Text = "Github Wiki";
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "MainForm";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "MainForm";
this.contextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem cmdExit;
private System.Windows.Forms.ToolStripMenuItem cmdBrowse;
private System.Windows.Forms.ToolStripMenuItem cmdConfigure;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem cmdLibraryExplorer;
private System.Windows.Forms.ToolStripMenuItem cmdRestart;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem cmdLogWindow;
private System.Windows.Forms.ToolStripMenuItem cmdCommunity;
private System.Windows.Forms.ToolStripMenuItem cmdApiDocs;
private System.Windows.Forms.ToolStripMenuItem cmdStandardDocs;
private System.Windows.Forms.ToolStripMenuItem cmdSwagger;
private System.Windows.Forms.ToolStripMenuItem cmdGtihub;
}
}

View file

@ -0,0 +1,188 @@
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using MediaBrowser.ServerApplication.Logging;
using MediaBrowser.ServerApplication.Native;
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace MediaBrowser.ServerApplication
{
public partial class MainForm : Form
{
private readonly ILogger _logger;
private readonly IServerApplicationHost _appHost;
private readonly ILogManager _logManager;
private readonly IServerConfigurationManager _configurationManager;
private readonly IUserManager _userManager;
private readonly ILibraryManager _libraryManager;
private readonly IJsonSerializer _jsonSerializer;
private readonly IDisplayPreferencesRepository _displayPreferencesManager;
private readonly IItemRepository _itemRepository;
private LogForm _logForm;
public MainForm(ILogManager logManager, IServerApplicationHost appHost, IServerConfigurationManager configurationManager, IUserManager userManager, ILibraryManager libraryManager, IJsonSerializer jsonSerializer, IDisplayPreferencesRepository displayPreferencesManager, IItemRepository itemRepo)
{
InitializeComponent();
_logger = logManager.GetLogger("MainWindow");
_itemRepository = itemRepo;
_appHost = appHost;
_logManager = logManager;
_configurationManager = configurationManager;
_userManager = userManager;
_libraryManager = libraryManager;
_jsonSerializer = jsonSerializer;
_displayPreferencesManager = displayPreferencesManager;
cmdExit.Click += cmdExit_Click;
cmdRestart.Click += cmdRestart_Click;
cmdLogWindow.Click += cmdLogWindow_Click;
cmdConfigure.Click += cmdConfigure_Click;
cmdCommunity.Click += cmdCommunity_Click;
cmdBrowse.Click += cmdBrowse_Click;
cmdLibraryExplorer.Click += cmdLibraryExplorer_Click;
cmdSwagger.Click += cmdSwagger_Click;
cmdStandardDocs.Click += cmdStandardDocs_Click;
cmdGtihub.Click += cmdGtihub_Click;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
LoadLogWindow(null, EventArgs.Empty);
_logManager.LoggerLoaded += LoadLogWindow;
_configurationManager.ConfigurationUpdated += Instance_ConfigurationUpdated;
if (_appHost.IsFirstRun)
{
Action action = () => notifyIcon1.ShowBalloonTip(5000, "Media Browser", "Welcome to Media Browser Server!", ToolTipIcon.Info);
Invoke(action);
}
}
/// <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)
{
Action action = () =>
{
var isLogWindowOpen = _logForm != null;
if ((!isLogWindowOpen && _configurationManager.Configuration.ShowLogWindow) ||
(isLogWindowOpen && !_configurationManager.Configuration.ShowLogWindow))
{
_logManager.ReloadLogger(_configurationManager.Configuration.EnableDebugLevelLogging
? LogSeverity.Debug
: LogSeverity.Info);
}
};
Invoke(action);
}
/// <summary>
/// Loads the log window.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
void LoadLogWindow(object sender, EventArgs args)
{
CloseLogWindow();
Action action = () =>
{
// Add our log window if specified
if (_configurationManager.Configuration.ShowLogWindow)
{
_logForm = new LogForm(_logManager);
Trace.Listeners.Add(new WindowTraceListener(_logForm));
}
else
{
Trace.Listeners.Remove("MBLogWindow");
}
// Set menu option indicator
cmdLogWindow.Checked = _configurationManager.Configuration.ShowLogWindow;
};
Invoke(action);
}
/// <summary>
/// Closes the log window.
/// </summary>
void CloseLogWindow()
{
if (_logForm != null)
{
_logForm.ShutDown();
}
}
void cmdBrowse_Click(object sender, EventArgs e)
{
BrowserLauncher.OpenWebClient(_userManager, _configurationManager, _appHost, _logger);
}
void cmdCommunity_Click(object sender, EventArgs e)
{
BrowserLauncher.OpenCommunity(_logger);
}
void cmdConfigure_Click(object sender, EventArgs e)
{
BrowserLauncher.OpenDashboard(_userManager, _configurationManager, _appHost, _logger);
}
void cmdLogWindow_Click(object sender, EventArgs e)
{
_configurationManager.Configuration.ShowLogWindow = !_configurationManager.Configuration.ShowLogWindow;
_configurationManager.SaveConfiguration();
LoadLogWindow(sender, e);
}
void cmdLibraryExplorer_Click(object sender, EventArgs e)
{
new LibraryViewer(_jsonSerializer, _userManager, _libraryManager, _displayPreferencesManager, _itemRepository).Show();
}
void cmdRestart_Click(object sender, EventArgs e)
{
_appHost.Restart();
}
void cmdExit_Click(object sender, EventArgs e)
{
Close();
_appHost.Shutdown();
}
void cmdGtihub_Click(object sender, EventArgs e)
{
BrowserLauncher.OpenGithub(_logger);
}
void cmdStandardDocs_Click(object sender, EventArgs e)
{
BrowserLauncher.OpenStandardApiDocumentation(_configurationManager, _appHost, _logger);
}
void cmdSwagger_Click(object sender, EventArgs e)
{
BrowserLauncher.OpenSwagger(_configurationManager, _appHost, _logger);
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,8 @@
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Constants;
using MediaBrowser.Common.Implementations.Logging;
using MediaBrowser.Common.Implementations.Updates;
using MediaBrowser.Controller;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Implementations;
using MediaBrowser.ServerApplication.Native;
@ -16,7 +15,8 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Windows;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MediaBrowser.ServerApplication
@ -32,7 +32,6 @@ namespace MediaBrowser.ServerApplication
/// <summary>
/// Defines the entry point of the application.
/// </summary>
[STAThread]
public static void Main()
{
var startFlag = Environment.GetCommandLineArgs().ElementAtOrDefault(1);
@ -239,6 +238,8 @@ namespace MediaBrowser.ServerApplication
if (!runService)
{
HideSplashScreen();
ShowMainForm();
}
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
@ -248,6 +249,24 @@ namespace MediaBrowser.ServerApplication
Task.WaitAll(task);
}
private static MainForm _mainForm;
private static Thread _mainFormThread;
private static void ShowMainForm()
{
var thread = new Thread(() =>
{
_mainForm = new MainForm(_appHost.LogManager, _appHost, _appHost.ServerConfigurationManager, _appHost.UserManager, _appHost.LibraryManager, _appHost.JsonSerializer, _appHost.DisplayPreferencesRepository, _appHost.ItemRepository);
_mainForm.ShowDialog();
});
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Start();
_mainFormThread = thread;
}
private static SplashForm _splash;
private static Thread _splashThread;
private static void ShowSplashScreen(Version appVersion, Progress<double> progress, ILogger logger)
@ -270,8 +289,13 @@ namespace MediaBrowser.ServerApplication
{
if (_splash != null)
{
_splash.Close();
_splashThread = null;
Action act = () =>
{
_splash.Close();
_splashThread = null;
};
_splash.Invoke(act);
}
}

View file

@ -117,6 +117,12 @@
<DependentUpon>LogForm.cs</DependentUpon>
</Compile>
<Compile Include="Logging\WindowTraceListener.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="MainStartup.cs" />
<Compile Include="Native\Assemblies.cs" />
<Compile Include="Native\Autorun.cs" />
@ -146,9 +152,15 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LibraryViewer.resx">
<DependentUpon>LibraryViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Logging\LogForm.resx">
<DependentUpon>LogForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>

View file

@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -43,29 +42,4 @@ namespace MediaBrowser.ServerApplication.Splash
base.OnClosing(e);
}
}
public static class ControlHelper
{
#region Redraw Suspend/Resume
[DllImport("user32.dll", EntryPoint = "SendMessageA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private const int WM_SETREDRAW = 0xB;
public static void SuspendDrawing(this Control target)
{
SendMessage(target.Handle, WM_SETREDRAW, 0, 0);
}
public static void ResumeDrawing(this Control target) { ResumeDrawing(target, true); }
public static void ResumeDrawing(this Control target, bool redraw)
{
SendMessage(target.Handle, WM_SETREDRAW, 1, 0);
if (redraw)
{
target.Refresh();
}
}
#endregion
}
}