mirror of
https://github.com/Radarr/Radarr.git
synced 2024-10-03 22:57:18 +02:00
Fixed: Tray app restart
This commit is contained in:
parent
8b8f79d6c3
commit
6befbec381
@ -4,7 +4,6 @@
|
|||||||
<TargetFrameworks>net6.0</TargetFrameworks>
|
<TargetFrameworks>net6.0</TargetFrameworks>
|
||||||
|
|
||||||
<ApplicationIcon>..\NzbDrone.Host\Radarr.ico</ApplicationIcon>
|
<ApplicationIcon>..\NzbDrone.Host\Radarr.ico</ApplicationIcon>
|
||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="!$(RuntimeIdentifier.StartsWith('win'))">
|
<PropertyGroup Condition="!$(RuntimeIdentifier.StartsWith('win'))">
|
||||||
<AssemblyName>Radarr</AssemblyName>
|
<AssemblyName>Radarr</AssemblyName>
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<system.net>
|
|
||||||
<connectionManagement>
|
|
||||||
<add address="*" maxconnection="100" />
|
|
||||||
</connectionManagement>
|
|
||||||
</system.net>
|
|
||||||
<startup useLegacyV2RuntimeActivationPolicy="true">
|
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
|
|
||||||
</startup>
|
|
||||||
<runtime>
|
|
||||||
<loadFromRemoteSources enabled="true" />
|
|
||||||
</runtime>
|
|
||||||
</configuration>
|
|
@ -1,31 +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">
|
|
||||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
|
||||||
</requestedPrivileges>
|
|
||||||
</security>
|
|
||||||
</trustInfo>
|
|
||||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
|
||||||
<application>
|
|
||||||
|
|
||||||
<!-- 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>
|
|
@ -20,7 +20,6 @@ public class AppLifetime : IHostedService, IHandle<ApplicationShutdownRequested>
|
|||||||
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,
|
||||||
@ -30,7 +29,6 @@ public AppLifetime(IHostApplicationLifetime appLifetime,
|
|||||||
IBrowserService browserService,
|
IBrowserService browserService,
|
||||||
IProcessProvider processProvider,
|
IProcessProvider processProvider,
|
||||||
IEventAggregator eventAggregator,
|
IEventAggregator eventAggregator,
|
||||||
IUtilityModeRouter utilityModeRouter,
|
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_appLifetime = appLifetime;
|
_appLifetime = appLifetime;
|
||||||
@ -40,7 +38,6 @@ public AppLifetime(IHostApplicationLifetime appLifetime,
|
|||||||
_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);
|
||||||
|
@ -176,7 +176,18 @@ public static ApplicationModes GetApplicationMode(IStartupContext startupContext
|
|||||||
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\Radarr.ico</ApplicationIcon>
|
<ApplicationIcon>..\NzbDrone.Host\Radarr.ico</ApplicationIcon>
|
||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
|
||||||
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
|
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -13,6 +12,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\NzbDrone.Host\Radarr.Host.csproj" />
|
<ProjectReference Include="..\NzbDrone.Host\Radarr.Host.csproj" />
|
||||||
|
<ProjectReference Include="..\NzbDrone.Windows\Radarr.Windows.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
|
@ -4,9 +4,8 @@
|
|||||||
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 Radarr.Host;
|
using Radarr.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 @@ protected override void OnClosing(CancelEventArgs e)
|
|||||||
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 @@ protected override void Dispose(bool isDisposing)
|
|||||||
|
|
||||||
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 @@ private void LaunchBrowser(object sender, EventArgs e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,22 @@ public static class WindowsApp
|
|||||||
|
|
||||||
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: " + e.Message);
|
Logger.Fatal(e, "EPIC FAIL: " + e.Message);
|
||||||
var message = string.Format("{0}: {1}", e.GetType().Name, e.Message);
|
var message = string.Format("{0}: {1}", e.GetType().Name, e.ToString());
|
||||||
MessageBox.Show(text: message, buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error, caption: "Epic Fail!");
|
MessageBox.Show(text: message, buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error, caption: "Epic Fail!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<system.net>
|
|
||||||
<connectionManagement>
|
|
||||||
<add address="*" maxconnection="100" />
|
|
||||||
</connectionManagement>
|
|
||||||
</system.net>
|
|
||||||
<startup useLegacyV2RuntimeActivationPolicy="true">
|
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
|
|
||||||
</startup>
|
|
||||||
<runtime>
|
|
||||||
<loadFromRemoteSources enabled="true" />
|
|
||||||
</runtime>
|
|
||||||
</configuration>
|
|
@ -1,31 +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">
|
|
||||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
|
||||||
</requestedPrivileges>
|
|
||||||
</security>
|
|
||||||
</trustInfo>
|
|
||||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
|
||||||
<application>
|
|
||||||
|
|
||||||
<!-- 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
Block a user