Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 "use strict"; | 1 "use strict"; |
2 | 2 |
3 chrome.runtime.onMessage.addListener((message, sender, sendResponse) => | 3 chrome.runtime.onMessage.addListener((message, sender, sendResponse) => |
4 { | 4 { |
5 return ext.onMessage._dispatch(message, {}, sendResponse).indexOf(true) != -1; | 5 return ext.onMessage._dispatch(message, {}, sendResponse).indexOf(true) != -1; |
6 }); | 6 }); |
7 | 7 |
8 ext.onExtensionUnloaded = (() => | |
Sebastian Noack
2017/01/16 15:35:55
The IFEE here existed originally to encapsulate th
kzar
2017/01/17 07:42:44
Done.
| |
9 { | 8 { |
10 let port = null; | 9 let port = null; |
11 | 10 |
12 return { | 11 ext.onExtensionUnloaded = { |
13 addListener(listener) | 12 addListener(listener) |
14 { | 13 { |
15 if (!port) | 14 if (!port) |
16 port = chrome.runtime.connect(); | 15 port = chrome.runtime.connect(); |
17 | 16 |
18 // When the extension is reloaded, disabled or uninstalled the | 17 // When the extension is reloaded, disabled or uninstalled the |
19 // background page dies and automatically disconnects all ports | 18 // background page dies and automatically disconnects all ports |
20 port.onDisconnect.addListener(listener); | 19 port.onDisconnect.addListener(listener); |
21 }, | 20 }, |
22 removeListener(listener) | 21 removeListener(listener) |
23 { | 22 { |
24 if (port) | 23 if (port) |
25 { | 24 { |
26 port.onDisconnect.removeListener(listener); | 25 port.onDisconnect.removeListener(listener); |
27 | 26 |
28 if (!port.onDisconnect.hasListeners()) | 27 if (!port.onDisconnect.hasListeners()) |
29 { | 28 { |
30 port.disconnect(); | 29 port.disconnect(); |
31 port = null; | 30 port = null; |
32 } | 31 } |
33 } | 32 } |
34 } | 33 } |
35 }; | 34 }; |
36 })(); | 35 } |
LEFT | RIGHT |