Skip to content

Commit d3ca547

Browse files
committed
install-test-extension: remove force install option
1 parent 769ab43 commit d3ca547

2 files changed

Lines changed: 57 additions & 69 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,17 @@ Edge は起動直後ではなく数分後にチェックし、以降は数時間
147147
| コマンド | 内容 |
148148
| --- | --- |
149149
| `install-test-extension.ps1` | ビルドと登録 |
150+
| `install-test-extension.ps1 -RestartEdge` | 登録後に Edge を再起動する |
150151
| `install-test-extension.ps1 -WhatIf` | レジストリを変更せずに内容を確認 |
151152
| `install-test-extension.ps1 -Uninstall` | 登録を解除し、元のレジストリ値に戻す |
152153
| `install-test-extension.ps1 -Uninstall -Purge` | 生成物とテスト鍵も削除 (次回は別の ID になります) |
153154

155+
`-RestartEdge` は Edge のプロセスを終了して起動し直すだけで、プロファイルには触れません。
156+
未保存の作業は失われます。`-Uninstall` と組み合わせることもできます。
157+
158+
`-Purge` を使うと拡張機能 ID が変わります。`edge://extensions``edge://policy`
159+
確認する際は、スクリプトが出力した ID と一致しているか注意してください。
160+
154161
生成物は `.testinstall\` に置かれます (git 管理外)。
155162
`-WhatIf` はレジストリ変更のみを抑止し、crx などの生成は実際に行います。
156163

tools/install-test-extension.ps1

Lines changed: 50 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
With -Uninstall, deletes the install directory including the test key.
2929
The next install then generates a new key, and therefore a new ID.
3030
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.
3636
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.
3939
4040
.PARAMETER InstallRoot
4141
Where the packed crx, the manifests, the test config and the test key are
@@ -56,7 +56,7 @@
5656
param(
5757
[switch]$Uninstall,
5858
[switch]$Purge,
59-
[switch]$ForceReinstall,
59+
[switch]$RestartEdge,
6060
[string]$InstallRoot
6161
)
6262

@@ -202,56 +202,30 @@ function Invoke-EdgePack([string]$Directory, [string]$KeyPath) {
202202
return $produced
203203
}
204204

205-
function Stop-Edge {
205+
# Only the processes are touched; nothing in the profile is modified.
206+
function Restart-Edge {
206207
$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+
}
222220
}
223-
Start-Sleep -Milliseconds 250
224221
}
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'
240224
}
241225

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'
255229
}
256230
}
257231

@@ -358,8 +332,16 @@ if ($Uninstall) {
358332
}
359333
}
360334

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+
}
363345
return
364346
}
365347

@@ -460,11 +442,6 @@ Write-Host " $TestConfig"
460442

461443
# --- registry ---------------------------------------------------------------
462444

463-
if ($ForceReinstall) {
464-
Write-Step 'Stopping Edge and dropping the copy it installed'
465-
Remove-InstalledExtension $extensionId
466-
}
467-
468445
Write-Step 'Registering the ExtensionInstallForcelist policy'
469446
$entry = "$extensionId;$(ConvertTo-FileUrl $UpdateXml)"
470447
$valueName = Get-ForcelistValueName $extensionId
@@ -503,22 +480,26 @@ if ($PSCmdlet.ShouldProcess("$OwnKey\Configfile", "Set to $TestConfig")) {
503480
Write-Host " $TestConfig"
504481
}
505482

483+
if ($RestartEdge) {
484+
Write-Step 'Restarting Edge'
485+
Restart-Edge
486+
}
487+
506488
# --- done -------------------------------------------------------------------
507489

508490
Write-Host ''
509491
Write-Host "Done. Packaged version $version" -ForegroundColor Green
510492
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.'
520496
Write-Host ''
521497
}
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 ''
522503
Write-Host 'Then confirm on edge://extensions that the version reads'
523504
Write-Host " $version"
524505
Write-Host 'If it still reads the old version, the running code is the old build.'

0 commit comments

Comments
 (0)