Commit 7b11fee2 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Remove kde connect context menu entries when host dies

They don't work without a host and up on (re)starting we get a deviceAdded signal for every device leading to duplicate menu id errors.

Differential Revision: https://phabricator.kde.org/D21044
parent 324f54cf
......@@ -141,6 +141,7 @@ function raiseTab(tabId) {
//
var kdeConnectMenuIdPrefix = "kdeconnect_page_";
var kdeConnectDevices = [];
chrome.contextMenus.onClicked.addListener(function (info) {
if (!info.menuItemId.startsWith(kdeConnectMenuIdPrefix)) {
......@@ -175,10 +176,19 @@ addCallback("kdeconnect", "deviceAdded", function(message) {
contexts: ["link", "page"],
title: menuEntryTitle,
});
kdeConnectDevices.push(id);
});
addCallback("kdeconnect", "deviceRemoved", function(message) {
chrome.contextMenus.remove("kdeconnect_page_" + message.id)
let id = message.id;
let idx = kdeConnectDevices.indexOf(id);
if (idx > -1) {
kdeConnectDevices.splice(idx, 1);
}
chrome.contextMenus.remove(kdeConnectMenuIdPrefix + id);
});
// MPRIS
......@@ -675,6 +685,12 @@ function connectHost() {
console.warn("Host disconnected", error);
// Remove all kde connect menu entries since they won't work without a host
for (let device of kdeConnectDevices) {
chrome.contextMenus.remove(kdeConnectMenuIdPrefix + device);
}
kdeConnectDevices = [];
var reason = chrome.i18n.getMessage("general_error_unknown");
if (error && error.message) {
reason = error.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