fix(app): Start with Windows belongs to the copy that set it; the uninstaller removes sign-in entries

The client's HKCU Run value now counts as on only when it starts this executable, so a portable copy, a
second install or a development build no longer shows the box ticked, and starting one no longer rewrites the
entry to itself. Refresh only follows an entry whose program an update renamed in this copy's folder, and
unticking removes only this copy's entry. Portable copies keep the choice in memory and hide the Startup row,
since they leave nothing in the registry.

The uninstaller removes the client's and the Uploader's sign-in entries when they start a program of the folder
it removes. StartupCommand in Titano.Core holds the Run key, the value names and the command parsing shared by
both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 10:35:13 +00:00
1 parent d25ecca64e
commit 97c6484c74
8 files changed
+240 -35

No files matched your search

@@ -0,0 +1,45 @@
using Titano.App.Infrastructure;
using Titano.Core.IO;
using Titano.Testing;
namespace Titano.App.Tests.Infrastructure;
/// <summary>Settings › General › Startup: one sign-in entry shared by every copy of Titano, which no copy takes over by starting.</summary>
public sealed class StartWithWindowsTests
{
private const string Installed = @"C:\Users\ada\AppData\Local\Programs\Titano\Titano.exe";
[Test]
public void AStartFollowsOnlyAnEntryAnUpdateLeftBehindInItsOwnFolder()
{
static bool Gone(string path) => false;
static bool Present(string path) => true;
var installed = StartupCommand.Format(Installed, RunKeyStartWithWindows.MinimizedOption);
// The entry already starts this copy: nothing to write.
Assert.False(RunKeyStartWithWindows.Follows(installed, Installed, Gone));
// An update renamed the program in its folder: the entry follows it.
Assert.True(RunKeyStartWithWindows.Follows(StartupCommand.Format(@"C:\Users\ada\AppData\Local\Programs\Titano\Titano.old.exe", "--minimized"),
Installed, Gone));
// The installed copy is still there: a portable copy, a second install or a development build that starts leaves it alone.
Assert.False(RunKeyStartWithWindows.Follows(installed, @"E:\Titano\Titano.exe", Present));
Assert.False(RunKeyStartWithWindows.Follows(installed, @"C:\src\Titano\bin\Debug\Titano.exe", Present));
// Gone from another folder (a USB stick that is not plugged in): still not this copy's entry.
Assert.False(RunKeyStartWithWindows.Follows(installed, @"E:\Titano\Titano.exe", Gone));
// No entry, or no executable path: nothing to follow.
Assert.False(RunKeyStartWithWindows.Follows(null, Installed, Gone));
Assert.False(RunKeyStartWithWindows.Follows(installed, null, Gone));
}
[Test]
public void ScreenshotsAndPortableCopiesKeepTheChoiceInMemory()
{
var startup = new MemoryStartWithWindows();
Assert.False(startup.IsEnabled);
startup.SetEnabled(true);
startup.Refresh();
Assert.True(startup.IsEnabled);
startup.SetEnabled(false);
Assert.False(startup.IsEnabled);
}
}
@@ -0,0 +1,58 @@
using Titano.Core.IO;
using Titano.Testing;
namespace Titano.Core.Tests.Foundation;
/// <summary>The sign-in entries of the client and the Uploader: which copy they start, and which folder the uninstaller may clean.</summary>
public sealed class StartupCommandTests
{
private const string Installed = @"C:\Users\ada\AppData\Local\Programs\Titano\Titano.exe";
[Test]
public void TheCommandNamesItsProgram()
{
var command = StartupCommand.Format(Installed, "--minimized");
Assert.Equal("\"" + Installed + "\" --minimized", command);
Assert.Equal(Installed, StartupCommand.Executable(command));
Assert.Equal(@"C:\Users\ada\AppData\Local\Programs\Titano", StartupCommand.Folder(command));
// Written by hand or by an older tool: unquoted, or with spaces around.
Assert.Equal(@"D:\Titano\Titano.exe", StartupCommand.Executable(@" D:\Titano\Titano.exe --minimized "));
Assert.Equal(@"D:\Titano\Titano.exe", StartupCommand.Executable(@"D:\Titano\Titano.exe"));
Assert.Null(StartupCommand.Executable(null));
Assert.Null(StartupCommand.Executable(" "));
Assert.Null(StartupCommand.Executable("\"unterminated --minimized"));
Assert.Null(StartupCommand.Executable("\"\" --minimized"));
Assert.Null(StartupCommand.Folder("Titano.exe"));
Assert.Equal(@"D:\Titano", StartupCommand.FolderOf(@"D:\Titano\Titano.exe"));
}
[Test]
public void AnEntryBelongsToTheCopyItStarts()
{
var command = StartupCommand.Format(Installed, "--minimized");
Assert.True(StartupCommand.Starts(command, Installed));
Assert.True(StartupCommand.Starts(command, Installed.ToUpperInvariant()), "Windows paths ignore case");
// A portable copy on a USB stick, a second install or a development build is another program.
Assert.False(StartupCommand.Starts(command, @"E:\Titano\Titano.exe"));
Assert.False(StartupCommand.Starts(command, @"C:\Users\ada\AppData\Local\Programs\Titano\Titano.exe.old"));
Assert.False(StartupCommand.Starts(command, null));
Assert.False(StartupCommand.Starts(null, Installed));
}
[Test]
public void TheUninstallerRemovesOnlyTheEntriesOfItsFolder()
{
var client = StartupCommand.Format(Installed, "--minimized");
var uploader = StartupCommand.Format(@"C:\Users\ada\AppData\Local\Programs\Titano\Uploader\Titano.Uploader.exe", "--tray");
const string folder = @"C:\Users\ada\AppData\Local\Programs\Titano";
Assert.True(StartupCommand.StartsFrom(client, folder));
Assert.True(StartupCommand.StartsFrom(client, folder + @"\"));
Assert.True(StartupCommand.StartsFrom(uploader, folder.ToLowerInvariant()));
// A sibling folder that shares the name's start, another drive, or nothing at all stay.
Assert.False(StartupCommand.StartsFrom(StartupCommand.Format(@"C:\Users\ada\AppData\Local\Programs\Titano2\Titano.exe", "--minimized"), folder));
Assert.False(StartupCommand.StartsFrom(StartupCommand.Format(@"E:\Titano\Titano.exe", "--minimized"), folder));
Assert.False(StartupCommand.StartsFrom(StartupCommand.Format(folder, "--minimized"), folder));
Assert.False(StartupCommand.StartsFrom(null, folder));
Assert.False(StartupCommand.StartsFrom(client, @"\"));
}
}