diff --git a/extension/extension-purpose.js b/extension/extension-purpose.js --- a/extension/extension-purpose.js +++ b/extension/extension-purpose.js @@ -17,6 +17,10 @@ let purposeShareMenuId = "purpose_share"; +// Stores so that when you click the finished +// notification it will open the URL +let purposeNotificationUrls = {}; + function purposeShare(data) { return new Promise((resolve, reject) => { sendPortMessageWithReply("purpose", "share", {data}).then((reply) => { @@ -43,6 +47,12 @@ title: chrome.i18n.getMessage("purpose_share_finished_title"), message: chrome.i18n.getMessage("purpose_share_finished_text", url), iconUrl: "icons/document-share.png" + }, (notificationId) => { + if (chrome.runtime.lastError) { + return; + } + + purposeNotificationUrls[notificationId] = url; }); } @@ -107,3 +117,14 @@ addRuntimeCallback("purpose", "share", (message, sender, action) => { return purposeShare(message); }); + +chrome.notifications.onClicked.addListener((notificationId) => { + const url = purposeNotificationUrls[notificationId]; + if (url) { + chrome.tabs.create({url}); + } +}); + +chrome.notifications.onClosed.addListener((notificationId) => { + delete purposeNotificationUrls[notificationId]; +});