Skip to content

Commit

Permalink
Displaying notification on success.
Browse files Browse the repository at this point in the history
  • Loading branch information
pilar6195 committed May 17, 2019
1 parent d17aa27 commit d360216
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
function createNotification(type, title, message, sticky) {
function createNotification(type, title, message, sticky, timeout) {
const notificationContent = {
type,
iconUrl: 'logo.png',
title,
message
message: message || ''
};

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

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

if (typeof timeout === 'number')
setTimeout(() => chrome.notifications.clear(id), timeout);

return id;
}

Expand Down Expand Up @@ -39,6 +43,7 @@ chrome.browserAction.onClicked.addListener(async tab => {
});
const json = await response.json();
copyText(json.url);
createNotification('basic', 'URL shortened and copied to clipboard!', json.url, false, 5000);
} catch (err) {
console.log(err.toString());
createNotification('basic', 'An error has occured!', err.toString(), true);
Expand Down

0 comments on commit d360216

Please sign in to comment.