-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathbackground.js
More file actions
24 lines (21 loc) · 788 Bytes
/
background.js
File metadata and controls
24 lines (21 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let connections = 0;
let programPort = null;
chrome.runtime.onConnect.addListener(function(port) {
if (!connections++)
programPort = chrome.runtime.connectNative("org.mpris.browser_host");
function passMessage(msg) {
if (msg.tabId === port.sender.tab.id || msg.tabId < 0)
port.postMessage(msg);
};
programPort.onMessage.addListener(passMessage);
port.onMessage.addListener(function(msg) {
msg.tabId = port.sender.tab.id;
programPort.postMessage(msg);
});
port.onDisconnect.addListener(function() {
programPort.postMessage({ type: "quit", tabId: port.sender.tab.id });
programPort.onMessage.removeListener(passMessage);
if (!--connections)
programPort.disconnect();
});
});