From af0b8dda037efddcf0a2dad5ba85525bba02295a Mon Sep 17 00:00:00 2001 From: Ivan Gadzhega Date: Mon, 13 Feb 2017 01:32:12 +0200 Subject: [PATCH] Show notifications when receiving money --- audio/coin.mp3 | Bin 0 -> 7680 bytes background.js | 49 ++++++++++++++++++++++++++++++++++++++++++------- manifest.json | 4 +++- 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 audio/coin.mp3 diff --git a/audio/coin.mp3 b/audio/coin.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..bf9f6a32a705a37a53a359445de4609c17fb13c7 GIT binary patch literal 7680 zcmZ8`1yEI8)b_cT?n{@zr9(to1eEUXk{5wXgMf&L3YU~d8U&GUq)WORq(M?Z>6DVV zobU3!|3CB1w`TU)GbiS(XYFUz-rz|P0{FjT?C`=4eUAh^SO9<#0I;wK2??pGso`)q zH#fJSprE+8xU{sis;a8KzW%dk&kzWNi;Ih=r>BpPPjGN>L_}O%Txx1+c6N4gadA~u zRdaK5cX#*b=;+MM%)-LL+S=Oo_V)h%{^{xI)zuYvC+L4YR+rIG5aN3*_7eKyP9 z0H9E0!&uY=0L42!)^U_e?jHOv0Z(2b0D_=1OsD{>FaaELgO3XU4fxV-`DIC%_)wZq zb(`lhhF3D*;C&vN$a(pdVA~e;Nbc;C^*C7>KHDA zLo!~X{alkI+D*(|+7C_=xOxM7^^0lHBLf^{!I{F1|X z^unpVi8)EAhZ|Qv3}sW0p#j1O zFn&X;xH+Zsm%sQ5hez2|3*+K8`1#2!g?2(Z7xXCws>mYXY-_ZZNT7Ly=qfGpb5b83AD;g2sYqG9UzM z*~RnCNt$+w0CQ%4z8O5JK~UUt_g7yT-Xr}8r1C%T=LfpUQSb}ttC|!3c)C&buFKP6 zcsJlrx?_J|vea1cCCq9y1&DyA)Dp@-9K=j+MvW&>J(Kl!=&4@ zE>9+W9P{l*K{TCP&K52sKTu6UKb<~tXnMFARQ>uI1pi{P1IojZh|Hgj15xmLlSO%9 zg&QOz5>2&Rrt&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pWFt?*L?2?=qrG82PX)?NhynZ;}= zpd(Z!lDjz3;G92O&AQYPs!@nbTGn@4QcYJhVX2r)lY+amZ@evp1gCjAqkLm*AjT60 zI5u`+$TN~?^y$%M2=(7KFq|eBybOt8enNES(3VL~JNO~F)%vk|mi!DIN-34@&-DL4 aQRM?qC=ht)rEb4lZvcQizq<+>82k^%z}Mmc literal 0 HcmV?d00001 diff --git a/background.js b/background.js index 0241df2..d699e5e 100644 --- a/background.js +++ b/background.js @@ -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 // -------------------------------------------------- @@ -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); diff --git a/manifest.json b/manifest.json index d539f04..53c0ada 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,9 @@ }, "permissions": [ "https://publisher.assetstore.unity3d.com/", - "alarms" + "alarms", + "notifications", + "storage" ], "browser_action": { "default_title": "",