mirror of
https://github.com/haexhub/haex-hub.git
synced 2025-12-17 06:30:50 +01:00
Add web.openAsync method to open URLs in browser
- Add extension_web_open Tauri command - Validate URL format and allow only http/https - Use tauri-plugin-opener to open URL in default browser - Add handleWebOpenAsync handler in frontend
This commit is contained in:
@ -33,6 +33,43 @@ pub struct WebFetchResponse {
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn extension_web_open(
|
||||
url: String,
|
||||
public_key: String,
|
||||
name: String,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<(), ExtensionError> {
|
||||
// Get extension to validate it exists
|
||||
let _extension = state
|
||||
.extension_manager
|
||||
.get_extension_by_public_key_and_name(&public_key, &name)?
|
||||
.ok_or_else(|| ExtensionError::NotFound {
|
||||
public_key: public_key.clone(),
|
||||
name: name.clone(),
|
||||
})?;
|
||||
|
||||
// Validate URL format
|
||||
let parsed_url = url::Url::parse(&url).map_err(|e| ExtensionError::WebError {
|
||||
reason: format!("Invalid URL: {}", e),
|
||||
})?;
|
||||
|
||||
// Only allow http and https URLs
|
||||
let scheme = parsed_url.scheme();
|
||||
if scheme != "http" && scheme != "https" {
|
||||
return Err(ExtensionError::WebError {
|
||||
reason: format!("Unsupported URL scheme: {}. Only http and https are allowed.", scheme),
|
||||
});
|
||||
}
|
||||
|
||||
// Open URL in default browser using tauri-plugin-opener
|
||||
tauri_plugin_opener::open_url(&url, None::<&str>).map_err(|e| ExtensionError::WebError {
|
||||
reason: format!("Failed to open URL in browser: {}", e),
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn extension_web_fetch(
|
||||
url: String,
|
||||
|
||||
@ -79,6 +79,7 @@ pub fn run() {
|
||||
extension::database::extension_sql_execute,
|
||||
extension::database::extension_sql_select,
|
||||
extension::web::extension_web_fetch,
|
||||
extension::web::extension_web_open,
|
||||
extension::get_all_dev_extensions,
|
||||
extension::get_all_extensions,
|
||||
extension::get_extension_info,
|
||||
|
||||
Reference in New Issue
Block a user