Chrome Extension: Schedule notification not resetting data on chrome storage












0















I've developed an app that should trigger an alarm at a specific hour everyday. This alarm will trigger a rich notification, which has a callback function that sets data in the chrome storage.



The issue is:




  • If chrome is running the scheduled notification triggers correctly and resets the data in the chrome storage.

  • If chrome is not running (e.g.: PC turned off) and I start chrome 1 or 2 hours after the scheduled notification, the data will reset.

  • If chrome is not running and I start chrome 6 or 7 hours after (let's say I turn on the PC after my sleep) the data will not reset, even though the scheduled notification triggers.


Creating alarm:



chrome.alarms.create("resetDailyValue", {
when: new Date().setUTCHours(resetTime, 0, 0, 0),
periodInMinutes: resetTime * 60
});


Schedule notification:



chrome.alarms.onAlarm.addListener(function (alarm) {      
chrome.storage.sync.get(null, function (keys) {
dailyValue = keys["dailyValue"];
});

if (alarm.name === "resetDailyValue") {
chrome.notifications.create(resetNotificationOptions,
function () {
chrome.storage.sync.set({
"dailyValue": dailyDefaultValue
}, function () {
console.log("Daily value reset!");
});
});
}
});









share|improve this question























  • What's the point of setting dailyValue in this code? Where does dailyDefaultValue come from? Is your background page persistent? The fact that the notification does trigger means chrome.alarms works fine, something else is at fault.

    – Xan
    Nov 14 '18 at 11:59











  • dailyDefaultValue is a const equal to 0. The reason to set dailyValue to 0, is to reset a progress bar in the popup.html file. And as you can see in my bullet times, the setting of the value doesn't work when the extension is offline for a long time.

    – Pedro Gomes
    Nov 14 '18 at 19:44
















0















I've developed an app that should trigger an alarm at a specific hour everyday. This alarm will trigger a rich notification, which has a callback function that sets data in the chrome storage.



The issue is:




  • If chrome is running the scheduled notification triggers correctly and resets the data in the chrome storage.

  • If chrome is not running (e.g.: PC turned off) and I start chrome 1 or 2 hours after the scheduled notification, the data will reset.

  • If chrome is not running and I start chrome 6 or 7 hours after (let's say I turn on the PC after my sleep) the data will not reset, even though the scheduled notification triggers.


Creating alarm:



chrome.alarms.create("resetDailyValue", {
when: new Date().setUTCHours(resetTime, 0, 0, 0),
periodInMinutes: resetTime * 60
});


Schedule notification:



chrome.alarms.onAlarm.addListener(function (alarm) {      
chrome.storage.sync.get(null, function (keys) {
dailyValue = keys["dailyValue"];
});

if (alarm.name === "resetDailyValue") {
chrome.notifications.create(resetNotificationOptions,
function () {
chrome.storage.sync.set({
"dailyValue": dailyDefaultValue
}, function () {
console.log("Daily value reset!");
});
});
}
});









share|improve this question























  • What's the point of setting dailyValue in this code? Where does dailyDefaultValue come from? Is your background page persistent? The fact that the notification does trigger means chrome.alarms works fine, something else is at fault.

    – Xan
    Nov 14 '18 at 11:59











  • dailyDefaultValue is a const equal to 0. The reason to set dailyValue to 0, is to reset a progress bar in the popup.html file. And as you can see in my bullet times, the setting of the value doesn't work when the extension is offline for a long time.

    – Pedro Gomes
    Nov 14 '18 at 19:44














0












0








0








I've developed an app that should trigger an alarm at a specific hour everyday. This alarm will trigger a rich notification, which has a callback function that sets data in the chrome storage.



The issue is:




  • If chrome is running the scheduled notification triggers correctly and resets the data in the chrome storage.

  • If chrome is not running (e.g.: PC turned off) and I start chrome 1 or 2 hours after the scheduled notification, the data will reset.

  • If chrome is not running and I start chrome 6 or 7 hours after (let's say I turn on the PC after my sleep) the data will not reset, even though the scheduled notification triggers.


Creating alarm:



chrome.alarms.create("resetDailyValue", {
when: new Date().setUTCHours(resetTime, 0, 0, 0),
periodInMinutes: resetTime * 60
});


Schedule notification:



chrome.alarms.onAlarm.addListener(function (alarm) {      
chrome.storage.sync.get(null, function (keys) {
dailyValue = keys["dailyValue"];
});

if (alarm.name === "resetDailyValue") {
chrome.notifications.create(resetNotificationOptions,
function () {
chrome.storage.sync.set({
"dailyValue": dailyDefaultValue
}, function () {
console.log("Daily value reset!");
});
});
}
});









share|improve this question














I've developed an app that should trigger an alarm at a specific hour everyday. This alarm will trigger a rich notification, which has a callback function that sets data in the chrome storage.



The issue is:




  • If chrome is running the scheduled notification triggers correctly and resets the data in the chrome storage.

  • If chrome is not running (e.g.: PC turned off) and I start chrome 1 or 2 hours after the scheduled notification, the data will reset.

  • If chrome is not running and I start chrome 6 or 7 hours after (let's say I turn on the PC after my sleep) the data will not reset, even though the scheduled notification triggers.


Creating alarm:



chrome.alarms.create("resetDailyValue", {
when: new Date().setUTCHours(resetTime, 0, 0, 0),
periodInMinutes: resetTime * 60
});


Schedule notification:



chrome.alarms.onAlarm.addListener(function (alarm) {      
chrome.storage.sync.get(null, function (keys) {
dailyValue = keys["dailyValue"];
});

if (alarm.name === "resetDailyValue") {
chrome.notifications.create(resetNotificationOptions,
function () {
chrome.storage.sync.set({
"dailyValue": dailyDefaultValue
}, function () {
console.log("Daily value reset!");
});
});
}
});






javascript google-chrome google-chrome-extension google-chrome-app






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 13:42









Pedro GomesPedro Gomes

84




84













  • What's the point of setting dailyValue in this code? Where does dailyDefaultValue come from? Is your background page persistent? The fact that the notification does trigger means chrome.alarms works fine, something else is at fault.

    – Xan
    Nov 14 '18 at 11:59











  • dailyDefaultValue is a const equal to 0. The reason to set dailyValue to 0, is to reset a progress bar in the popup.html file. And as you can see in my bullet times, the setting of the value doesn't work when the extension is offline for a long time.

    – Pedro Gomes
    Nov 14 '18 at 19:44



















  • What's the point of setting dailyValue in this code? Where does dailyDefaultValue come from? Is your background page persistent? The fact that the notification does trigger means chrome.alarms works fine, something else is at fault.

    – Xan
    Nov 14 '18 at 11:59











  • dailyDefaultValue is a const equal to 0. The reason to set dailyValue to 0, is to reset a progress bar in the popup.html file. And as you can see in my bullet times, the setting of the value doesn't work when the extension is offline for a long time.

    – Pedro Gomes
    Nov 14 '18 at 19:44

















What's the point of setting dailyValue in this code? Where does dailyDefaultValue come from? Is your background page persistent? The fact that the notification does trigger means chrome.alarms works fine, something else is at fault.

– Xan
Nov 14 '18 at 11:59





What's the point of setting dailyValue in this code? Where does dailyDefaultValue come from? Is your background page persistent? The fact that the notification does trigger means chrome.alarms works fine, something else is at fault.

– Xan
Nov 14 '18 at 11:59













dailyDefaultValue is a const equal to 0. The reason to set dailyValue to 0, is to reset a progress bar in the popup.html file. And as you can see in my bullet times, the setting of the value doesn't work when the extension is offline for a long time.

– Pedro Gomes
Nov 14 '18 at 19:44





dailyDefaultValue is a const equal to 0. The reason to set dailyValue to 0, is to reset a progress bar in the popup.html file. And as you can see in my bullet times, the setting of the value doesn't work when the extension is offline for a long time.

– Pedro Gomes
Nov 14 '18 at 19:44












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282359%2fchrome-extension-schedule-notification-not-resetting-data-on-chrome-storage%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282359%2fchrome-extension-schedule-notification-not-resetting-data-on-chrome-storage%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine