Skip to content

Commit

Permalink
Minor change to notifications function.
Browse files Browse the repository at this point in the history
  • Loading branch information
pilar6195 committed Jun 11, 2019
1 parent 3d069ed commit bc7cedb
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
var browser = browser || chrome; // eslint-disable-line

function createNotification(type, title, message, sticky, timeout) {
function createNotification(title, message = '', sticky = false, timeout) {
const notificationContent = {
type,
type: 'basic',
iconUrl: 'logo.png',
title,
message: message || ''
title, message,
requireInteraction: typeof InstallTrigger === 'undefined'
? sticky
: false
};

if (typeof InstallTrigger === 'undefined') // Does not work with firefox.
notificationContent.requireInteraction = sticky || false;

const id = `notification_${Date.now()}`;
browser.notifications.create(id, notificationContent);

Expand All @@ -30,9 +29,7 @@ function copyText(text) {
input.remove();
}

browser.notifications.onClicked.addListener(id => {
browser.notifications.clear(id);
});
browser.notifications.onClicked.addListener(browser.notifications.clear);

/* On extension icon click */
browser.browserAction.onClicked.addListener(tab => {
Expand All @@ -55,7 +52,7 @@ browser.browserAction.onClicked.addListener(tab => {

const json = await response.json();
copyText(json.url);
createNotification('basic', 'URL shortened and copied to clipboard!', json.url, false, 5000);
createNotification('URL shortened and copied to clipboard!', json.url, false, 5000);

if (items.history.length === 5)
items.history.pop();
Expand All @@ -65,7 +62,7 @@ browser.browserAction.onClicked.addListener(tab => {
browser.storage.local.set({ history: items.history });
} catch (err) {
console.log(err.toString());
createNotification('basic', 'An error has occured!', err.toString(), true);
createNotification('An error has occured!', err.toString(), true);
} finally {
browser.browserAction.setBadgeText({ text: '' });
}
Expand Down

0 comments on commit bc7cedb

Please sign in to comment.