Skip to content

Commit

Permalink
feat: automatically remove success notification
Browse files Browse the repository at this point in the history
Closes #8.
  • Loading branch information
dessant committed May 16, 2019
1 parent 62b780d commit 8b912f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
17 changes: 14 additions & 3 deletions src/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ async function clearDataType(dataType, options = null, enDataTypes = null) {
await browser.browsingData.remove({since}, dataTypes);
}
} catch (err) {
await showNotification('error_dataTypeNotCleared');
await showNotification({
messageId: 'error_dataTypeNotCleared',
type: 'error'
});
throw err;
}

Expand All @@ -154,7 +157,12 @@ async function clearDataType(dataType, options = null, enDataTypes = null) {
}

if (options.notifyOnSuccess) {
await showNotification('info_dataTypeCleared');
const notification = await showNotification({
messageId: 'info_dataTypeCleared'
});
window.setTimeout(() => {
browser.notifications.clear(notification);
}, 6000); // 6 seconds
}

if (options.reloadTabs !== 'false') {
Expand Down Expand Up @@ -191,7 +199,10 @@ async function onActionClick() {
const enDataTypes = await getEnabledDataTypes(options);

if (enDataTypes.length === 0) {
await showNotification('error_allDataTypesDisabled');
await showNotification({
messageId: 'error_allDataTypesDisabled',
type: 'error'
});
return;
}

Expand Down
14 changes: 10 additions & 4 deletions src/utils/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ function getOptionLabels(data, scope = 'optionValue') {
return labels;
}

function showNotification(messageId) {
return browser.notifications.create('cbd-notification', {
function showNotification({message, messageId, title, type = 'info'}) {
if (!title) {
title = getText('extensionName');
}
if (messageId) {
message = getText(messageId);
}
return browser.notifications.create(`cbd-notification-${type}`, {
type: 'basic',
title: getText('extensionName'),
message: getText(messageId),
title: title,
message: message,
iconUrl: '/src/icons/app/icon-48.png'
});
}
Expand Down

0 comments on commit 8b912f1

Please sign in to comment.