OLD | NEW |
1 chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) | 1 chrome.runtime.onMessage.addListener((message, sender, sendResponse) => |
2 { | 2 { |
3 return ext.onMessage._dispatch(message, {}, sendResponse).indexOf(true) != -1; | 3 return ext.onMessage._dispatch(message, {}, sendResponse).indexOf(true) != -1; |
4 }); | 4 }); |
5 | 5 |
6 ext.onExtensionUnloaded = (function() | 6 ext.onExtensionUnloaded = (() => |
7 { | 7 { |
8 var port = null; | 8 let port = null; |
9 | 9 |
10 return { | 10 return { |
11 addListener: function(listener) | 11 addListener: listener => |
12 { | 12 { |
13 if (!port) | 13 if (!port) |
14 port = chrome.runtime.connect(); | 14 port = chrome.runtime.connect(); |
15 | 15 |
16 // When the extension is reloaded, disabled or uninstalled the | 16 // When the extension is reloaded, disabled or uninstalled the |
17 // background page dies and automatically disconnects all ports | 17 // background page dies and automatically disconnects all ports |
18 port.onDisconnect.addListener(listener); | 18 port.onDisconnect.addListener(listener); |
19 }, | 19 }, |
20 removeListener: function(listener) | 20 removeListener: listener => |
21 { | 21 { |
22 if (port) | 22 if (port) |
23 { | 23 { |
24 port.onDisconnect.removeListener(listener); | 24 port.onDisconnect.removeListener(listener); |
25 | 25 |
26 if (!port.onDisconnect.hasListeners()) | 26 if (!port.onDisconnect.hasListeners()) |
27 { | 27 { |
28 port.disconnect(); | 28 port.disconnect(); |
29 port = null; | 29 port = null; |
30 } | 30 } |
31 } | 31 } |
32 } | 32 } |
33 }; | 33 }; |
34 })(); | 34 })(); |
OLD | NEW |