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.
1 lines
11 KiB
1 lines
11 KiB
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})}checkHourInput(){const t=parseInt(this.hourInput);isNaN(t)?this.hourInput="12":t<1?(this.hourInput="12",this.hourAm=!this.hourAm):t>12?(this.hourInput="1",this.hourAm=!this.hourAm):this.hourInput=t.toString()}checkMinuteInput(){const t=parseInt(this.minuteInput);isNaN(t)?this.minuteInput="00":t<0?this.minuteInput="59":t<10?this.minuteInput="0"+t:t>59?this.minuteInput="00":this.minuteInput=t.toString()}async turnOnNotifications(){let t=()=>{};return this.askPermission().then(s=>(u("Permission granted: "+JSON.stringify(s)),this.subscribeToPush())).then(()=>{var s;return u("Subscribed successfully."),(s=navigator.serviceWorker)==null?void 0:s.ready}).then(s=>s.pushManager.getSubscription()).then(async s=>{if(s){t=await this.$notify({group:"alert",type:"info",title:"Notification Setup Underway",text:"Setting up notifications for interesting activity, which takes about 10 seconds. If you don't see a final confirmation, check the 'Troubleshoot' page."},-1);const n=S(this.hourInput),o=(this.hourAm?n===12?0:n:n===12?12:n+12)%24+Math.round(new Date().getTimezoneOffset()/60),d=(o+(o<0?24:0))%24,f=S(this.minuteInput)+Math.round(new Date().getTimezoneOffset()%60),T=(f+(f<0?60:0))%60,k={notifyTime:{utcHour:d,minute:T},notifyType:this.pushType,message:this.messageInput,...s.toJSON()};return await this.sendSubscriptionToServer(k),u("Subscription data sent to server with endpoint: "+s.endpoint),k}else throw new Error("Subscription object is not available.")}).then(async s=>{u("Subscription data sent to server and all finished successfully."),await R(s,!0),t(),setTimeout(()=>{this.$notify({group:"alert",type:"success",title:"Notification Is On",text:"You should see at least one on your device; if not, check the 'Troubleshoot' link."},7e3)},500);const n=this.hourInput+":"+this.minuteInput+" "+(this.hourAm?"AM":"PM");this.callback(!0,n,this.messageInput)}).catch(s=>{u("Got an error setting notification permissions: string "+s.toString()+" JSON "+JSON.stringify(s),!0),this.$notify({group:"alert",type:"danger",title:"Error Setting Notification Permissions",text:"Could not set notification permissions."},3e3)})}subscribeToPush(){return new Promise((t,s)=>{var a;if(!("serviceWorker"in navigator&&"PushManager"in window)){const o="Push messaging is not supported";return console.warn(o),s(new Error(o))}if(window.Notification.permission!=="granted"){const o="Notification permission not granted";return console.warn(o),s(new Error(o))}const r={userVisibleOnly:!0,applicationServerKey:U(this.vapidKey)};(a=navigator.serviceWorker)==null||a.ready.then(o=>o.pushManager.subscribe(r)).then(o=>{u("Push subscription successful: "+JSON.stringify(o)),t()}).catch(o=>{u("Push subscription failed: "+JSON.stringify(o)+" - "+JSON.stringify(r),!0),this.$notify({group:"alert",type:"danger",title:"Error Setting Push Notifications",text:"We encountered an issue setting up push notifications. If you wish to revoke notification permissions, please do so in your browser settings."},-1),s(o)})})}sendSubscriptionToServer(t){return u("About to send subscription... "+JSON.stringify(t)),fetch("/web-push/subscribe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then(s=>{if(!s.ok)throw console.error("Bad response subscribing to web push: ",s),new Error("Failed to send push subscription to server");u("Push subscription sent to server successfully.")})}};b=B([C],b);const Y={key:0,class:"fixed z-[100] top-0 inset-x-0 w-full inset-0 h-screen flex flex-col items-center justify-center bg-slate-900/50"},_={class:"flex w-11/12 max-w-sm mx-auto mb-3 overflow-hidden bg-white rounded-lg shadow-lg"},z={class:"w-full px-6 py-6 text-slate-900 text-center"},q={key:0,class:"text-lg mb-4"},G={key:0},F={key:1},Z={key:1,class:"text-lg mb-4"},Q={key:2},X={key:0},ee={key:1},te={class:"flex flex-row justify-center"},se={key:0},ie={key:1};function oe(i,e,t,s,n,r){const a=M("fa");return c(),H($,{"enter-active-class":"transform ease-out duration-300 transition","enter-from-class":"translate-y-2 opacity-0 sm:translate-y-4","enter-to-class":"translate-y-0 opacity-100 sm:translate-y-0","leave-active-class":"transition ease-in duration-500","leave-from-class":"opacity-100","leave-to-class":"opacity-0"},{default:V(()=>[i.isVisible?(c(),h("div",Y,[l("div",_,[l("div",z,[i.serviceWorkerReady&&i.vapidKey?(c(),h("p",q,[i.pushType===i.DAILY_CHECK_TITLE?(c(),h("span",G," Would you like to be notified of new activity, up to once a day? ")):(c(),h("span",F," Would you like to get a reminder message once a day? "))])):(c(),h("p",Z,[e[8]||(e[8]=y(" Waiting for system initialization, which may take up to 5 seconds... ")),g(a,{icon:"spinner",spin:""})])),i.serviceWorkerReady&&i.vapidKey?(c(),h("div",Q,[i.pushType===i.DAILY_CHECK_TITLE?(c(),h("div",X,e[9]||(e[9]=[l("span",null,"Yes, send me a message when there is new data for me",-1)]))):(c(),h("div",ee,[e[10]||(e[10]=l("span",null,"Yes, send me this message:",-1)),v(l("textarea",{type:"text",id:"push-message","onUpdate:modelValue":e[0]||(e[0]=o=>i.messageInput=o),class:"rounded border border-slate-400 mt-2 px-2 py-2 w-full",maxlength:"100"},null,512),[[w,i.messageInput]]),e[11]||(e[11]=l("span",{class:"w-full flex justify-between text-xs text-slate-500"},[l("span"),l("span",null,"(100 characters max)")],-1))])),l("div",null,[l("span",te,[e[14]||(e[14]=l("span",{class:"mt-2"},"... at: ",-1)),v(l("input",{type:"number",onChange:e[1]||(e[1]=(...o)=>i.checkHourInput&&i.checkHourInput(...o)),class:"rounded-l border border-r-0 border-slate-400 ml-2 mt-2 px-2 py-2 text-center w-20","onUpdate:modelValue":e[2]||(e[2]=o=>i.hourInput=o)},null,544),[[w,i.hourInput]]),v(l("input",{type:"number",onChange:e[3]||(e[3]=(...o)=>i.checkMinuteInput&&i.checkMinuteInput(...o)),class:"border border-slate-400 mt-2 px-2 py-2 text-center w-20","onUpdate:modelValue":e[4]||(e[4]=o=>i.minuteInput=o)},null,544),[[w,i.minuteInput]]),l("span",{class:"rounded-r border border-slate-400 bg-slate-200 text-center text-blue-500 mt-2 px-2 py-2 w-20",onClick:e[5]||(e[5]=o=>i.hourAm=!i.hourAm)},[i.hourAm?(c(),h("span",se,[e[12]||(e[12]=y(" AM ")),g(a,{icon:"chevron-down"})])):(c(),h("span",ie,[e[13]||(e[13]=y(" PM ")),g(a,{icon:"chevron-up"})]))])])]),l("button",{class:"block w-full text-center text-md font-bold uppercase bg-blue-600 text-white mt-2 px-2 py-2 rounded-md",onClick:e[6]||(e[6]=o=>{i.close(),i.turnOnNotifications()})}," Turn on Daily Message ")])):I("",!0),l("button",{onClick:e[7]||(e[7]=o=>i.close()),class:"block w-full text-center text-md font-bold uppercase bg-slate-600 text-white mt-4 px-2 py-2 rounded-md"}," No, Not Now ")])])])):I("",!0)]),_:1})}const le=D(b,[["render",oe],["__scopeId","data-v-9f8794cf"]]);export{le as P};
|
|
|