mirror of https://github.com/lidarr/Lidarr
Fixed: Tray app restart
Co-Authored-By: ta264 <ta264@users.noreply.github.com>
This commit is contained in:
parent
11dec985b0
commit
9b4605be03
|
@ -4,7 +4,6 @@
|
||||||
<TargetFrameworks>net6.0</TargetFrameworks>
|
<TargetFrameworks>net6.0</TargetFrameworks>
|
||||||
|
|
||||||
<ApplicationIcon>..\NzbDrone.Host\NzbDrone.ico</ApplicationIcon>
|
<ApplicationIcon>..\NzbDrone.Host\NzbDrone.ico</ApplicationIcon>
|
||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="!$(RuntimeIdentifier.StartsWith('win'))">
|
<PropertyGroup Condition="!$(RuntimeIdentifier.StartsWith('win'))">
|
||||||
<AssemblyName>Lidarr</AssemblyName>
|
<AssemblyName>Lidarr</AssemblyName>
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
|
||||||
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
|
|
||||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
|
||||||
<security>
|
|
||||||
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
|
|
||||||
<!-- UAC Manifest Options
|
|
||||||
If you want to change the Windows User Account Control level replace the
|
|
||||||
requestedExecutionLevel node with one of the following.
|
|
||||||
|
|
||||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
|
||||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
|
||||||
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
|
|
||||||
|
|
||||||
Specifying requestedExecutionLevel element will disable file and registry virtualization.
|
|
||||||
Remove this element if your application requires this virtualization for backwards
|
|
||||||
compatibility.
|
|
||||||
-->
|
|
||||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
|
||||||
</requestedPrivileges>
|
|
||||||
</security>
|
|
||||||
</trustInfo>
|
|
||||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
|
||||||
<application>
|
|
||||||
<!-- A list of the Windows versions that this application has been tested on and is
|
|
||||||
is designed to work with. Uncomment the appropriate elements and Windows will
|
|
||||||
automatically selected the most compatible environment. -->
|
|
||||||
|
|
||||||
<!-- Windows Vista -->
|
|
||||||
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
|
|
||||||
|
|
||||||
<!-- Windows 7 -->
|
|
||||||
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
|
|
||||||
|
|
||||||
<!-- Windows 8 -->
|
|
||||||
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
|
|
||||||
|
|
||||||
<!-- Windows 8.1 -->
|
|
||||||
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
|
|
||||||
|
|
||||||
<!-- Windows 10 -->
|
|
||||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
|
||||||
|
|
||||||
</application>
|
|
||||||
</compatibility>
|
|
||||||
|
|
||||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
|
||||||
<windowsSettings>
|
|
||||||
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
|
|
||||||
</windowsSettings>
|
|
||||||
</application>
|
|
||||||
</assembly>
|
|
|
@ -19,7 +19,6 @@ namespace NzbDrone.Host
|
||||||
private readonly IBrowserService _browserService;
|
private readonly IBrowserService _browserService;
|
||||||
private readonly IProcessProvider _processProvider;
|
private readonly IProcessProvider _processProvider;
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private readonly IUtilityModeRouter _utilityModeRouter;
|
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public AppLifetime(IHostApplicationLifetime appLifetime,
|
public AppLifetime(IHostApplicationLifetime appLifetime,
|
||||||
|
@ -29,7 +28,6 @@ namespace NzbDrone.Host
|
||||||
IBrowserService browserService,
|
IBrowserService browserService,
|
||||||
IProcessProvider processProvider,
|
IProcessProvider processProvider,
|
||||||
IEventAggregator eventAggregator,
|
IEventAggregator eventAggregator,
|
||||||
IUtilityModeRouter utilityModeRouter,
|
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_appLifetime = appLifetime;
|
_appLifetime = appLifetime;
|
||||||
|
@ -39,7 +37,6 @@ namespace NzbDrone.Host
|
||||||
_browserService = browserService;
|
_browserService = browserService;
|
||||||
_processProvider = processProvider;
|
_processProvider = processProvider;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
_utilityModeRouter = utilityModeRouter;
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
appLifetime.ApplicationStarted.Register(OnAppStarted);
|
appLifetime.ApplicationStarted.Register(OnAppStarted);
|
||||||
|
|
|
@ -174,7 +174,18 @@ namespace NzbDrone.Host
|
||||||
return ApplicationModes.UninstallService;
|
return ApplicationModes.UninstallService;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OsInfo.IsWindows && WindowsServiceHelpers.IsWindowsService())
|
// IsWindowsService can throw sometimes, so wrap it
|
||||||
|
bool isWindowsService = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
isWindowsService = WindowsServiceHelpers.IsWindowsService();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// don't care
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OsInfo.IsWindows && isWindowsService)
|
||||||
{
|
{
|
||||||
return ApplicationModes.Service;
|
return ApplicationModes.Service;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
|
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<ApplicationIcon>..\NzbDrone.Host\NzbDrone.ico</ApplicationIcon>
|
<ApplicationIcon>..\NzbDrone.Host\NzbDrone.ico</ApplicationIcon>
|
||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
|
||||||
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
|
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -4,9 +4,8 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using NLog;
|
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Common.Processes;
|
using NzbDrone.Core.Lifecycle;
|
||||||
using NzbDrone.Host;
|
using NzbDrone.Host;
|
||||||
|
|
||||||
namespace NzbDrone.SysTray
|
namespace NzbDrone.SysTray
|
||||||
|
@ -14,28 +13,19 @@ namespace NzbDrone.SysTray
|
||||||
public class SystemTrayApp : Form, IHostedService
|
public class SystemTrayApp : Form, IHostedService
|
||||||
{
|
{
|
||||||
private readonly IBrowserService _browserService;
|
private readonly IBrowserService _browserService;
|
||||||
private readonly IRuntimeInfo _runtimeInfo;
|
private readonly ILifecycleService _lifecycle;
|
||||||
private readonly IProcessProvider _processProvider;
|
|
||||||
|
|
||||||
private readonly NotifyIcon _trayIcon = new NotifyIcon();
|
private readonly NotifyIcon _trayIcon = new NotifyIcon();
|
||||||
private readonly ContextMenuStrip _trayMenu = new ContextMenuStrip();
|
private readonly ContextMenuStrip _trayMenu = new ContextMenuStrip();
|
||||||
|
|
||||||
public SystemTrayApp(IBrowserService browserService, IRuntimeInfo runtimeInfo, IProcessProvider processProvider)
|
public SystemTrayApp(IBrowserService browserService, ILifecycleService lifecycle)
|
||||||
{
|
{
|
||||||
_browserService = browserService;
|
_browserService = browserService;
|
||||||
_runtimeInfo = runtimeInfo;
|
_lifecycle = lifecycle;
|
||||||
_processProvider = processProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
Application.ThreadException += OnThreadException;
|
|
||||||
Application.ApplicationExit += OnApplicationExit;
|
|
||||||
|
|
||||||
Application.SetHighDpiMode(HighDpiMode.PerMonitor);
|
|
||||||
Application.EnableVisualStyles();
|
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
|
||||||
|
|
||||||
_trayMenu.Items.Add(new ToolStripMenuItem("Launch Browser", null, LaunchBrowser));
|
_trayMenu.Items.Add(new ToolStripMenuItem("Launch Browser", null, LaunchBrowser));
|
||||||
_trayMenu.Items.Add(new ToolStripSeparator());
|
_trayMenu.Items.Add(new ToolStripSeparator());
|
||||||
_trayMenu.Items.Add(new ToolStripMenuItem("Exit", null, OnExit));
|
_trayMenu.Items.Add(new ToolStripMenuItem("Exit", null, OnExit));
|
||||||
|
@ -69,12 +59,6 @@ namespace NzbDrone.SysTray
|
||||||
DisposeTrayIcon();
|
DisposeTrayIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnClosed(EventArgs e)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Closing");
|
|
||||||
base.OnClosed(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnLoad(EventArgs e)
|
protected override void OnLoad(EventArgs e)
|
||||||
{
|
{
|
||||||
Visible = false;
|
Visible = false;
|
||||||
|
@ -102,8 +86,7 @@ namespace NzbDrone.SysTray
|
||||||
|
|
||||||
private void OnExit(object sender, EventArgs e)
|
private void OnExit(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LogManager.Configuration = null;
|
_lifecycle.Shutdown();
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LaunchBrowser(object sender, EventArgs e)
|
private void LaunchBrowser(object sender, EventArgs e)
|
||||||
|
@ -117,33 +100,17 @@ namespace NzbDrone.SysTray
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnApplicationExit(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_runtimeInfo.RestartPending)
|
|
||||||
{
|
|
||||||
_processProvider.SpawnNewProcess(_runtimeInfo.ExecutingApplication, "--restart --nobrowser");
|
|
||||||
}
|
|
||||||
|
|
||||||
DisposeTrayIcon();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnThreadException(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
DisposeTrayIcon();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DisposeTrayIcon()
|
private void DisposeTrayIcon()
|
||||||
{
|
{
|
||||||
try
|
if (_trayIcon == null)
|
||||||
{
|
|
||||||
_trayIcon.Visible = false;
|
|
||||||
_trayIcon.Icon = null;
|
|
||||||
_trayIcon.Visible = false;
|
|
||||||
_trayIcon.Dispose();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_trayIcon.Visible = false;
|
||||||
|
_trayIcon.Icon = null;
|
||||||
|
_trayIcon.Visible = false;
|
||||||
|
_trayIcon.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,21 +16,23 @@ namespace NzbDrone
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
Application.EnableVisualStyles();
|
||||||
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var startupArgs = new StartupContext(args);
|
var startupArgs = new StartupContext(args);
|
||||||
|
|
||||||
NzbDroneLogger.Register(startupArgs, false, true);
|
NzbDroneLogger.Register(startupArgs, false, true);
|
||||||
|
|
||||||
Bootstrap.Start(args, e =>
|
Bootstrap.Start(args, e => { e.ConfigureServices((_, s) => s.AddSingleton<IHostedService, SystemTrayApp>()); });
|
||||||
{
|
|
||||||
e.ConfigureServices((_, s) => s.AddSingleton<IHostedService, SystemTrayApp>());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Fatal(e, "EPIC FAIL");
|
Logger.Fatal(e, "EPIC FAIL: " + e.Message);
|
||||||
MessageBox.Show($"{e.GetType().Name}: {e.Message}", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error, caption: "Epic Fail!");
|
var message = string.Format("{0}: {1}", e.GetType().Name, e.ToString());
|
||||||
|
MessageBox.Show(text: message, buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error, caption: "Epic Fail!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
|
||||||
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
|
|
||||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
|
||||||
<security>
|
|
||||||
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
|
|
||||||
<!-- UAC Manifest Options
|
|
||||||
If you want to change the Windows User Account Control level replace the
|
|
||||||
requestedExecutionLevel node with one of the following.
|
|
||||||
|
|
||||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
|
||||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
|
||||||
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
|
|
||||||
|
|
||||||
Specifying requestedExecutionLevel element will disable file and registry virtualization.
|
|
||||||
Remove this element if your application requires this virtualization for backwards
|
|
||||||
compatibility.
|
|
||||||
-->
|
|
||||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
|
||||||
</requestedPrivileges>
|
|
||||||
</security>
|
|
||||||
</trustInfo>
|
|
||||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
|
||||||
<application>
|
|
||||||
<!-- A list of the Windows versions that this application has been tested on and is
|
|
||||||
is designed to work with. Uncomment the appropriate elements and Windows will
|
|
||||||
automatically selected the most compatible environment. -->
|
|
||||||
|
|
||||||
<!-- Windows Vista -->
|
|
||||||
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
|
|
||||||
|
|
||||||
<!-- Windows 7 -->
|
|
||||||
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
|
|
||||||
|
|
||||||
<!-- Windows 8 -->
|
|
||||||
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
|
|
||||||
|
|
||||||
<!-- Windows 8.1 -->
|
|
||||||
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
|
|
||||||
|
|
||||||
<!-- Windows 10 -->
|
|
||||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
|
||||||
|
|
||||||
</application>
|
|
||||||
</compatibility>
|
|
||||||
|
|
||||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
|
||||||
<windowsSettings>
|
|
||||||
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
|
|
||||||
</windowsSettings>
|
|
||||||
</application>
|
|
||||||
</assembly>
|
|
Loading…
Reference in New Issue