Auto-install protocol handler when exe run without args
This commit is contained in:
@@ -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<String>)> {
|
||||
// Expected formats:
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user