fix(installer): skip rewriting the autostart shortcut when already current
RegisterAutostartStep rewrote the Startup .lnk on every install/update/repair even when it already pointed at the right worker exe. AutostartShortcut.Install now reads the existing shortcut's target via ShortcutFactory.TryGetTarget and skips the rewrite when it matches, reporting the skip in progress output. Legacy service/scheduled-task cleanup stays unconditional (migration safety net).
This commit is contained in:
@@ -22,13 +22,58 @@ public class AutostartShortcutTests
|
||||
var workerExe = Path.Combine(workerDir, "ClaudeDo.Worker.exe");
|
||||
File.WriteAllText(workerExe, "");
|
||||
|
||||
AutostartShortcut.Install(startup, workerExe);
|
||||
var created = AutostartShortcut.Install(startup, workerExe);
|
||||
|
||||
Assert.True(created);
|
||||
Assert.True(File.Exists(Path.Combine(startup, AutostartShortcut.FileName)));
|
||||
}
|
||||
finally { Directory.Delete(startup, true); Directory.Delete(workerDir, true); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Install_is_noop_when_shortcut_already_targets_same_exe()
|
||||
{
|
||||
var startup = TempDir();
|
||||
var workerDir = TempDir();
|
||||
try
|
||||
{
|
||||
var workerExe = Path.Combine(workerDir, "ClaudeDo.Worker.exe");
|
||||
File.WriteAllText(workerExe, "");
|
||||
AutostartShortcut.Install(startup, workerExe);
|
||||
var writtenAt = File.GetLastWriteTimeUtc(Path.Combine(startup, AutostartShortcut.FileName));
|
||||
|
||||
var createdAgain = AutostartShortcut.Install(startup, workerExe);
|
||||
|
||||
Assert.False(createdAgain);
|
||||
Assert.Equal(writtenAt, File.GetLastWriteTimeUtc(Path.Combine(startup, AutostartShortcut.FileName)));
|
||||
}
|
||||
finally { Directory.Delete(startup, true); Directory.Delete(workerDir, true); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Install_rewrites_shortcut_when_target_changed()
|
||||
{
|
||||
var startup = TempDir();
|
||||
var workerDir = TempDir();
|
||||
try
|
||||
{
|
||||
var oldExe = Path.Combine(workerDir, "old", "ClaudeDo.Worker.exe");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(oldExe)!);
|
||||
File.WriteAllText(oldExe, "");
|
||||
AutostartShortcut.Install(startup, oldExe);
|
||||
|
||||
var newExe = Path.Combine(workerDir, "new", "ClaudeDo.Worker.exe");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(newExe)!);
|
||||
File.WriteAllText(newExe, "");
|
||||
|
||||
var created = AutostartShortcut.Install(startup, newExe);
|
||||
|
||||
Assert.True(created);
|
||||
Assert.Equal(newExe, ShortcutFactory.TryGetTarget(Path.Combine(startup, AutostartShortcut.FileName)));
|
||||
}
|
||||
finally { Directory.Delete(startup, true); Directory.Delete(workerDir, true); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Remove_deletes_existing_lnk()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user