From 614dea955c957d58c79da346fa36fec176c59728 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 29 Mar 2014 02:03:04 -0400 Subject: [PATCH] add an option to run silently -- no notifications at all --- _locales/en/messages.json | 1 + javascript/clearhistory.js | 24 +++++++++++++++--------- javascript/options.js | 4 +++- manifest.json | 5 +++-- views/options.html | 7 +++++++ 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 9ad84d3..d62529a 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -25,6 +25,7 @@ "optionsDownloads": {"message": "Clear download history"}, "optionsSaved": {"message": "Preferences saved!"}, "optionsAutoclear": {"message": "Automatically purge old entries"}, + "optionsNotify": {"message": "Display a notification whenever data is cleared"}, "confirmPrompt": {"message": "Are you sure you want to delete the history?"}, "notificationTitle": {"message": "History deleted successfully!"}, "notificationTimeNewer": { diff --git a/javascript/clearhistory.js b/javascript/clearhistory.js index 28eb2b0..b40f595 100644 --- a/javascript/clearhistory.js +++ b/javascript/clearhistory.js @@ -65,6 +65,9 @@ function clearDownloads(s) { * Callback for when history deletion is successful */ function didClearHistory(s) { + if (s.notify !== CONSTANTS.YES) + return; + var time = ~~(s.time) || CONSTANTS.DEFAULT_TIME; time = getUnitsForTime(time); var timeMsg = (time.time === -1) ? 'notificationTimeAll' : @@ -72,14 +75,17 @@ function didClearHistory(s) { 'notificationTimeOlder'; var timeString = chrome.i18n.getMessage(timeMsg, [time.time, time.units]); var message = chrome.i18n.getMessage('notificationBody', timeString); - var notification = webkitNotifications.createNotification( - chrome.extension.getURL('/images/icon48.png'), - chrome.i18n.getMessage('notificationTitle'), - message); - notification.show(); - setTimeout(function() { - notification.cancel(); - }, 5000); + var options = { + type: 'basic', + title: chrome.i18n.getMessage('notificationTitle'), + message: message, + iconUrl: chrome.extension.getURL('/images/icon128.png'), + }; + + var id = 'clearhistory advance notify'; + chrome.notifications.clear(id, function(wasCleared) { + chrome.notifications.create(id, options, function(){}); + }); } /** @@ -122,7 +128,7 @@ function clearAll(s) { function runCleaner() { var keys = [ - 'cookies', 'downloads', 'time', 'timeStart', + 'cookies', 'downloads', 'time', 'timeStart', 'notify', ]; chrome.storage.sync.get(keys, function(s) { if (s.cookies === CONSTANTS.YES) { diff --git a/javascript/options.js b/javascript/options.js index bd3a227..c4ffda4 100644 --- a/javascript/options.js +++ b/javascript/options.js @@ -40,7 +40,7 @@ function init() { // Load or set localStorage data var settings = [ - 'timeStart', 'time', 'prompt', 'cookies', 'downloads', 'autoclear', + 'timeStart', 'time', 'prompt', 'cookies', 'downloads', 'autoclear', 'notify', ]; chrome.storage.sync.get(settings, function(s) { var timeStart = s.timeStart || CONSTANTS.YES; @@ -49,6 +49,7 @@ function init() { var clearCookies = s.cookies || CONSTANTS.NO; var clearDownloads = s.downloads || CONSTANTS.NO; var autoClear = s.autoclear || CONSTANTS.NO; + var notify = s.notify || CONSTANTS.YES; $('input[name=timeStart][value="' + timeStart + '"]')[0].checked = true; $('input[name=time][value="' + time + '"]')[0].checked = true; @@ -56,6 +57,7 @@ function init() { $('input[name=cookies]')[0].checked = (clearCookies === CONSTANTS.YES); $('input[name=downloads]')[0].checked = (clearDownloads === CONSTANTS.YES); $('input[name=autoclear]')[0].checked = (autoClear === CONSTANTS.YES); + $('input[name=notify]')[0].checked = (notify === CONSTANTS.YES); }); } diff --git a/manifest.json b/manifest.json index ce21c70..05070f7 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,8 @@ "name": "__MSG_name__", "default_locale": "en", "manifest_version": 2, - "version": "1.5.3", + "minimum_chrome_version": "28", + "version": "1.5.4", "description": "__MSG_description__", "permissions": [ "alarms", @@ -35,6 +36,6 @@ "128": "images/icon128.png" }, "web_accessible_resources": [ - "images/icon48.png" + "images/icon128.png" ] } diff --git a/views/options.html b/views/options.html index 33e3748..7837324 100644 --- a/views/options.html +++ b/views/options.html @@ -107,6 +107,13 @@ +
+ +
+