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; }); } @@ -104,3 +114,16 @@ addRuntimeCallback("purpose", "share", (message, sender, action) => { return purposeShare(message); }); + +chrome.notifications.onClicked.addListener((notificationId) => { + const url = purposeNotificationUrls[notificationId]; + if (url) { + delete purposeNotificationUrls[notificationId]; + + chrome.tabs.create({url}); + } +}); + +chrome.notifications.onClosed.addListener((notificationId) => { + delete purposeNotificationUrls[notificationId]; +}); diff --git a/extension/utils.js b/extension/utils.js --- a/extension/utils.js +++ b/extension/utils.js @@ -22,12 +22,29 @@ static get() { return new Promise((resolve, reject) => { - SettingsUtils.storage().get(DEFAULT_EXTENSION_SETTINGS, (items) => { + SettingsUtils.storage().get(null /* get all */, (items) => { const error = chrome.runtime.lastError; if (error) { return reject(error); } + // Passing a default Object get() only returns defaults for the top level of the object, + // so we need to merge the level underneath manually. + const addObjectInto = (obj, add) => { + if (typeof add !== "object" || Array.isArray(add)) { + return; + } + + Object.keys(add).forEach((key) => { + if (!obj.hasOwnProperty(key)) { + obj[key] = add[key]; + } else { + addObjectInto(obj[key], add[key]); + } + }); + }; + + addObjectInto(items, DEFAULT_EXTENSION_SETTINGS); resolve(items); }); });