fix(startup): Start with Windows honours an entry Task Manager turned off
Task Manager's Startup tab keeps the Run value and writes a StartupApproved\Run value whose odd first byte means off. The client and the Uploader now show such an entry as off; ticking the box removes the marker so the entry runs again, unticking removes it with the Run value, and re-pointing the command after an update leaves it as it is. Core/IO/StartupApproval holds the rule; the registry hive is injectable for tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
5 files changed
+231
-47
No files matched your search
@@ -1,6 +1,8 @@
|
||||
using Microsoft.Win32;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.Core.IO;
|
||||
using Titano.Testing;
|
||||
using Titano.Uploader.Infrastructure;
|
||||
|
||||
namespace Titano.App.Tests.Infrastructure;
|
||||
|
||||
@@ -31,6 +33,77 @@ public sealed class StartWithWindowsTests
|
||||
Assert.False(RunKeyStartWithWindows.Follows(installed, null, Gone));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void AnEntryTaskManagerTurnedOffShowsOffUntilTheBoxIsTickedAgain()
|
||||
{
|
||||
// A scratch hive of its own: the user's sign-in entries are never touched.
|
||||
var hive = @"Software\Titano.StartupTests." + Guid.NewGuid().ToString("N");
|
||||
try
|
||||
{
|
||||
using var root = Registry.CurrentUser.CreateSubKey(hive, writable: true);
|
||||
var startup = new RunKeyStartWithWindows(Installed, root);
|
||||
startup.SetEnabled(true);
|
||||
Assert.True(startup.IsEnabled);
|
||||
|
||||
// Task Manager › Startup › Disable keeps the Run value and writes the switch apart.
|
||||
TurnOff(root, StartupCommand.ClientValue);
|
||||
Assert.False(startup.IsEnabled, "shown as off");
|
||||
Assert.True(StartupCommand.Starts(Value(root, StartupCommand.RunKey, StartupCommand.ClientValue) as string, Installed), "the command stays");
|
||||
|
||||
// An update renamed the program: the command follows it, and the entry stays off.
|
||||
const string renamed = @"C:\Users\ada\AppData\Local\Programs\Titano\Titano.next.exe";
|
||||
var updated = new RunKeyStartWithWindows(renamed, root);
|
||||
updated.Refresh();
|
||||
Assert.True(StartupCommand.Starts(Value(root, StartupCommand.RunKey, StartupCommand.ClientValue) as string, renamed));
|
||||
Assert.False(updated.IsEnabled, "still off after the update");
|
||||
|
||||
// Ticking the box turns it on again; unticking leaves nothing behind.
|
||||
updated.SetEnabled(true);
|
||||
Assert.True(updated.IsEnabled);
|
||||
Assert.Null(Value(root, StartupApproval.RunKey, StartupCommand.ClientValue));
|
||||
TurnOff(root, StartupCommand.ClientValue);
|
||||
updated.SetEnabled(false);
|
||||
Assert.Null(Value(root, StartupCommand.RunKey, StartupCommand.ClientValue));
|
||||
Assert.Null(Value(root, StartupApproval.RunKey, StartupCommand.ClientValue));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Registry.CurrentUser.DeleteSubKeyTree(hive, throwOnMissingSubKey: false);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void TheUploadersEntryHonoursTaskManagerToo()
|
||||
{
|
||||
var hive = @"Software\Titano.StartupTests." + Guid.NewGuid().ToString("N");
|
||||
try
|
||||
{
|
||||
using var root = Registry.CurrentUser.CreateSubKey(hive, writable: true);
|
||||
var uploader = @"C:\Users\ada\AppData\Local\Programs\Titano\Uploader\Titano.Uploader.exe";
|
||||
var startup = new RunKeyStartupRegistration(uploader, root);
|
||||
startup.SetEnabled(true);
|
||||
Assert.True(startup.IsEnabled);
|
||||
|
||||
TurnOff(root, StartupCommand.UploaderValue);
|
||||
Assert.False(startup.IsEnabled, "shown as off");
|
||||
startup.Refresh();
|
||||
Assert.False(startup.IsEnabled, "a refresh keeps it off");
|
||||
|
||||
startup.SetEnabled(true);
|
||||
Assert.True(startup.IsEnabled);
|
||||
TurnOff(root, StartupCommand.UploaderValue);
|
||||
startup.SetEnabled(false);
|
||||
Assert.Null(Value(root, StartupCommand.RunKey, StartupCommand.UploaderValue));
|
||||
Assert.Null(Value(root, StartupApproval.RunKey, StartupCommand.UploaderValue));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Registry.CurrentUser.DeleteSubKeyTree(hive, throwOnMissingSubKey: false);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ScreenshotsAndPortableCopiesKeepTheChoiceInMemory()
|
||||
{
|
||||
@@ -42,4 +115,17 @@ public sealed class StartWithWindowsTests
|
||||
startup.SetEnabled(false);
|
||||
Assert.False(startup.IsEnabled);
|
||||
}
|
||||
|
||||
/// <summary>What Task Manager writes when the user disables an entry: 0x03, three zero bytes, then when.</summary>
|
||||
private static void TurnOff(RegistryKey root, string name)
|
||||
{
|
||||
using var approved = root.CreateSubKey(StartupApproval.RunKey, writable: true);
|
||||
approved.SetValue(name, new byte[] { 0x03, 0, 0, 0, 0x60, 0x1B, 0x3C, 0x92, 0x8A, 0x3F, 0xDB, 0x01 }, RegistryValueKind.Binary);
|
||||
}
|
||||
|
||||
private static object? Value(RegistryKey root, string subKey, string name)
|
||||
{
|
||||
using var key = root.OpenSubKey(subKey);
|
||||
return key?.GetValue(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Titano.Core.IO;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Foundation;
|
||||
|
||||
/// <summary>The switch Task Manager's Startup tab keeps apart from a sign-in entry's command.</summary>
|
||||
public sealed class StartupApprovalTests
|
||||
{
|
||||
[Test]
|
||||
public void AnOddFirstByteMeansTurnedOff()
|
||||
{
|
||||
// As Task Manager writes them: a state, three zero bytes, then the time it was turned off.
|
||||
Assert.True(StartupApproval.IsTurnedOff([0x03, 0, 0, 0, 0x60, 0x1B, 0x3C, 0x92, 0x8A, 0x3F, 0xDB, 0x01]));
|
||||
Assert.True(StartupApproval.IsTurnedOff([0x01, 0, 0, 0]));
|
||||
Assert.False(StartupApproval.IsTurnedOff([0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
Assert.False(StartupApproval.IsTurnedOff([0x06, 0, 0, 0]));
|
||||
// Never touched in Task Manager, or a value of another type: the entry is on.
|
||||
Assert.False(StartupApproval.IsTurnedOff(null));
|
||||
Assert.False(StartupApproval.IsTurnedOff([]));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user