feat: add Web Push API support and PWA integration (#189)
* feat: add Web Push API support and PWA integration Add web Push API with subscribe/unsubscribe and visibility endpoints Introduce usePushVisibilityBeacon and useSessionDeepLink hooks Integrate PWA with service worker, registerSW, and VAPID key persistence * feat: add heartbeat visibility beacon for web runtime Add a 10s heartbeat to ping visibility while visible Subscribe to visibilitychange, focus, blur, pageshow, and pagehide events to report state Clear heartbeat interval on unmount to avoid leaks
This commit is contained in:
committed by
GitHub
parent
06c5e821a4
commit
1f23b63c0b
@@ -255,6 +255,9 @@ async fn handle_event(
|
||||
"question.asked" => {
|
||||
handle_question_asked(app, &event.properties, notified_questions).await;
|
||||
}
|
||||
"permission.asked" => {
|
||||
handle_permission_asked(app, &event.properties, notified_questions).await;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -264,6 +267,7 @@ async fn handle_question_asked(
|
||||
properties: &Value,
|
||||
notified_questions: &Mutex<HashSet<String>>,
|
||||
) {
|
||||
|
||||
let session_id = properties.get("sessionID").and_then(Value::as_str);
|
||||
let question_id = properties.get("id").and_then(Value::as_str);
|
||||
|
||||
@@ -301,6 +305,54 @@ async fn handle_question_asked(
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_permission_asked(
|
||||
app: &AppHandle,
|
||||
properties: &Value,
|
||||
notified_requests: &Mutex<HashSet<String>>,
|
||||
) {
|
||||
let session_id = properties.get("sessionID").and_then(Value::as_str);
|
||||
let request_id = properties.get("id").and_then(Value::as_str);
|
||||
|
||||
let (session_id, request_id) = match (session_id, request_id) {
|
||||
(Some(s), Some(r)) => (s, r),
|
||||
_ => return,
|
||||
};
|
||||
|
||||
let key = format!("{}:{}", session_id, request_id);
|
||||
{
|
||||
let mut notified = notified_requests.lock().await;
|
||||
if notified.contains(&key) {
|
||||
return;
|
||||
}
|
||||
notified.insert(key);
|
||||
}
|
||||
|
||||
let permission = properties
|
||||
.get("permission")
|
||||
.and_then(Value::as_str)
|
||||
.filter(|s| !s.is_empty())
|
||||
.unwrap_or("Agent requested permission");
|
||||
|
||||
let should_notify = app
|
||||
.get_webview_window("main")
|
||||
.map(|window| {
|
||||
let focused = window.is_focused().unwrap_or(false);
|
||||
let minimized = window.is_minimized().unwrap_or(false);
|
||||
!focused || minimized
|
||||
})
|
||||
.unwrap_or(true);
|
||||
|
||||
if should_notify {
|
||||
let _ = app
|
||||
.notification()
|
||||
.builder()
|
||||
.title("Permission required")
|
||||
.body(permission)
|
||||
.sound("Glass")
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_message_updated(
|
||||
app: &AppHandle,
|
||||
properties: &Value,
|
||||
|
||||
Reference in New Issue
Block a user