From e7abcbb976f996d0f9a9e81e7a702d6c76e3e1ea Mon Sep 17 00:00:00 2001 From: Daniel Dolezal Date: Fri, 10 Apr 2026 00:23:21 +0200 Subject: [PATCH] move host app into a other directory --- browser_cli/cli.py | 31 +++++++++++++++++++++++++------ com.browsercli.host.json | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/browser_cli/cli.py b/browser_cli/cli.py index d8249b9..3291e9b 100755 --- a/browser_cli/cli.py +++ b/browser_cli/cli.py @@ -7,6 +7,7 @@ import sys import os import json import stat +import shutil from pathlib import Path from rich.console import Console @@ -40,6 +41,18 @@ NATIVE_HOST_DIRS = { } +def _native_host_wrapper_path() -> Path: + if sys.platform == "darwin": + base_dir = Path.home() / "Library" / "Application Support" / "browser-cli" + else: + base_dir = Path(os.environ.get("XDG_DATA_HOME", Path.home() / ".local" / "share")) / "browser-cli" + return base_dir / "libexec" / "native-host" + + +def _native_host_script_path() -> Path: + return _native_host_wrapper_path().with_name("native_host.py") + + @click.group() @click.option( "--browser", default=None, metavar="ALIAS", @@ -128,12 +141,16 @@ def cmd_rename_profile(alias): def cmd_install(browser): """Register the native messaging host and print extension load instructions.""" - # Install wrapper outside PATH — Chrome uses the absolute path from the manifest, - # so it doesn't need to be a shell command. - share_dir = Path.home() / ".local" / "share" / "browser-cli" - share_dir.mkdir(parents=True, exist_ok=True) - wrapper_path = share_dir / "native-host" - wrapper_content = f'#!/bin/sh\nexec "{sys.executable}" -m browser_cli.native_host "$@"\n' + # Install wrapper outside PATH — the browser uses the absolute path from the + # native messaging manifest, so only `browser-cli` needs to be on PATH. + wrapper_path = _native_host_wrapper_path() + native_host_script_path = _native_host_script_path() + wrapper_path.parent.mkdir(parents=True, exist_ok=True) + shutil.copy2(Path(__file__).with_name("native_host.py"), native_host_script_path) + native_host_script_path.chmod( + native_host_script_path.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH + ) + wrapper_content = f'#!/bin/sh\nexec "{sys.executable}" "{native_host_script_path}" "$@"\n' wrapper_path.write_text(wrapper_content) wrapper_path.chmod(wrapper_path.stat().st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH) @@ -177,6 +194,8 @@ def cmd_install(browser): for p in installed: console.print(f"[green]✓[/green] Wrote native host manifest: {p}") + console.print(f"[green]✓[/green] Installed native host script: {native_host_script_path}") + console.print(f"[green]✓[/green] Installed native host wrapper: {wrapper_path}") console.print("\n[bold]Step 2:[/bold] Restart Chrome completely (Cmd/Ctrl+Q, then reopen)") console.print("\n[green bold]✓ Installation complete![/green bold]") diff --git a/com.browsercli.host.json b/com.browsercli.host.json index 598b7c4..ed5ac9d 100644 --- a/com.browsercli.host.json +++ b/com.browsercli.host.json @@ -1,7 +1,7 @@ { "name": "com.browsercli.host", "description": "browser-cli native messaging host", - "path": "/REPLACE_WITH_ABSOLUTE_PATH/browser-cli-native-host", + "path": "/REPLACE_WITH_ABSOLUTE_PATH/browser-cli/libexec/native-host", "type": "stdio", "allowed_origins": [ "chrome-extension://REPLACE_WITH_EXTENSION_ID/"