VulpesOS/assets/webapps/network-alerts.gaiamobile.org/js/attention/attention.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

9 lines
No EOL
1.6 KiB
JavaScript

;'use strict';(function(exports){var form;function init(){form=document.querySelector('form');form.addEventListener('submit',onFormSubmit);navigator.mozL10n.once(function(){sendNotification().catch((err)=>{console.error('Error while sending a notification',err);});});document.addEventListener('visibilitychange',onVisibilityChange);}
function sendNotification(){var params=Utils.parseParams();var fromNotification=params.notification;if(fromNotification){return Promise.resolve();}
return new Promise(function(resolve,reject){var titleL10n=params.title;var body=params.body;var req=navigator.mozApps.getSelf();req.onsuccess=function onsuccess(event){var app=event.target.result;NotificationHelper.send(titleL10n,{body:body,tag:''+Date.now(),icon:NotificationHelper.getIconURI(app),data:{title:titleL10n},closeOnClick:false}).then(function(notification){notification.onerror=function onerror(){reject(new Error('CMAS: notification API error'));};notification.onshow=resolve;});};req.onerror=function onerror(){reject(new Error('CMAS: App getSelf request error'));};});}
function closeApp(){window.opener?window.opener.close():window.close();}
function onFormSubmit(e){e.preventDefault();closeApp();}
function onVisibilityChange(){if(document.hidden&&!document.querySelector('h1').clientHeight){closeApp();}}
function render(){var params=Utils.parseParams();renderForm(params);var fromNotification=params.notification;if(!fromNotification){Notify.notify();}}
function renderForm(params){var title=params.title;var body=params.body;form.querySelector('h1').setAttribute('data-l10n-id',title);form.querySelector('p').textContent=body;}
exports.Attention={init,render};})(window);