From 9f36686ea1477dfa21f8e1b3a0e287c9e830cb05 Mon Sep 17 00:00:00 2001 From: Mike Swanson Date: Tue, 30 Dec 2025 06:06:51 -0700 Subject: [PATCH] Auto-install protocol handler when exe run without args --- agent/src/install.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++ agent/src/main.rs | 12 +++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/agent/src/install.rs b/agent/src/install.rs index daf1a91..675aa4d 100644 --- a/agent/src/install.rs +++ b/agent/src/install.rs @@ -301,6 +301,51 @@ pub fn install(force_user_install: bool) -> Result<()> { Ok(()) } +/// Check if the guruconnect:// protocol handler is registered +#[cfg(windows)] +pub fn is_protocol_handler_registered() -> bool { + use windows::Win32::System::Registry::{ + RegOpenKeyExW, RegCloseKey, HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, KEY_READ, + }; + + unsafe { + // Check system-wide registration (HKCR\guruconnect) + let mut key = HKEY::default(); + let key_path = to_wide("guruconnect"); + if RegOpenKeyExW( + HKEY_CLASSES_ROOT, + PCWSTR(key_path.as_ptr()), + 0, + KEY_READ, + &mut key, + ).is_ok() { + let _ = RegCloseKey(key); + return true; + } + + // Check user-level registration (HKCU\Software\Classes\guruconnect) + let key_path = to_wide(r"Software\Classes\guruconnect"); + if RegOpenKeyExW( + HKEY_CURRENT_USER, + PCWSTR(key_path.as_ptr()), + 0, + KEY_READ, + &mut key, + ).is_ok() { + let _ = RegCloseKey(key); + return true; + } + } + + false +} + +#[cfg(not(windows))] +pub fn is_protocol_handler_registered() -> bool { + // On non-Windows, assume not registered (or check ~/.local/share/applications) + false +} + /// Parse a guruconnect:// URL and extract session parameters pub fn parse_protocol_url(url: &str) -> Result<(String, String, Option)> { // Expected formats: diff --git a/agent/src/main.rs b/agent/src/main.rs index 2f2f614..d3e8110 100644 --- a/agent/src/main.rs +++ b/agent/src/main.rs @@ -138,9 +138,15 @@ fn main() -> Result<()> { if let Some(code) = cli.support_code { run_agent_mode(Some(code)) } else { - // No args: check if we should auto-detect mode - // For now, default to agent mode - run_agent_mode(None) + // No args: check if protocol handler is installed + // If not, run install mode (user likely downloaded from web) + if !install::is_protocol_handler_registered() { + info!("Protocol handler not registered, running installer"); + run_install(false) + } else { + // Protocol handler exists, run as agent + run_agent_mode(None) + } } } }