@@ -26,6 +26,13 @@ for arg in "$@"; do
2626 *) echo "unknown option: $arg" >&2; exit 2 ;;
2727 esac
2828done
29+# Also register with every other Brave channel that has been run on this Mac (Beta, Nightly),
30+# since each one reads host manifests from its own folder.
31+for ch in Brave-Browser-Beta Brave-Browser-Nightly; do
32+ if [[ -d "$HOME/Library/Application Support/BraveSoftware/$ch" && " ${CHANNELS[*]} " != *" $ch "* ]]; then
33+ CHANNELS+=("$ch")
34+ fi
35+done
2936
3037ID=$(tr -d '[:space:]' < extension-id 2>/dev/null || true)
3138if [[ -z "$ID" ]]; then
@@ -73,6 +80,27 @@ for ch in "${CHANNELS[@]}"; do
7380 echo "manifest: $DIR/io.diagonal.host.json"
7481done
7582
83+# Check what Brave will check, so a problem is named here instead of as "host not found" later.
84+for ch in "${CHANNELS[@]}"; do
85+ "$PYTHON" - "$HOME/Library/Application Support/BraveSoftware/$ch/NativeMessagingHosts/io.diagonal.host.json" "$ID" <<'PY'
86+import json, os, sys
87+path, ext_id = sys.argv[1], sys.argv[2]
88+m = json.load(open(path))
89+problems = []
90+if m.get("name") != "io.diagonal.host":
91+ problems.append(f"name is {m.get('name')!r}")
92+host = m.get("path", "")
93+if not os.path.isabs(host):
94+ problems.append(f"path {host!r} is not absolute")
95+elif not os.access(host, os.X_OK):
96+ problems.append(f"host {host} is missing or not executable")
97+if m.get("allowed_origins") != [f"chrome-extension://{ext_id}/"]:
98+ problems.append(f"allowed_origins is {m.get('allowed_origins')}")
99+if problems:
100+ sys.exit("manifest check failed for " + path + ": " + "; ".join(problems))
101+PY
102+done
103+
76104FM="${DIAGONAL_FM:-/usr/bin/fm}"
77105
78106# fm refuses to run (exit 69) until someone accepts Apple's terms for it, once per Mac.