The store build has its own id, so the native-messaging manifest refused it and the extension reported the app as not running. Chrome now allows the store id and the unpacked development id, in the NSIS hook and in both install scripts; --chrome-id / -ChromeId take a list. Co-Authored-By: Claude Opus 5.5 <[email protected]>
63 lines
2.9 KiB
PowerShell
63 lines
2.9 KiB
PowerShell
# Registers the Kestrove native-messaging host for the current user on Windows (HKCU, no admin).
|
|
# Linux/macOS: install.sh.
|
|
#
|
|
# powershell -ExecutionPolicy Bypass -File install.ps1 [-Nmh C:\path\kestrove-nmh.exe]
|
|
# [-ChromeId ID[,ID…]] [-FirefoxId ID] [-Browsers chrome,chromium,edge,firefox] [-Uninstall]
|
|
#
|
|
# Chrome and Brave share the Google\Chrome key. The manifests go to %LOCALAPPDATA%\Kestrove\NativeMessagingHosts.
|
|
# allowed_origins / allowed_extensions pin the host to our extension ids (docs/04 A8).
|
|
param(
|
|
[string]$Nmh = "",
|
|
# The Chrome Web Store build, then the unpacked development build.
|
|
[string[]]$ChromeId = @("pmhfoafjoogobhfadaicklhkldgnafmk", "kogapfibnnpeapfcjkkpgjddbhnjfein"),
|
|
[string]$FirefoxId = "[email protected]",
|
|
[string[]]$Browsers = @("chrome", "chromium", "edge", "firefox"),
|
|
[switch]$Uninstall
|
|
)
|
|
$ErrorActionPreference = "Stop"
|
|
$HostName = "app.kestrove.nmh"
|
|
$Here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
|
|
foreach ($id in $ChromeId) { if ($id -notmatch '^[a-p]{32}$') { throw "-ChromeId must be 32 letters a-p" } }
|
|
if ($FirefoxId -notmatch '^[A-Za-z0-9._@{}-]+$') { throw "bad -FirefoxId" }
|
|
|
|
$Keys = @{
|
|
chrome = "HKCU:\Software\Google\Chrome\NativeMessagingHosts\$HostName"
|
|
chromium = "HKCU:\Software\Chromium\NativeMessagingHosts\$HostName"
|
|
edge = "HKCU:\Software\Microsoft\Edge\NativeMessagingHosts\$HostName"
|
|
firefox = "HKCU:\Software\Mozilla\NativeMessagingHosts\$HostName"
|
|
}
|
|
$OutDir = Join-Path $env:LOCALAPPDATA "Kestrove\NativeMessagingHosts"
|
|
|
|
if ($Uninstall) {
|
|
foreach ($b in $Browsers) {
|
|
if (Test-Path $Keys[$b]) { Remove-Item $Keys[$b] -Force; Write-Host "removed $($Keys[$b])" }
|
|
}
|
|
Remove-Item (Join-Path $OutDir "$HostName.*.json") -ErrorAction SilentlyContinue
|
|
return
|
|
}
|
|
|
|
if (-not $Nmh) {
|
|
foreach ($c in @((Join-Path $Here "kestrove-nmh.exe"), (Join-Path $Here "..\src-tauri\target\release\kestrove-nmh.exe"), (Join-Path $Here "..\src-tauri\target\debug\kestrove-nmh.exe"))) {
|
|
if (Test-Path $c) { $Nmh = $c; break }
|
|
}
|
|
}
|
|
if (-not $Nmh -or -not (Test-Path $Nmh)) { throw "kestrove-nmh.exe not found; pass -Nmh" }
|
|
$Nmh = (Resolve-Path $Nmh).Path
|
|
|
|
New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
|
|
foreach ($flavor in @("chrome", "firefox")) {
|
|
$m = Get-Content -Raw (Join-Path $Here "$HostName.$flavor.json") | ConvertFrom-Json
|
|
$m.path = $Nmh
|
|
if ($flavor -eq "chrome") { $m.allowed_origins = @($ChromeId | ForEach-Object { "chrome-extension://$_/" }) } else { $m.allowed_extensions = @($FirefoxId) }
|
|
$m | ConvertTo-Json -Depth 4 | Set-Content -Encoding UTF8 (Join-Path $OutDir "$HostName.$flavor.json")
|
|
}
|
|
|
|
foreach ($b in $Browsers) {
|
|
if (-not $Keys.ContainsKey($b)) { throw "unknown browser $b" }
|
|
$flavor = if ($b -eq "firefox") { "firefox" } else { "chrome" }
|
|
New-Item -Force -Path $Keys[$b] | Out-Null
|
|
Set-Item -Path $Keys[$b] -Value (Join-Path $OutDir "$HostName.$flavor.json")
|
|
Write-Host "registered $($Keys[$b])"
|
|
}
|