@@ -50,6 +50,38 @@ $ErrorActionPreference = 'Stop'
5050function Say ($m ) { Write-Host " $m " }
5151function Head ($m ) { Write-Host " `n $m " - ForegroundColor Cyan }
5252
53+ # How to start Claude Desktop again, from the path of its running process; $null when it cannot be worked out.
54+ function Get-ClaudeStart ([string ]$appPath ) {
55+ if ($appPath -match ' \\WindowsApps\\(?<folder>[^\\]+)\\' ) {
56+ # Store / MSIX app, started through its application id. The folder ("Claude_2.1.0.0_x64__pzs8sxrjxfjjc") gives
57+ # the package family ("Claude_pzs8sxrjxfjjc"); after Claude updated itself the running folder is an older
58+ # version than the installed package, so the family is matched, never the path.
59+ $folder = $Matches [' folder' ]
60+ if ($folder -notmatch ' ^(?<name>[^_]+)_.*__(?<publisher>[^_]+)$' ) { return $null }
61+ $family = " $ ( $Matches [' name' ]) _$ ( $Matches [' publisher' ]) "
62+ $aumid = $null
63+ try {
64+ $aumid = (Get-StartApps - ErrorAction Stop | Where-Object { $_.AppID -like " $family !*" } | Select-Object - First 1 ).AppID
65+ }
66+ catch { }
67+ if (-not $aumid ) {
68+ try {
69+ $pkg = Get-AppxPackage - ErrorAction Stop | Where-Object { $_.PackageFamilyName -eq $family } | Select-Object - First 1
70+ if ($pkg ) { $aumid = " $family !" + @ ((Get-AppxPackageManifest $pkg ).Package.Applications.Application)[0 ].Id }
71+ }
72+ catch { }
73+ }
74+ if ($aumid ) { return " shell:AppsFolder\$aumid " }
75+ return $null
76+ }
77+ # Per-user install: the launcher above the versioned "app-x.y.z" folders starts the current version.
78+ if ($appPath -match ' ^(?<root>.+)\\app-[^\\]+\\[^\\]+$' -and (Test-Path (Join-Path $Matches [' root' ] ' claude.exe' ))) {
79+ return (Join-Path $Matches [' root' ] ' claude.exe' )
80+ }
81+ if ($appPath -and (Test-Path $appPath )) { return $appPath }
82+ return $null
83+ }
84+
5385$src = $PSScriptRoot
5486if (-not (Test-Path (Join-Path $src ' bin\xpplens.exe' ))) {
5587 throw " $src \bin\xpplens.exe not found - run install.ps1 from an unpacked xpp-lens package."
@@ -197,23 +229,26 @@ if ($desktop.Count -gt 0) {
197229 -not ([Environment ]::GetCommandLineArgs() | Where-Object { $_ -like ' -NonI*' })
198230 if (-not $restart -and $canAsk ) {
199231 Write-Host " "
200- $answer = Read-Host " Claude Desktop is running. Restart it now so all its sessions use $version ? Work in progress there is interrupted. [y/N]"
232+ $answer = Read-Host " Claude Desktop is running. Restart it now so all its sessions use ${ version} ? Work in progress there is interrupted. [y/N]"
201233 $restart = $answer -match ' ^\s*(y|yes|t|tak)\s*$'
202234 }
203235 if ($restart ) {
204- $appPath = $desktop [0 ].Path
205- $desktop | Stop-Process - Force - ErrorAction SilentlyContinue
206- Start-Sleep - Seconds 2
207- if ($appPath -match ' \\WindowsApps\\' ) {
208- # Store / MSIX app: started through its application id, not the exe path.
209- $pkg = Get-AppxPackage | Where-Object { $_.InstallLocation -and $appPath.StartsWith ($_.InstallLocation , [StringComparison ]::OrdinalIgnoreCase) } | Select-Object - First 1
210- $appId = @ ((Get-AppxPackageManifest $pkg ).Package.Applications.Application)[0 ].Id
211- Start-Process " shell:AppsFolder\$ ( $pkg.PackageFamilyName ) !$appId "
236+ # Worked out before Claude is stopped: when it cannot be started again, it is not stopped either.
237+ $start = Get-ClaudeStart $desktop [0 ].Path
238+ if (-not $start ) {
239+ Say " Claude Desktop could not be located for a restart - it was left running; restart it yourself to use $version ."
212240 }
213241 else {
214- Start-Process $appPath
242+ $desktop | Stop-Process - Force - ErrorAction SilentlyContinue
243+ Start-Sleep - Seconds 2
244+ try {
245+ Start-Process $start - ErrorAction Stop
246+ Say " Claude Desktop restarted."
247+ }
248+ catch {
249+ Say " Claude Desktop was closed but did not start again ($ ( $_.Exception.Message ) ) - start it from the Start menu."
250+ }
215251 }
216- Say " Claude Desktop restarted."
217252 }
218253 else {
219254 Say " Claude Desktop: open sessions keep the old version until it is restarted; new sessions use $version ."
0 commit comments