Fix the MSI installer issue when App plugin is running. (#557)

Our App plugin used the ShellLink.Open to retrieve the FullPath. But it would open the ink file exclusively. This may cause some problem. Especially when we try to upgrade some installed App through MSI installer, installer would throw exception and show a prompt to user.

Original discussion here:

1. https://github.com/microsoft/PowerToys/pull/37654
2. https://github.com/microsoft/PowerToys/pull/37924
3. https://github.com/microsoft/PowerToys/pull/37987

Tested locally with VS.


---------

Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
This commit is contained in:
moooyo
2025-03-19 02:21:04 +08:00
committed by GitHub
parent dc9bc113d8
commit 997c8acb46

View File

@@ -101,11 +101,17 @@ internal sealed class Win32ProgramRepository : ListRepository<Programs.Win32Prog
}
}
private void OnAppRenamed(object sender, RenamedEventArgs e)
private async Task OnAppRenamedAsync(object sender, RenamedEventArgs e)
{
var oldPath = e.OldFullPath;
var newPath = e.FullPath;
// fix for https://github.com/microsoft/PowerToys/issues/34391
// the msi installer creates a shortcut, which is detected by the PT Run and ends up in calling this OnAppRenamed method
// the thread needs to be halted for a short time to avoid locking the new shortcut file as we read it, otherwise the lock causes
// in the issue scenario that a warning is popping up during the msi install process.
await Task.Delay(1000).ConfigureAwait(false);
var extension = Path.GetExtension(newPath);
Win32Program.ApplicationType oldAppType = Win32Program.GetAppTypeFromPath(oldPath);
Programs.Win32Program? newApp = Win32Program.GetAppFromPath(newPath);
@@ -150,6 +156,14 @@ internal sealed class Win32ProgramRepository : ListRepository<Programs.Win32Prog
}
}
private void OnAppRenamed(object sender, RenamedEventArgs e)
{
Task.Run(async () =>
{
await OnAppRenamedAsync(sender, e).ConfigureAwait(false);
}).ConfigureAwait(false);
}
private void OnAppDeleted(object sender, FileSystemEventArgs e)
{
var path = e.FullPath;