You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
11 KiB
2 lines
11 KiB
4 weeks ago
|
var P=Object.defineProperty;var E=(i,e,t)=>e in i?P(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var p=(i,e,t)=>E(i,typeof e!="symbol"?e+"":e,t);import{C,V as x,f as A,D as O,y as u,a4 as N,a5 as W,_ as D,g as M,x as c,p as H,w as V,h,j as l,k as y,i as g,m as v,s as w,l as I,T as $}from"./index-BLqts8WY.js";import{D as K,a as L,av as S,au as R,aw as U}from"./index-MyY_xqVN.js";var j=Object.defineProperty,J=Object.getOwnPropertyDescriptor,B=(i,e,t,s)=>{for(var n=s>1?void 0:s?J(e,t):e,r=i.length-1,a;r>=0;r--)(a=i[r])&&(n=(s?a(e,t,n):a(n))||n);return s&&n&&j(e,t,n),n};let b=class extends x{constructor(){super(...arguments);p(this,"$notify");p(this,"DAILY_CHECK_TITLE",K);p(this,"DIRECT_PUSH_TITLE",L);p(this,"callback",()=>{});p(this,"hourAm",!0);p(this,"hourInput","8");p(this,"isVisible",!1);p(this,"messageInput","");p(this,"minuteInput","00");p(this,"pushType","");p(this,"serviceWorkerReady",!1);p(this,"vapidKey","")}async open(t,s){var n;this.callback=s||this.callback,this.isVisible=!0,this.pushType=t;try{const r=await A();let a=O;if(r!=null&&r.webPushServer&&(a=r.webPushServer),a.startsWith("http://localhost"))u("Not checking for VAPID in this local environment.");else{let o="";await this.axios.get(a+"/web-push/vapid").then(d=>{var m,f;this.vapidKey=((m=d.data)==null?void 0:m.vapidKey)||"",u("Got vapid key: "+this.vapidKey),o=JSON.stringify(d.data),(f=navigator.serviceWorker)==null||f.addEventListener("controllerchange",()=>{u("New service worker is now controlling the page")})}),this.vapidKey||(this.$notify({group:"alert",type:"danger",title:"Error Setting Notifications",text:"Could not set notifications."},5e3),u("Error Setting Notifications: web push server response didn't have vapidKey: "+o,!0))}}catch(r){window.location.host.startsWith("localhost")?u("Ignoring the error getting VAPID for local development."):(u("Got an error initializing notifications: "+JSON.stringify(r),!0),this.$notify({group:"alert",type:"danger",title:"Error Setting Notifications",text:"Got an error setting notifications."},5e3))}(n=navigator.serviceWorker)==null||n.ready.then(()=>{this.serviceWorkerReady=!0}),this.pushType===this.DIRECT_PUSH_TITLE?(this.messageInput="Click to share some gratitude with the world -- even if they're unnamed.",setTimeout(function(){var r;(r=document.getElementById("push-message"))==null||r.focus()},100)):this.messageInput=""}close(){this.isVisible=!1}sendMessageToServiceWorker(t){return new Promise((s,n)=>{var r,a;if((r=navigator.serviceWorker)!=null&&r.controller){const o=new MessageChannel;o.port1.onmessage=d=>{d.data.error?n(d.data.error):s(d.data)},(a=navigator.serviceWorker)==null||a.controller.postMessage(t,[o.port2])}else n("Service worker controller not available")})}async askPermission(){var s,n;if(!("serviceWorker"in navigator&&((s=navigator.serviceWorker)!=null&&s.controller)))return Promise.reject("Service worker not available.");await N.open();const t=(n=await N.secret.get(W))==null?void 0:n.secret;return t?this.sendSecretToServiceWorker(t).then(()=>this.checkNotificationSupport()).then(()=>this.requestNotificationPermission()).catch(r=>Promise.reject(r)):Promise.reject("No secret found.")}sendSecretToServiceWorker(t){const s={type:"SEND_LOCAL_DATA",data:t};return this.sendMessageToServiceWorker(s).then(n=>{u("Response from service worker: "+JSON.stringify(n))})}checkNotificationSupport(){return"Notification"in window?(window.Notification.permission==="granted",Promise.resolve()):(this.$notify({group:"alert",type:"danger",title:"Browser Notifications Are Not Supported",text:"This browser does not support notifications."},3e3),Promise.reject("This browser does not support notifications."))}requestNotificationPermission(){return window.Notification.requestPermission().then(t=>{if(t!=="granted")throw this.$notify({group:"alert",type:"danger",title:"Error Requesting Notification Permission",text:"Allow this app permission to make notifications for personal reminders. You can adjust them at any time in your settings."},-1),new Error("Permission was not granted to this app.");return t})}
|