UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.68 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{lo as t}from"./control-ui-connection-Bfj9beF_.js";import{sM as n}from"./control-ui-boot-shared-DFTSUQQ0.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=n()?.webkit?.messageHandlers?.openclawNotifications,r=e?.postMessage.bind(e);if(!r)return null;let a=i(window.__OPENCLAW_NATIVE_NOTIFICATIONS__)??{permission:`unknown`,test:null},s,c,l=!1,u=e=>{a=e,s?.(a)},d=e=>{let t=i(e.detail);if(t){if(u(t),t.test?.state===`pending`)l=!0;else if(t.test&&l){let e=c;c=void 0,l=!1,e?.resolve(t.test)}}},f=()=>r({type:`status`}),p=[t(window,o,d),t(window,`focus`,f)];return f(),{get snapshot(){return a},subscribe(e){return s=e,()=>{s=void 0}},requestPermission(){r({type:`request-permission`})},sendTest(){if(c)return c.promise;if(a.test?.state!==`pending`)return c=Promise.withResolvers(),l=!1,u({...a,test:{state:`pending`}}),r({type:`send-test`}),c.promise},backgroundSessionCompleted(e){r({type:`background-session-completed`,...e})},dispose(){p.forEach(e=>e()),s=void 0,c?.resolve(void 0),c=void 0}}}var o;function s(){return(s=e((()=>{o=`openclaw:native-notifications-status`})))()}s();export{a as createNativeNotificationsCapability};