UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.55 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{va as t}from"./control-ui-core-9qYjK5B2.js";import{Yr as n}from"./ui-DuRgK6kL.js";function r(e){return e===`granted`||e===`denied`||e===`notDetermined`}function i(e){if(typeof e!=`object`||!e||!(`permission`in e)||!r(e.permission))return null;if(!(`test`in e)||e.test===null)return{permission:e.permission,test:null};let t=e.test;return typeof t!=`object`||!t||!(`state`in t)?null:t.state===`pending`||t.state===`sent`?{permission:e.permission,test:{state:t.state}}:t.state===`error`&&`message`in t&&typeof t.message==`string`?{permission:e.permission,test:{state:`error`,message:t.message}}:null}function a(){let e=t()?.webkit?.messageHandlers?.openclawNotifications;return e?.postMessage.bind(e)}function o(){let e=a();if(!e)return null;let t=i(window.__OPENCLAW_NATIVE_NOTIFICATIONS__)??{permission:`unknown`,test:null},r=new Set,o=e=>{t=e;for(let e of r)e(t)},c=e=>{let t=i(e.detail);t&&o(t)},l=()=>e({type:`status`});return window.addEventListener(s,c),window.addEventListener(`focus`,l),l(),{get snapshot(){return t},subscribe:e=>n(r,e),requestPermission(){e({type:`request-permission`})},sendTest(){t.test?.state!==`pending`&&(o({...t,test:{state:`pending`}}),e({type:`send-test`}))},backgroundSessionCompleted(t){e({type:`background-session-completed`,...t})},dispose(){window.removeEventListener(s,c),window.removeEventListener(`focus`,l),r.clear()}}}var s;function c(){return(c=e((()=>{s=`openclaw:native-notifications-status`})))()}c();export{o as createNativeNotificationsCapability};