I have an application in vue js, which registers a task, I would like to be notified 5 minutes before the task happens, I have the following code.
function getData(){
let data = new Date();
let dia = data.getDate();
if (dia.toString().length == 1){
dia = "0"+dia;
}
let mes = data.getMonth() + 1;
if (mes.toString().length == 1){
mes = "0"+mes;
}
let ano = data.getFullYear();
let dataFull = dia + '/' + mes + '/' + ano;
let hora = data.getHours();
if (hora.toString().length == 1){
hora = "0"+hora;
}
let minuto = data.getMinutes();
if (minuto.toString().length == 1){
minuto = "0"+minuto;
}
let horaFull = hora + ':' + minuto;
let horaAlarm = hora + ':' + (minuto - 5);
return {
dia: dia,
mes: mes,
ano: ano,
hora: hora,
minuto: minuto,
dataFull: dataFull,
horaFull: horaFull,
horaAlarm: horaAlarm
}
}
document.addEventListener('DOMContentLoaded', function(){
if(Notification.permission !== 'granted')
Notification.requestPermission();
});
if(getData().horaFull == getData().horaAlarm){
var notification = new Notification('Titulo teste',{
ico: 'https://www.google.com.br/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
body: falta 5 minutos para sua tarefa
});
}
But he never falls on (if) anyone can help me ???