UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines 1.61 kB
import{n as e}from"./rolldown-runtime-DkW27tQK.js";function t(e){return e===`granted`||e===`denied`||e===`notDetermined`}function n(e){if(typeof e!=`object`||!e||!(`permission`in e)||!t(e.permission))return null;if(!(`test`in e))return{permission:e.permission,test:null};let n=e.test;return n===null?{permission:e.permission,test:null}:typeof n!=`object`||!n||!(`state`in n)?null:n.state===`pending`||n.state===`sent`?{permission:e.permission,test:{state:n.state}}:n.state===`error`&&`message`in n&&typeof n.message==`string`?{permission:e.permission,test:{state:`error`,message:n.message}}:null}function r(){if(typeof window>`u`)return;let e=window.webkit?.messageHandlers?.openclawNotifications;return e?.postMessage.bind(e)}function i(){let e=r();if(!e)return null;let t=n(window.__OPENCLAW_NATIVE_NOTIFICATIONS__)??{permission:`unknown`,test:null},i=new Set,o=e=>{t=e;for(let e of i)e(t)},s=e=>{let t=n(e.detail);t&&o(t)},c=()=>e({type:`status`});return window.addEventListener(a,s),window.addEventListener(`focus`,c),c(),{get snapshot(){return t},subscribe(e){return i.add(e),()=>i.delete(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(a,s),window.removeEventListener(`focus`,c),i.clear()}}}var a;function o(){return(o=e((()=>{a=`openclaw:native-notifications-status`})))()}o();export{i as createNativeNotificationsCapability}; //# sourceMappingURL=native-notifications-D_lyz80n.js.map