Skip to content

Commit

Permalink
Show notifications when receiving money
Browse files Browse the repository at this point in the history
  • Loading branch information
Borod4r committed Feb 12, 2017
1 parent b159c60 commit af0b8dd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
Binary file added audio/coin.mp3
Binary file not shown.
49 changes: 42 additions & 7 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,40 @@ function showErrorBadge() {
chrome.browserAction.setBadgeText({ text: "ERR" } );
}

// --------------------------------------------------
// Notifications
// --------------------------------------------------

function playNotificationSound() {
var sound = new Audio('audio/coin.mp3');
sound.play();
}

function showRevenueNotification(revenue) {
var opt = {
type: "basic",
title: "Asset Store Checker",
message: "+ " + revenue.toString() + "$",
iconUrl: "icon.128.png"
};
chrome.notifications.create(opt);
playNotificationSound();
}

// --------------------------------------------------
// Storage
// --------------------------------------------------

function checkRevenueDiff(revenue, callback) {
chrome.storage.local.get(['revenue'], function (old) {
var diff = revenue - old.revenue;
if (diff > 0) {
callback(diff);
chrome.storage.local.set({'revenue': revenue});
}
});
}

// --------------------------------------------------
// HTTP Requests
// --------------------------------------------------
Expand Down Expand Up @@ -102,13 +136,14 @@ function getCurrentRevenue() {
get(getCurrentRevenueUrl(id, period))
.then(JSON.parse)
.then(function (result) {
var arr = result.aaData;
var total= 0.0;
for(var i in arr) {
total += parseFloat(arr[i][5].replace(/\$|,/g, ''));
}
total = Math.round(total * 0.7);
showRevenueBadge(total);
var arr = result.aaData;
var revenue= 0.0;
for(var i in arr) {
revenue += parseFloat(arr[i][5].replace(/\$|,/g, ''));
}
revenue = Math.round(revenue * 0.7);
showRevenueBadge(revenue);
checkRevenueDiff(revenue, showRevenueNotification);
}, chainError);
}, chainError);
}, chainError);
Expand Down
4 changes: 3 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
},
"permissions": [
"https://publisher.assetstore.unity3d.com/",
"alarms"
"alarms",
"notifications",
"storage"
],
"browser_action": {
"default_title": "",
Expand Down

0 comments on commit af0b8dd

Please sign in to comment.