From f462d127203dcacaf8236a50dc521c348168e3de Mon Sep 17 00:00:00 2001 From: Albie Spriddell Date: Wed, 20 Nov 2024 20:56:35 +0000 Subject: [PATCH] add autostart removal on uninstallation --- DragonFruit.OnionFruit.Windows/Program.cs | 11 ++++++++++- .../StartupLaunchService.cs | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/DragonFruit.OnionFruit.Windows/Program.cs b/DragonFruit.OnionFruit.Windows/Program.cs index 61beb36..1b39558 100644 --- a/DragonFruit.OnionFruit.Windows/Program.cs +++ b/DragonFruit.OnionFruit.Windows/Program.cs @@ -47,7 +47,8 @@ public static class Program public static void Main(string[] args) { HandleSecondInstance(); - VelopackApp.Build().Run(); + + VelopackApp.Build().WithBeforeUninstallFastCallback(_ => PerformRemovalCleanup()).Run(); // FluentAvalonia needs Windows 10.0.14393.0 (Anniversary Update) or later // see https://github.com/amwx/FluentAvalonia/issues/212 @@ -208,4 +209,12 @@ private static void PerformShutdown(object sender, UnhandledExceptionEventArgs e // shutdown any ongoing session _host?.Services.GetService().StopSession().AsTask().Wait(); } + + private static void PerformRemovalCleanup() + { + using (var startupManager = new StartupLaunchService(null, null)) + { + startupManager.SetStartupState(false); + } + } } \ No newline at end of file diff --git a/DragonFruit.OnionFruit.Windows/StartupLaunchService.cs b/DragonFruit.OnionFruit.Windows/StartupLaunchService.cs index a264038..c2a440b 100644 --- a/DragonFruit.OnionFruit.Windows/StartupLaunchService.cs +++ b/DragonFruit.OnionFruit.Windows/StartupLaunchService.cs @@ -38,7 +38,7 @@ public StartupLaunchService(IOnionFruitUpdater updater, string[] launchArgs) _startupCollectionKey = null; } - InstanceLaunchedByStartupService = launchArgs.Any(x => x.Equals(StartupAppArgs, StringComparison.OrdinalIgnoreCase)); + InstanceLaunchedByStartupService = launchArgs?.Any(x => x.Equals(StartupAppArgs, StringComparison.OrdinalIgnoreCase)) == true; } public bool InstanceLaunchedByStartupService { get; } @@ -71,7 +71,7 @@ public StartupLaunchState SetStartupState(bool enabled) private StartupLaunchState GetStartupStateImpl() { #if !DEBUG - if (!_updater.IsInstalled) + if (_updater?.IsInstalled != true) { return StartupLaunchState.Blocked; }