Auto-install protocol handler when exe run without args

This commit is contained in:
2025-12-30 06:06:51 -07:00
parent 1b810a5f0a
commit 9f36686ea1
2 changed files with 54 additions and 3 deletions

View File

@@ -301,6 +301,51 @@ pub fn install(force_user_install: bool) -> Result<()> {
Ok(()) 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 /// Parse a guruconnect:// URL and extract session parameters
pub fn parse_protocol_url(url: &str) -> Result<(String, String, Option<String>)> { pub fn parse_protocol_url(url: &str) -> Result<(String, String, Option<String>)> {
// Expected formats: // Expected formats:

View File

@@ -138,13 +138,19 @@ fn main() -> Result<()> {
if let Some(code) = cli.support_code { if let Some(code) = cli.support_code {
run_agent_mode(Some(code)) run_agent_mode(Some(code))
} else { } else {
// No args: check if we should auto-detect mode // No args: check if protocol handler is installed
// For now, default to agent mode // 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) run_agent_mode(None)
} }
} }
} }
} }
}
/// Run in agent mode (receive remote connections) /// Run in agent mode (receive remote connections)
fn run_agent_mode(support_code: Option<String>) -> Result<()> { fn run_agent_mode(support_code: Option<String>) -> Result<()> {