|
28 | 28 | With -Uninstall, deletes the install directory including the test key. |
29 | 29 | The next install then generates a new key, and therefore a new ID. |
30 | 30 |
|
31 | | -.PARAMETER ForceReinstall |
32 | | - Deletes the copy Edge already installed so that the policy installs the |
33 | | - current build from scratch on the next start. The extension ID is unchanged. |
34 | | - Edge's own update check is slow and throttled, so this is the reliable way |
35 | | - to pick up a rebuild. |
| 31 | +.PARAMETER RestartEdge |
| 32 | + Stops every Edge process and starts it again once everything is registered, |
| 33 | + so that Edge picks up the registrations without closing it by hand. Only the |
| 34 | + processes are touched, nothing in the profile. Unsaved work in the browser |
| 35 | + is lost. |
36 | 36 |
|
37 | | - Edge is terminated first, because it would otherwise rewrite the files being |
38 | | - removed. Any unsaved work in the browser is lost. |
| 37 | + Note that restarting does not by itself pull in a rebuilt extension: Edge |
| 38 | + keeps the copy it installed until its own update check runs. |
39 | 39 |
|
40 | 40 | .PARAMETER InstallRoot |
41 | 41 | Where the packed crx, the manifests, the test config and the test key are |
|
56 | 56 | param( |
57 | 57 | [switch]$Uninstall, |
58 | 58 | [switch]$Purge, |
59 | | - [switch]$ForceReinstall, |
| 59 | + [switch]$RestartEdge, |
60 | 60 | [string]$InstallRoot |
61 | 61 | ) |
62 | 62 |
|
@@ -202,56 +202,30 @@ function Invoke-EdgePack([string]$Directory, [string]$KeyPath) { |
202 | 202 | return $produced |
203 | 203 | } |
204 | 204 |
|
205 | | -function Stop-Edge { |
| 205 | +# Only the processes are touched; nothing in the profile is modified. |
| 206 | +function Restart-Edge { |
206 | 207 | $processes = Get-Process -Name 'msedge' -ErrorAction SilentlyContinue |
207 | | - if (-not $processes) { |
208 | | - Write-Host ' Edge is not running' |
209 | | - return |
210 | | - } |
211 | | - if (-not $PSCmdlet.ShouldProcess('msedge', "Stop $($processes.Count) process(es)")) { |
212 | | - return |
213 | | - } |
214 | | - |
215 | | - Write-Host " stopping $($processes.Count) Edge process(es)" |
216 | | - $processes | Stop-Process -Force -ErrorAction SilentlyContinue -WhatIf:$false |
217 | | - |
218 | | - $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() |
219 | | - while (Get-Process -Name 'msedge' -ErrorAction SilentlyContinue) { |
220 | | - if ($stopwatch.Elapsed.TotalSeconds -gt 30) { |
221 | | - throw 'Edge is still running after 30 seconds.' |
| 208 | + if ($processes) { |
| 209 | + if ($PSCmdlet.ShouldProcess('msedge', "Stop $($processes.Count) process(es)")) { |
| 210 | + Write-Host " stopping $($processes.Count) process(es)" |
| 211 | + $processes | Stop-Process -Force -ErrorAction SilentlyContinue -WhatIf:$false |
| 212 | + |
| 213 | + $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() |
| 214 | + while (Get-Process -Name 'msedge' -ErrorAction SilentlyContinue) { |
| 215 | + if ($stopwatch.Elapsed.TotalSeconds -gt 30) { |
| 216 | + throw 'Edge is still running after 30 seconds.' |
| 217 | + } |
| 218 | + Start-Sleep -Milliseconds 250 |
| 219 | + } |
222 | 220 | } |
223 | | - Start-Sleep -Milliseconds 250 |
224 | 221 | } |
225 | | - # Give Windows a moment to release the profile files. |
226 | | - Start-Sleep -Milliseconds 500 |
227 | | -} |
228 | | - |
229 | | -# Edge only replaces a force installed extension when its own update check runs, |
230 | | -# which it delays and throttles. Dropping the installed copy makes the policy |
231 | | -# install the current crx from scratch on the next start, keeping the same ID. |
232 | | -function Remove-InstalledExtension([string]$ExtensionId) { |
233 | | - # Edge would rewrite the files being removed, so it is stopped first. |
234 | | - Stop-Edge |
235 | | - |
236 | | - $userData = Join-Path $env:LOCALAPPDATA 'Microsoft\Edge\User Data' |
237 | | - if (-not (Test-Path $userData)) { |
238 | | - Write-Warning "No Edge user data found at $userData" |
239 | | - return |
| 222 | + else { |
| 223 | + Write-Host ' Edge was not running' |
240 | 224 | } |
241 | 225 |
|
242 | | - $removed = 0 |
243 | | - Get-ChildItem $userData -Directory -ErrorAction SilentlyContinue | ForEach-Object { |
244 | | - $installed = Join-Path $_.FullName "Extensions\$ExtensionId" |
245 | | - if (Test-Path $installed) { |
246 | | - if ($PSCmdlet.ShouldProcess($installed, 'Delete the installed extension')) { |
247 | | - Remove-Item -LiteralPath $installed -Recurse -Force -WhatIf:$false |
248 | | - Write-Host " removed from profile $($_.Name)" |
249 | | - $removed++ |
250 | | - } |
251 | | - } |
252 | | - } |
253 | | - if ($removed -eq 0) { |
254 | | - Write-Host ' nothing installed yet' |
| 226 | + if ($PSCmdlet.ShouldProcess('Microsoft Edge', 'Start')) { |
| 227 | + Start-Process -FilePath (Get-EdgePath) -WhatIf:$false | Out-Null |
| 228 | + Write-Host ' started' |
255 | 229 | } |
256 | 230 | } |
257 | 231 |
|
@@ -358,8 +332,16 @@ if ($Uninstall) { |
358 | 332 | } |
359 | 333 | } |
360 | 334 |
|
361 | | - Write-Host '' |
362 | | - Write-Host 'Restart Edge for the change to take effect.' -ForegroundColor Green |
| 335 | + if ($RestartEdge) { |
| 336 | + Write-Step 'Restarting Edge' |
| 337 | + Restart-Edge |
| 338 | + Write-Host '' |
| 339 | + Write-Host 'Done.' -ForegroundColor Green |
| 340 | + } |
| 341 | + else { |
| 342 | + Write-Host '' |
| 343 | + Write-Host 'Restart Edge for the change to take effect.' -ForegroundColor Green |
| 344 | + } |
363 | 345 | return |
364 | 346 | } |
365 | 347 |
|
@@ -460,11 +442,6 @@ Write-Host " $TestConfig" |
460 | 442 |
|
461 | 443 | # --- registry --------------------------------------------------------------- |
462 | 444 |
|
463 | | -if ($ForceReinstall) { |
464 | | - Write-Step 'Stopping Edge and dropping the copy it installed' |
465 | | - Remove-InstalledExtension $extensionId |
466 | | -} |
467 | | - |
468 | 445 | Write-Step 'Registering the ExtensionInstallForcelist policy' |
469 | 446 | $entry = "$extensionId;$(ConvertTo-FileUrl $UpdateXml)" |
470 | 447 | $valueName = Get-ForcelistValueName $extensionId |
@@ -503,22 +480,26 @@ if ($PSCmdlet.ShouldProcess("$OwnKey\Configfile", "Set to $TestConfig")) { |
503 | 480 | Write-Host " $TestConfig" |
504 | 481 | } |
505 | 482 |
|
| 483 | +if ($RestartEdge) { |
| 484 | + Write-Step 'Restarting Edge' |
| 485 | + Restart-Edge |
| 486 | +} |
| 487 | + |
506 | 488 | # --- done ------------------------------------------------------------------- |
507 | 489 |
|
508 | 490 | Write-Host '' |
509 | 491 | Write-Host "Done. Packaged version $version" -ForegroundColor Green |
510 | 492 | Write-Host '' |
511 | | -if ($ForceReinstall) { |
512 | | - Write-Host 'Edge was stopped and its copy removed. Start Edge to install this build.' |
513 | | - Write-Host '' |
514 | | -} |
515 | | -else { |
516 | | - Write-Host 'Edge keeps the copy it already installed until its own update check' |
517 | | - Write-Host 'runs, which is delayed and throttled. To pick up this build reliably,' |
518 | | - Write-Host 'run (this terminates Edge):' |
519 | | - Write-Host ' .\tools\install-test-extension.ps1 -ForceReinstall' |
| 493 | +if (-not $RestartEdge) { |
| 494 | + Write-Host 'Restart Edge so it sees the registrations, or pass -RestartEdge' |
| 495 | + Write-Host 'to have this script do it.' |
520 | 496 | Write-Host '' |
521 | 497 | } |
| 498 | +Write-Host 'Restarting is not enough to pull in a rebuilt extension: Edge keeps' |
| 499 | +Write-Host 'the copy it installed until its own update check runs, which can take' |
| 500 | +Write-Host 'hours. To apply this build now, open edge://extensions, turn on' |
| 501 | +Write-Host 'Developer mode and press Update.' |
| 502 | +Write-Host '' |
522 | 503 | Write-Host 'Then confirm on edge://extensions that the version reads' |
523 | 504 | Write-Host " $version" |
524 | 505 | Write-Host 'If it still reads the old version, the running code is the old build.' |
|
0 commit comments