adding the edge and vivaldi browser for installing the extension to, generate uuids when the browser not have a alias set
This commit is contained in:
+25
-6
@@ -40,6 +40,14 @@ NATIVE_HOST_DIRS = {
|
||||
"linux": [Path.home() / ".config/BraveSoftware/Brave-Browser/NativeMessagingHosts"],
|
||||
"darwin": [Path.home() / "Library/Application Support/BraveSoftware/Brave-Browser/NativeMessagingHosts"],
|
||||
},
|
||||
"edge": {
|
||||
"linux": [Path.home() / ".config/microsoft-edge/NativeMessagingHosts"],
|
||||
"darwin": [Path.home() / "Library/Application Support/Microsoft Edge/NativeMessagingHosts"],
|
||||
},
|
||||
"vivaldi": {
|
||||
"linux": [Path.home() / ".config/vivaldi/NativeMessagingHosts"],
|
||||
"darwin": [Path.home() / "Library/Application Support/Vivaldi/NativeMessagingHosts"],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -155,11 +163,15 @@ def cmd_clients():
|
||||
|
||||
|
||||
@main.command("rename-profile")
|
||||
@click.option(
|
||||
"--browser", "target_browser", default=None, metavar="ALIAS",
|
||||
help="Browser profile alias to rename. Overrides the global --browser option for this command.",
|
||||
)
|
||||
@click.argument("alias")
|
||||
def cmd_rename_profile(alias):
|
||||
def cmd_rename_profile(target_browser, alias):
|
||||
"""Set the profile alias used to identify this browser instance."""
|
||||
try:
|
||||
send_command("clients.rename_profile", {"alias": alias})
|
||||
send_command("clients.rename_profile", {"alias": alias}, profile=target_browser)
|
||||
except BrowserNotConnected as e:
|
||||
console.print(f"[red]Error:[/red] {e}")
|
||||
sys.exit(1)
|
||||
@@ -170,7 +182,7 @@ def cmd_rename_profile(alias):
|
||||
# ── install ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@main.command("install")
|
||||
@click.argument("browser", type=click.Choice(["chrome", "chromium", "brave"]), default="chrome")
|
||||
@click.argument("browser", type=click.Choice(["chrome", "chromium", "brave", "edge", "vivaldi"]), default="chrome")
|
||||
def cmd_install(browser):
|
||||
"""Register the native messaging host and print extension load instructions."""
|
||||
|
||||
@@ -188,7 +200,14 @@ def cmd_install(browser):
|
||||
wrapper_path.chmod(wrapper_path.stat().st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
|
||||
|
||||
# Ask for extension ID
|
||||
ext_url = "brave://extensions" if browser == "brave" else "chrome://extensions"
|
||||
ext_urls = {
|
||||
"chrome": "chrome://extensions",
|
||||
"chromium": "chrome://extensions",
|
||||
"brave": "brave://extensions",
|
||||
"edge": "edge://extensions",
|
||||
"vivaldi": "vivaldi://extensions",
|
||||
}
|
||||
ext_url = ext_urls[browser]
|
||||
console.print("\n[bold]Step 1:[/bold] Load the extension in your browser")
|
||||
console.print(f" 1. Open [cyan]{ext_url}[/cyan]")
|
||||
console.print(" 2. Enable [bold]Developer mode[/bold] (top-right toggle)")
|
||||
@@ -230,9 +249,9 @@ def cmd_install(browser):
|
||||
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(f"\n[bold]Step 2:[/bold] Restart {browser.capitalize()} completely (Cmd/Ctrl+Q, then reopen)")
|
||||
console.print("\n[green bold]✓ Installation complete![/green bold]")
|
||||
console.print(" After restarting Chrome, try: [cyan]browser-cli tabs list[/cyan]")
|
||||
console.print(" After restarting the browser, try: [cyan]browser-cli tabs list[/cyan]")
|
||||
|
||||
|
||||
# ── native-host (hidden, called by Chrome via native messaging) ────────────────
|
||||
|
||||
@@ -75,6 +75,15 @@ def _socket_path_for(alias: str) -> str:
|
||||
return str(SOCKET_DIR / f"{safe}.sock")
|
||||
|
||||
|
||||
def _resolve_profile_alias(first_msg: dict | None) -> str:
|
||||
"""Return a unique alias when the extension did not provide one."""
|
||||
if first_msg and first_msg.get("type") == "hello":
|
||||
alias = first_msg.get("alias")
|
||||
if alias and alias != DEFAULT_ALIAS:
|
||||
return alias
|
||||
return str(uuid.uuid4())
|
||||
|
||||
|
||||
# --- Thread A: read messages from extension (stdin) ---
|
||||
|
||||
def stdin_reader(alias: str):
|
||||
@@ -191,10 +200,10 @@ def main():
|
||||
# Wait for the hello handshake to learn the profile alias
|
||||
first_msg = read_native_message(stdin)
|
||||
if first_msg and first_msg.get("type") == "hello":
|
||||
alias = first_msg.get("alias") or DEFAULT_ALIAS
|
||||
alias = _resolve_profile_alias(first_msg)
|
||||
else:
|
||||
# No hello — fall back to default, re-queue message if it was a command
|
||||
alias = DEFAULT_ALIAS
|
||||
# No hello — use a generated alias and re-queue the first command if needed.
|
||||
alias = str(uuid.uuid4())
|
||||
if first_msg:
|
||||
msg_id = first_msg.get("id")
|
||||
if msg_id:
|
||||
|
||||
Reference in New Issue
Block a user