move host app into a other directory
This commit is contained in:
+25
-6
@@ -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]")
|
||||
|
||||
Reference in New Issue
Block a user