# 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] [-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 = "", [string]$ChromeId = "kogapfibnnpeapfcjkkpgjddbhnjfein", [string]$FirefoxId = "browser@kestrove.app", [string[]]$Browsers = @("chrome", "chromium", "edge", "firefox"), [switch]$Uninstall ) $ErrorActionPreference = "Stop" $HostName = "app.kestrove.nmh" $Here = Split-Path -Parent $MyInvocation.MyCommand.Path if ($ChromeId -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 = @("chrome-extension://$ChromeId/") } 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])" }