Skip to content

Commit

Permalink
fixed adding event before events initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
gergelyszabo94 committed Oct 14, 2019
1 parent 3240c9e commit e1a75d0
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions extension/chrome/js/background_scripts/background.js
@@ -1,16 +1,17 @@
// handles install and update events
chrome.runtime.onInstalled.addListener((details) =>{
if(details.reason === 'install'){

// sets the default options for first run (on install from the webstore/amo or when loaded in developer mode)
for (let key in storageKeys) {chrome.storage.local.set({[key]: storageKeys[key]}, () =>{});}

let installEvent = {
type:'install',
timestamp: Date.now()
};

trackEvent(installEvent);

// sets the default options for first run (on install from the webstore/amo or when loaded in developer mode)
for (let key in storageKeys) {chrome.storage.local.set({[key]: storageKeys[key]}, () =>{});}

chrome.browserAction.setBadgeText({text: 'I'});
chrome.notifications.create('installed', {
type: 'basic',
Expand All @@ -20,13 +21,6 @@ chrome.runtime.onInstalled.addListener((details) =>{
},(notificationId) =>{});
}
else if(details.reason === 'update'){
let updateEvent = {
type:'update',
timestamp: Date.now()
};

trackEvent(updateEvent);

// sets defaults options for new options that haven't been set yet (for features introduced since the last version - runs when the extension updates or gets reloaded in developer mode)
// it checks whether the setting has ever been set - I consider removing older ones since there is no one updating from version that old
let keysArray = [];
Expand All @@ -36,6 +30,13 @@ chrome.runtime.onInstalled.addListener((details) =>{
for (let key in storageKeys) { if (result[key] === undefined) chrome.storage.local.set({[key]: storageKeys[key]}, () =>{}) }
});

let updateEvent = {
type:'update',
timestamp: Date.now()
};

trackEvent(updateEvent);

chrome.browserAction.setBadgeText({text: 'U'});

// notifies the user when the extension is updated
Expand Down

0 comments on commit e1a75d0

Please sign in to comment.