From 2e69a944d9ab0efdb73cfd65719f3e47f4c7abf3 Mon Sep 17 00:00:00 2001 From: winewill Date: Wed, 18 Nov 2026 16:45:37 +0800 Subject: [PATCH] fix(desktop): include all uncertain uninstall targets in fallback reports --- apps/desktop/installer/uninstall.nsh | 7 +++++++ apps/desktop/tests/expected/windows-uninstall.json | 1 + apps/desktop/tests/windows-uninstall-smoke.ps1 | 13 ++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/desktop/installer/uninstall.nsh b/apps/desktop/installer/uninstall.nsh index f61af3884b..714e7826c7 100644 --- a/apps/desktop/installer/uninstall.nsh +++ b/apps/desktop/installer/uninstall.nsh @@ -184,6 +184,13 @@ Function un.RunRegistrationCleanup ${If} $0 != 0 StrCpy $UnCleanupResult 1 DetailPrint $1 + ${If} $UnDirectoryOnly == 1 + ${AndIf} $UnRegistrationArguments != "-UnownedOnly" + System::Call '$PLUGINSDIR\window-frame.dll::UninstallNote(p $UnSession, w "[unverified] Registration cleanup targets: HKCU\${UNINSTALL_REGISTRY_KEY}; $oldDesktopLink; $oldStartMenuLink") ?c' + !ifdef UNINSTALL_REGISTRY_KEY_2 + System::Call '$PLUGINSDIR\window-frame.dll::UninstallNote(p $UnSession, w "[unverified] Registration cleanup target: HKCU\${UNINSTALL_REGISTRY_KEY_2}") ?c' + !endif + ${EndIf} System::Call '$PLUGINSDIR\window-frame.dll::UninstallNote(p $UnSession, w "Registration cleanup failed or did not return a result. Exit: $0. Targets: HKCU\${DSH_COMMAND_ENVIRONMENT_KEY} [Path]; HKCU\${DSH_COMMAND_OWNER_KEY}; HKCU\${DSH_PROTOCOL_KEY}. Unverified registrations may remain.") ?c' ${EndIf} FunctionEnd diff --git a/apps/desktop/tests/expected/windows-uninstall.json b/apps/desktop/tests/expected/windows-uninstall.json index 635208dc97..148db0ed5c 100644 --- a/apps/desktop/tests/expected/windows-uninstall.json +++ b/apps/desktop/tests/expected/windows-uninstall.json @@ -4,6 +4,7 @@ "silent", "unowned", "missing-location", + "missing-location-short", "missing-location-foreign", "owned-retained", "upgrade", diff --git a/apps/desktop/tests/windows-uninstall-smoke.ps1 b/apps/desktop/tests/windows-uninstall-smoke.ps1 index 77fbc55297..db12575c5c 100644 --- a/apps/desktop/tests/windows-uninstall-smoke.ps1 +++ b/apps/desktop/tests/windows-uninstall-smoke.ps1 @@ -71,15 +71,22 @@ try { [IO.File]::WriteAllText((Join-Path $userDataPath 'Local State'), 'chromium profile') [IO.File]::WriteAllText((Join-Path $cachePath 'download.txt'), 'update') Copy-Item -LiteralPath (Join-Path $installPath ('Uninstall ' + $ProductName + '.exe')) -Destination $uninstaller -Force - $missingLocation = $mode -in @('missing-location', 'missing-location-foreign') + $missingLocation = $mode -in @('missing-location', 'missing-location-short', 'missing-location-foreign') $foreign = $mode -eq 'missing-location-foreign' if ($missingLocation) { Remove-ItemProperty -LiteralPath ('HKCU:\Software\' + $RegistryKey) -Name InstallLocation } $arpKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\' + $RegistryKey if ($mode -eq 'missing-location') { $originalCommand = (Get-ItemProperty $arpKey).UninstallString $alternateCommand = $originalCommand.Replace($installPath + '\', $installPath + '\.\') + if ($alternateCommand -ceq $originalCommand -or -not $alternateCommand.Contains($installPath + '\.\')) { throw 'Equivalent-path fixture did not rewrite the uninstall command' } Set-ItemProperty $arpKey UninstallString $alternateCommand } + if ($mode -eq 'missing-location-short') { + $uninstallFile = Join-Path $installPath ('Uninstall ' + $ProductName + '.exe') + $shortFile = (New-Object -ComObject Scripting.FileSystemObject).GetFile($uninstallFile).ShortPath + if ($shortFile -ceq $uninstallFile) { throw 'Short-name fixture has no alternate name' } + Set-ItemProperty $arpKey UninstallString ('"' + $shortFile + '" /currentuser') + } $desktopLink = Join-Path ([Environment]::GetFolderPath('DesktopDirectory')) ($ProductName + '.lnk') $startLink = Join-Path ([Environment]::GetFolderPath('Programs')) ($ProductName + '.lnk') if ($missingLocation) { @@ -87,7 +94,7 @@ try { $shortcut = (New-Object -ComObject WScript.Shell).CreateShortcut($desktopLink) $shortcut.TargetPath = Join-Path $installPath ($ProductName + '.exe') $shortcut.Save() - if (-not (Test-Path -LiteralPath $desktopLink) -or (Get-ItemProperty $arpKey).UninstallString -notlike ('*' + $installPath + '*')) { throw 'Missing A uninstall fixtures' } + if (-not (Test-Path -LiteralPath $desktopLink) -or -not (Test-Path -LiteralPath $arpKey)) { throw 'Missing A uninstall fixtures' } } $integrationRoot = if ($foreign) { $externalPath } else { $installPath } $commandDirectory = Join-Path $integrationRoot 'resources\runtime\cli\bin' @@ -107,7 +114,7 @@ try { try { $key.SetValue('', '"' + (Join-Path $integrationRoot ($ProductName + '.exe')) + '" "%1"') } finally { $key.Dispose() } $launchUninstaller = $uninstaller $arguments = '_?=' + $installPath - if ($mode -in @('silent', 'missing-location', 'missing-location-foreign', 'unowned', 'owned-retained', 'home-inside', 'registration-error', 'main-locked', 'auxiliary-locked', 'unsafe-root')) { $arguments = '/S ' + $arguments } + if ($mode -in @('silent', 'missing-location', 'missing-location-short', 'missing-location-foreign', 'unowned', 'owned-retained', 'home-inside', 'registration-error', 'main-locked', 'auxiliary-locked', 'unsafe-root')) { $arguments = '/S ' + $arguments } # electron-builder's installUtil.nsh runs an older uninstaller with exactly these flags when replacing it. if ($mode -eq 'upgrade') { Set-ItemProperty -LiteralPath ('HKCU:\Software\' + $RegistryKey) -Name InstallLocation -Value ($installPath + '\')