Sync working tree before initial Gitea push
- File reorg: popup/options/bulk-check moved to src/ subdirs - Shared modules: src/shared/id-extract.js, src/options/options-shared.js - Host updates: rcjav-host.py + register/install scripts - .gitignore expanded
This commit is contained in:
+54
-22
@@ -1,15 +1,15 @@
|
||||
# install-host.ps1
|
||||
# Registers rclonex native-messaging host so Brave can launch it.
|
||||
#
|
||||
# Usage: .\install-host.ps1 -ExtensionId <id-from-brave://extensions>
|
||||
# Usage: .\install-host.ps1
|
||||
# Optional: .\install-host.ps1 -ExtensionId <id-from-brave://extensions>
|
||||
#
|
||||
# Writes manifest to host\com.rcjav.host.json with the correct path + extension ID baked in,
|
||||
# Writes manifest to host\com.rcjav.host.json with the correct path + extension ID allowed,
|
||||
# then registers it in HKLM (requires admin - script self-elevates if needed) AND HKCU.
|
||||
# HKLM is required on some Brave installs; HKCU alone is not always honored.
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ExtensionId
|
||||
[string]$ExtensionId = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -19,30 +19,62 @@ $batPath = Join-Path $hostDir "rcjav-host.bat"
|
||||
if (-not (Test-Path $batPath)) { throw "Host bat not found: $batPath" }
|
||||
|
||||
$manifestPath = Join-Path $hostDir "com.rcjav.host.json"
|
||||
$template = Join-Path $hostDir "com.rcjav.host.json.template"
|
||||
if (-not (Test-Path $template)) { throw "Template not found: $template" }
|
||||
$allowlistPath = Join-Path $hostDir "allowed-extension-ids.json"
|
||||
|
||||
$content = Get-Content $template -Raw
|
||||
$content = $content.Replace("__HOST_BAT__", ($batPath -replace "\\", "\\"))
|
||||
$content = $content.Replace("__EXTENSION_ID__", $ExtensionId)
|
||||
# Self-elevate before writing the manifest or HKLM registry entries. Some
|
||||
# installs keep the host folder under admin-owned permissions.
|
||||
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
||||
[Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
if (-not $isAdmin) {
|
||||
Write-Host "Not running as admin - relaunching elevated..."
|
||||
$args = @(
|
||||
"-NoProfile", "-ExecutionPolicy", "Bypass",
|
||||
"-File", $PSCommandPath
|
||||
)
|
||||
if ($ExtensionId) { $args += @("-ExtensionId", $ExtensionId) }
|
||||
Start-Process pwsh -Verb RunAs -ArgumentList $args
|
||||
exit
|
||||
}
|
||||
|
||||
$extensionIds = @()
|
||||
if (Test-Path $allowlistPath) {
|
||||
try {
|
||||
$allowlist = Get-Content $allowlistPath -Raw | ConvertFrom-Json
|
||||
if ($allowlist.allowed_extension_ids) {
|
||||
$props = $allowlist.allowed_extension_ids.PSObject.Properties
|
||||
foreach ($prop in $props) {
|
||||
$id = [string]$prop.Value
|
||||
if ($id -match '^[a-p]{32}$' -and $extensionIds -notcontains $id) {
|
||||
$extensionIds += $id
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
throw "Failed to read $allowlistPath`: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
if ($ExtensionId) {
|
||||
if ($ExtensionId -notmatch '^[a-p]{32}$') { throw "Invalid extension ID: $ExtensionId" }
|
||||
if ($extensionIds -notcontains $ExtensionId) { $extensionIds += $ExtensionId }
|
||||
}
|
||||
if ($extensionIds.Count -eq 0) {
|
||||
throw "No extension IDs configured. Add IDs to $allowlistPath or pass -ExtensionId."
|
||||
}
|
||||
$allowedOrigins = @($extensionIds | ForEach-Object { "chrome-extension://$_/" })
|
||||
|
||||
$manifest = [ordered]@{
|
||||
name = "com.rcjav.host"
|
||||
description = "rclonex native messaging host (rc-jav bridge)"
|
||||
path = $batPath
|
||||
type = "stdio"
|
||||
allowed_origins = @($allowedOrigins)
|
||||
}
|
||||
$content = $manifest | ConvertTo-Json -Depth 4
|
||||
|
||||
# UTF-8 WITHOUT BOM - Chrome/Brave rejects manifests with a BOM.
|
||||
[System.IO.File]::WriteAllText($manifestPath, $content, [System.Text.UTF8Encoding]::new($false))
|
||||
Write-Host "Manifest written: $manifestPath"
|
||||
|
||||
# Self-elevate for HKLM if not already admin.
|
||||
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
||||
[Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
if (-not $isAdmin) {
|
||||
Write-Host "Not running as admin - relaunching elevated to write HKLM..."
|
||||
Start-Process pwsh -Verb RunAs -ArgumentList @(
|
||||
"-NoProfile", "-ExecutionPolicy", "Bypass",
|
||||
"-File", $PSCommandPath,
|
||||
"-ExtensionId", $ExtensionId
|
||||
)
|
||||
exit
|
||||
}
|
||||
|
||||
# Register in HKLM - required on some Brave installs.
|
||||
$keys = @(
|
||||
'HKLM:\Software\BraveSoftware\Brave-Browser\NativeMessagingHosts\com.rcjav.host',
|
||||
|
||||
Reference in New Issue
Block a user