Commit ae4890cf authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Purpose Plugin] Open shared URL when clicking notification

When we get a URL back from the share provider, let clicking the notification open it.

Differential Revision: https://phabricator.kde.org/D28792
parent 08468773
......@@ -17,6 +17,10 @@
let purposeShareMenuId = "purpose_share";
// Stores <notification id, share url> 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 @@ function purposeShare(data) {
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 @@ chrome.contextMenus.onClicked.addListener((info) => {
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];
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment