2 Copyright (C) 2017 Kai Uwe Broulik <kde@privat.broulik.de>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 3 of
7 the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 var kdeConnectMenuIdPrefix = "kdeconnect_page_";
19 var kdeConnectDevices = {};
21 chrome.contextMenus.onClicked.addListener(function (info) {
22 if (!info.menuItemId.startsWith(kdeConnectMenuIdPrefix)) {
26 const deviceId = info.menuItemId.substr(info.menuItemId.indexOf("@") + 1);
28 var url = info.linkUrl || info.srcUrl || info.pageUrl;
29 console.log("Send url", url, "to kdeconnect device", deviceId);
35 subsystem: "kdeconnect",
42 addCallback("kdeconnect", "deviceAdded", function(message) {
43 let deviceId = message.id;
44 let name = message.name;
45 let type = message.type;
48 id: kdeConnectMenuIdPrefix + "open@" + deviceId,
49 contexts: ["link", "page", "image", "audio", "video"],
50 title: chrome.i18n.getMessage("kdeconnect_open_device", name),
52 "http://*/*", "https://*/*"
61 iconName = "smartphone-symbolic";
64 iconName = "tablet-symbolic";
67 case "tv": // at this size you can't really tell desktop monitor icon from a TV
68 iconName = "computer-symbolic";
71 iconName = "computer-laptop-symbolic";
77 "16": "icons/" + iconName + ".svg"
82 chrome.contextMenus.create(props);
85 id: kdeConnectMenuIdPrefix + "call@" + deviceId,
87 title: chrome.i18n.getMessage("kdeconnect_call_device", name),
95 "16": "icons/call-start-symbolic.svg"
99 chrome.contextMenus.create(props);
101 kdeConnectDevices[deviceId] = {
106 addCallback("kdeconnect", "deviceRemoved", function(message) {
107 let deviceId = message.id;
109 if (!kdeConnectDevices[deviceId]) {
113 delete kdeConnectDevices[deviceId];
114 chrome.contextMenus.remove(kdeConnectMenuIdPrefix + "open@" + deviceId);
115 chrome.contextMenus.remove(kdeConnectMenuIdPrefix + "call@" + deviceId);