Commit 453b420c authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Connect to contextMenu clicked callback only once

The connection isn't bound to the menu entry but global causing the handler to fire multiple times, one more for every device added.

Differential Revision: https://phabricator.kde.org/D17102
parent 31d57c51
......@@ -140,34 +140,41 @@ function raiseTab(tabId) {
// ------------------------------------------------------------------------
//
var kdeConnectMenuIdPrefix = "kdeconnect_page_";
chrome.contextMenus.onClicked.addListener(function (info) {
if (!info.menuItemId.startsWith(kdeConnectMenuIdPrefix)) {
return;
}
var deviceId = info.menuItemId.substr(kdeConnectMenuIdPrefix.length);
var url = info.linkUrl || info.pageUrl;
console.log("Send url", url, "to kdeconnect device", deviceId);
if (!url) {
return;
}
port.postMessage({
subsystem: "kdeconnect",
event: "shareUrl",
url: url,
deviceId: deviceId
});
});
addCallback("kdeconnect", "deviceAdded", function(message) {
var id = message.id;
var name = message.name;
var menuEntryTitle = chrome.i18n.getMessage("kdeconnect_open_device", name);
var menuId = "kdeconnect_page_" + id;
var menuId = kdeConnectMenuIdPrefix + id;
chrome.contextMenus.create({
id: menuId,
contexts: ["link", "page"],
title: menuEntryTitle,
});
chrome.contextMenus.onClicked.addListener(function (info) {
if (info.menuItemId == menuId) {
var url = info.linkUrl || info.pageUrl;
console.log("Send url", url, "to kdeconnect device", id);
if (!url) {
return;
}
port.postMessage({
subsystem: "kdeconnect",
event: "shareUrl",
url: url,
deviceId: id
});
}
});
});
addCallback("kdeconnect", "deviceRemoved", function(message) {
......
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