Revision 9e26b71e
Added by koszko about 2 years ago
background/message_server.js | ||
---|---|---|
1 |
/** |
|
2 |
* Myext message server |
|
3 |
* |
|
4 |
* Copyright (C) 2021 Wojtek Kosior |
|
5 |
* Redistribution terms are gathered in the `copyright' file. |
|
6 |
*/ |
|
7 |
|
|
8 |
/* |
|
9 |
* IMPORTS_START |
|
10 |
* IMPORT browser |
|
11 |
* IMPORTS_END |
|
12 |
*/ |
|
13 |
|
|
14 |
var listeners = {}; |
|
15 |
|
|
16 |
/* magic should be one of the constants from /common/connection_types.js */ |
|
17 |
|
|
18 |
function listen_for_connection(magic, cb) |
|
19 |
{ |
|
20 |
listeners[magic] = cb; |
|
21 |
} |
|
22 |
|
|
23 |
function raw_listen(port) |
|
24 |
{ |
|
25 |
if (listeners[port.name] === undefined) |
|
26 |
return; |
|
27 |
|
|
28 |
listeners[port.name](port); |
|
29 |
} |
|
30 |
|
|
31 |
browser.runtime.onConnect.addListener(raw_listen); |
|
32 |
|
|
33 |
/* |
|
34 |
* EXPORTS_START |
|
35 |
* EXPORT listen_for_connection |
|
36 |
* EXPORTS_END |
|
37 |
*/ |
background/page_info_server.js | ||
---|---|---|
40 | 40 |
connection_data.port.postMessage(["new_url", query_all(url)]); |
41 | 41 |
} |
42 | 42 |
|
43 |
function remove_storage_listener(cb) |
|
44 |
{ |
|
45 |
storage.remove_change_listener(cb); |
|
46 |
} |
|
47 |
|
|
48 | 43 |
function new_connection(port) |
49 | 44 |
{ |
50 | 45 |
console.log("new page info connection!"); |
... | ... | |
59 | 54 |
storage.add_change_listener(_handle_change); |
60 | 55 |
|
61 | 56 |
port.onMessage.addListener(m => handle_subscription(connection_data, m)); |
62 |
port.onDisconnect.addListener(() => remove_storage_listener(handle_change)); |
|
57 |
port.onDisconnect.addListener( |
|
58 |
() => storage.remove_change_listener(_handle_change) |
|
59 |
); |
|
63 | 60 |
} |
64 | 61 |
|
65 | 62 |
async function start_page_info_server() |
common/message_server.js | ||
---|---|---|
1 |
/** |
|
2 |
* Myext message server |
|
3 |
* |
|
4 |
* Copyright (C) 2021 Wojtek Kosior |
|
5 |
* Redistribution terms are gathered in the `copyright' file. |
|
6 |
*/ |
|
7 |
|
|
8 |
/* |
|
9 |
* IMPORTS_START |
|
10 |
* IMPORT browser |
|
11 |
* IMPORTS_END |
|
12 |
*/ |
|
13 |
|
|
14 |
var listeners = {}; |
|
15 |
|
|
16 |
/* magic should be one of the constants from /common/connection_types.js */ |
|
17 |
|
|
18 |
function listen_for_connection(magic, cb) |
|
19 |
{ |
|
20 |
listeners[magic] = cb; |
|
21 |
} |
|
22 |
|
|
23 |
function raw_listen(port) |
|
24 |
{ |
|
25 |
if (listeners[port.name] === undefined) |
|
26 |
return; |
|
27 |
|
|
28 |
listeners[port.name](port); |
|
29 |
} |
|
30 |
|
|
31 |
browser.runtime.onConnect.addListener(raw_listen); |
|
32 |
|
|
33 |
/* |
|
34 |
* EXPORTS_START |
|
35 |
* EXPORT listen_for_connection |
|
36 |
* EXPORTS_END |
|
37 |
*/ |
Also available in: Unified diff
fix page info server bugs