Skip to content

Commit e973b57

Browse files
committed
Fix viewing notifications
1 parent 9d37278 commit e973b57

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/scripts/background.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,31 @@ function mainTRacker(activeUrl, tab, activeTab) {
9393
}
9494

9595
function showNotification(activeUrl, tab) {
96-
chrome.notifications.clear('watt-site-notification');
96+
chrome.notifications.clear('watt-site-notification', function (wasCleared) {
97+
if (!wasCleared) {
98+
console.log('!wasCleared');
99+
100+
chrome.notifications.create(
101+
'watt-site-notification', {
102+
type: 'basic',
103+
iconUrl: 'icons/128x128.png',
104+
title: "Web Activity Time Tracker",
105+
contextMessage: activeUrl + ' ' + convertShortSummaryTimeToString(tab.getTodayTime()),
106+
message: setting_notification_message
107+
}, function (notificationId) {
108+
console.log(notificationId);
109+
chrome.notifications.clear('watt-site-notification', function (wasCleared) {
110+
if (wasCleared)
111+
notificationAction(activeUrl, tab);
112+
});
113+
});
114+
} else {
115+
notificationAction(activeUrl, tab);
116+
}
117+
});
118+
}
119+
120+
function notificationAction(activeUrl, tab){
97121
chrome.notifications.create(
98122
'watt-site-notification', {
99123
type: 'basic',
@@ -165,6 +189,10 @@ function checkSettingsImEmpty() {
165189
});
166190
}
167191

192+
function setDefaultValueForNewSettings() {
193+
loadNotificationMessage();
194+
}
195+
168196
function addListener() {
169197
chrome.tabs.onActivated.addListener(function (info) {
170198
chrome.tabs.get(info.tabId, function (tab) {
@@ -183,6 +211,7 @@ function addListener() {
183211
}
184212
if (details.reason == 'update') {
185213
checkSettingsImEmpty();
214+
setDefaultValueForNewSettings();
186215
isNeedDeleteTimeIntervalFromTabs = true;
187216
}
188217
});
@@ -271,6 +300,10 @@ function loadNotificationList() {
271300
function loadNotificationMessage() {
272301
storage.getValue(STORAGE_NOTIFICATION_MESSAGE, function (item) {
273302
setting_notification_message = item;
303+
if (isEmpty(setting_notification_message)) {
304+
storage.saveValue(STORAGE_NOTIFICATION_MESSAGE, STORAGE_NOTIFICATION_MESSAGE_DEFAULT);
305+
setting_notification_message = STORAGE_NOTIFICATION_MESSAGE_DEFAULT;
306+
}
274307
});
275308
}
276309

@@ -285,6 +318,7 @@ function loadAddDataFromStorage() {
285318
loadBlackList();
286319
loadRestrictionList();
287320
loadNotificationList();
321+
loadNotificationMessage();
288322
loadSettings();
289323
}
290324

0 commit comments

Comments
 (0)