From 7cacd9adc7f37377f55e095f743a0889ce0dd6db Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 9 Nov 2016 09:39:26 +0100 Subject: changes: fix more email bugs --- modules/changes/changes.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'modules') diff --git a/modules/changes/changes.js b/modules/changes/changes.js index 4e9d87e..b420658 100644 --- a/modules/changes/changes.js +++ b/modules/changes/changes.js @@ -45,28 +45,26 @@ if(gsettings.notify){ scheduleNotify(); } -var notifyIsScheduled=false; +var notifyTimeout=null; function scheduleNotify(){ - if(notifyIsScheduled){ + if(notifyTimeout){ console.log("WARNING: requesting notify schedule when already scheduled"); return; } - notifyIsScheduled=true; - var timeoutFunc=function(){ - if(!gsettings.notify){ - notifyIsScheduled=false; - return; - } - performNotify(gsettings.notify,function(){ - performCleanup(); - if(gsettings.notify){ - setTimeout(timeoutFunc,gsettings.notify.interval); - } else { - notifyIsScheduled=false; - } - }); - }; - setTimeout(timeoutFunc,gsettings.notify.interval); + notifyTimeout=setTimeout(notifyTimerFunction,gsettings.notify.interval); +} + +function notifyTimerFunction(){ + if(!gsettings.notify){ + notifyTimeout=null; + return; + } + notifyTimeout=setTimeout(notifyTimerFunction,gsettings.notify.interval); + console.log("Performing notify"); + performNotify(gsettings.notify,function(){ + console.log("Performing cleanup"); + performCleanup(); + }); } @@ -228,8 +226,11 @@ function performNotify(settings,cb){ newdate: newhashes[url].date }); } + console.log("performNotify: diffs = "+JSON.stringify(diffs)); if(diffs.length!=0){ sendMail(settings.to,constructMailBody(settings.to,diffs),cb); + } else { + cb(); } }); } @@ -266,6 +267,7 @@ function performCleanup(){ } } } + persist.setItemSync("urls",urls); } -- cgit v1.2.3-70-g09d2