mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-07 20:08:59 +02:00
Fix: Emby notification icon remained visible after shutdown
Also implemented the recommended pattern for IDisposable.
This commit is contained in:
parent
74f511b2ee
commit
f7c3ee1c68
2 changed files with 26 additions and 49 deletions
|
@ -619,6 +619,12 @@ namespace MediaBrowser.ServerApplication
|
||||||
|
|
||||||
private static void ShutdownWindowsApplication()
|
private static void ShutdownWindowsApplication()
|
||||||
{
|
{
|
||||||
|
if (_serverNotifyIcon != null)
|
||||||
|
{
|
||||||
|
_serverNotifyIcon.Dispose();
|
||||||
|
_serverNotifyIcon = null;
|
||||||
|
}
|
||||||
|
|
||||||
//_logger.Info("Calling Application.Exit");
|
//_logger.Info("Calling Application.Exit");
|
||||||
//Application.Exit();
|
//Application.Exit();
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,13 @@ using MediaBrowser.Controller.Localization;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using MediaBrowser.Server.Startup.Common.Browser;
|
using MediaBrowser.Server.Startup.Common.Browser;
|
||||||
using System;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace MediaBrowser.ServerApplication
|
namespace MediaBrowser.ServerApplication
|
||||||
{
|
{
|
||||||
public class ServerNotifyIcon : IDisposable
|
public class ServerNotifyIcon : IDisposable
|
||||||
{
|
{
|
||||||
bool IsDisposing = false;
|
|
||||||
|
|
||||||
private NotifyIcon notifyIcon1;
|
private NotifyIcon notifyIcon1;
|
||||||
private ContextMenuStrip contextMenuStrip1;
|
private ContextMenuStrip contextMenuStrip1;
|
||||||
private ToolStripMenuItem cmdExit;
|
private ToolStripMenuItem cmdExit;
|
||||||
|
@ -21,25 +20,13 @@ namespace MediaBrowser.ServerApplication
|
||||||
private ToolStripMenuItem cmdRestart;
|
private ToolStripMenuItem cmdRestart;
|
||||||
private ToolStripSeparator toolStripSeparator1;
|
private ToolStripSeparator toolStripSeparator1;
|
||||||
private ToolStripMenuItem cmdCommunity;
|
private ToolStripMenuItem cmdCommunity;
|
||||||
|
private Container components;
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IServerApplicationHost _appHost;
|
private readonly IServerApplicationHost _appHost;
|
||||||
private readonly IServerConfigurationManager _configurationManager;
|
private readonly IServerConfigurationManager _configurationManager;
|
||||||
private readonly ILocalizationManager _localization;
|
private readonly ILocalizationManager _localization;
|
||||||
|
|
||||||
public bool Visible
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return notifyIcon1.Visible;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
Action act = () => notifyIcon1.Visible = false;
|
|
||||||
Invoke(act);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Invoke(Action action)
|
public void Invoke(Action action)
|
||||||
{
|
{
|
||||||
contextMenuStrip1.Invoke(action);
|
contextMenuStrip1.Invoke(action);
|
||||||
|
@ -55,7 +42,7 @@ namespace MediaBrowser.ServerApplication
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
|
|
||||||
var components = new System.ComponentModel.Container();
|
components = new System.ComponentModel.Container();
|
||||||
|
|
||||||
var resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
|
var resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
|
||||||
contextMenuStrip1 = new ContextMenuStrip(components);
|
contextMenuStrip1 = new ContextMenuStrip(components);
|
||||||
|
@ -138,32 +125,6 @@ namespace MediaBrowser.ServerApplication
|
||||||
LocalizeText();
|
LocalizeText();
|
||||||
|
|
||||||
notifyIcon1.DoubleClick += notifyIcon1_DoubleClick;
|
notifyIcon1.DoubleClick += notifyIcon1_DoubleClick;
|
||||||
Application.ThreadExit += Application_ThreadExit;
|
|
||||||
Application.ApplicationExit += Application_ApplicationExit;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application_ThreadExit(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
notifyIcon1.Visible = false;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application_ApplicationExit(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
notifyIcon1.Visible = false;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void notifyIcon1_DoubleClick(object sender, EventArgs e)
|
void notifyIcon1_DoubleClick(object sender, EventArgs e)
|
||||||
|
@ -222,16 +183,26 @@ namespace MediaBrowser.ServerApplication
|
||||||
_appHost.Shutdown();
|
_appHost.Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
~ServerNotifyIcon()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (!IsDisposing)
|
Dispose(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
IsDisposing = true;
|
if (disposing)
|
||||||
|
{
|
||||||
|
if (notifyIcon1 != null)
|
||||||
|
{
|
||||||
|
notifyIcon1.Visible = false;
|
||||||
|
notifyIcon1.Dispose();
|
||||||
|
notifyIcon1 = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (components != null)
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue