diff --git a/src/NzbDrone.Console/Lidarr.Console.csproj b/src/NzbDrone.Console/Lidarr.Console.csproj index 6011e44f1..3d21c1e76 100644 --- a/src/NzbDrone.Console/Lidarr.Console.csproj +++ b/src/NzbDrone.Console/Lidarr.Console.csproj @@ -4,7 +4,6 @@ net6.0 ..\NzbDrone.Host\NzbDrone.ico - app.manifest Lidarr diff --git a/src/NzbDrone.Console/app.manifest b/src/NzbDrone.Console/app.manifest deleted file mode 100644 index 8e6eb2fea..000000000 --- a/src/NzbDrone.Console/app.manifest +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - diff --git a/src/NzbDrone.Host/AppLifetime.cs b/src/NzbDrone.Host/AppLifetime.cs index d0d0955ce..0a181a7db 100644 --- a/src/NzbDrone.Host/AppLifetime.cs +++ b/src/NzbDrone.Host/AppLifetime.cs @@ -19,7 +19,6 @@ namespace NzbDrone.Host private readonly IBrowserService _browserService; private readonly IProcessProvider _processProvider; private readonly IEventAggregator _eventAggregator; - private readonly IUtilityModeRouter _utilityModeRouter; private readonly Logger _logger; public AppLifetime(IHostApplicationLifetime appLifetime, @@ -29,7 +28,6 @@ namespace NzbDrone.Host IBrowserService browserService, IProcessProvider processProvider, IEventAggregator eventAggregator, - IUtilityModeRouter utilityModeRouter, Logger logger) { _appLifetime = appLifetime; @@ -39,7 +37,6 @@ namespace NzbDrone.Host _browserService = browserService; _processProvider = processProvider; _eventAggregator = eventAggregator; - _utilityModeRouter = utilityModeRouter; _logger = logger; appLifetime.ApplicationStarted.Register(OnAppStarted); diff --git a/src/NzbDrone.Host/Bootstrap.cs b/src/NzbDrone.Host/Bootstrap.cs index 17d7f5276..deab120fe 100644 --- a/src/NzbDrone.Host/Bootstrap.cs +++ b/src/NzbDrone.Host/Bootstrap.cs @@ -174,7 +174,18 @@ namespace NzbDrone.Host 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; } diff --git a/src/NzbDrone/Lidarr.csproj b/src/NzbDrone/Lidarr.csproj index c92a70a8b..1c2a37522 100644 --- a/src/NzbDrone/Lidarr.csproj +++ b/src/NzbDrone/Lidarr.csproj @@ -5,7 +5,6 @@ win-x64;win-x86 true ..\NzbDrone.Host\NzbDrone.ico - app.manifest true diff --git a/src/NzbDrone/SysTray/SysTrayApp.cs b/src/NzbDrone/SysTray/SysTrayApp.cs index 9db8aa9bd..420ac2b47 100644 --- a/src/NzbDrone/SysTray/SysTrayApp.cs +++ b/src/NzbDrone/SysTray/SysTrayApp.cs @@ -4,9 +4,8 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Extensions.Hosting; -using NLog; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Processes; +using NzbDrone.Core.Lifecycle; using NzbDrone.Host; namespace NzbDrone.SysTray @@ -14,28 +13,19 @@ namespace NzbDrone.SysTray public class SystemTrayApp : Form, IHostedService { private readonly IBrowserService _browserService; - private readonly IRuntimeInfo _runtimeInfo; - private readonly IProcessProvider _processProvider; + private readonly ILifecycleService _lifecycle; private readonly NotifyIcon _trayIcon = new NotifyIcon(); private readonly ContextMenuStrip _trayMenu = new ContextMenuStrip(); - public SystemTrayApp(IBrowserService browserService, IRuntimeInfo runtimeInfo, IProcessProvider processProvider) + public SystemTrayApp(IBrowserService browserService, ILifecycleService lifecycle) { _browserService = browserService; - _runtimeInfo = runtimeInfo; - _processProvider = processProvider; + _lifecycle = lifecycle; } 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 ToolStripSeparator()); _trayMenu.Items.Add(new ToolStripMenuItem("Exit", null, OnExit)); @@ -69,12 +59,6 @@ namespace NzbDrone.SysTray DisposeTrayIcon(); } - protected override void OnClosed(EventArgs e) - { - Console.WriteLine("Closing"); - base.OnClosed(e); - } - protected override void OnLoad(EventArgs e) { Visible = false; @@ -102,8 +86,7 @@ namespace NzbDrone.SysTray private void OnExit(object sender, EventArgs e) { - LogManager.Configuration = null; - Environment.Exit(0); + _lifecycle.Shutdown(); } 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() { - try - { - _trayIcon.Visible = false; - _trayIcon.Icon = null; - _trayIcon.Visible = false; - _trayIcon.Dispose(); - } - catch (Exception) + if (_trayIcon == null) { + return; } + + _trayIcon.Visible = false; + _trayIcon.Icon = null; + _trayIcon.Visible = false; + _trayIcon.Dispose(); } } } diff --git a/src/NzbDrone/WindowsApp.cs b/src/NzbDrone/WindowsApp.cs index 361e26d44..db2d34ddb 100644 --- a/src/NzbDrone/WindowsApp.cs +++ b/src/NzbDrone/WindowsApp.cs @@ -16,21 +16,23 @@ namespace NzbDrone public static void Main(string[] args) { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.SetHighDpiMode(HighDpiMode.SystemAware); + try { var startupArgs = new StartupContext(args); NzbDroneLogger.Register(startupArgs, false, true); - Bootstrap.Start(args, e => - { - e.ConfigureServices((_, s) => s.AddSingleton()); - }); + Bootstrap.Start(args, e => { e.ConfigureServices((_, s) => s.AddSingleton()); }); } catch (Exception e) { - Logger.Fatal(e, "EPIC FAIL"); - MessageBox.Show($"{e.GetType().Name}: {e.Message}", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error, caption: "Epic Fail!"); + Logger.Fatal(e, "EPIC FAIL: " + 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!"); } } } diff --git a/src/NzbDrone/app.manifest b/src/NzbDrone/app.manifest deleted file mode 100644 index 8e6eb2fea..000000000 --- a/src/NzbDrone/app.manifest +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - -