committing because switching branches
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- This exists to load NaCl into context for the background script -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<!-- including nacl here -->
|
||||
<script src="dist/jex_include/local-nacl-1.0.3/nacl.js"></script>
|
||||
<script type="module" src="dist/background.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
"browser_action" : {"default_icon" : "art/jrx-icon-32.png",
|
||||
"default_title" : "Jæck Russell",
|
||||
"default_popup" : "popup.html"},
|
||||
"background" : {"scripts": ["dist/background.js"]},
|
||||
"background" : {"page" : "background.html"},
|
||||
"permissions" : ["storage"]}
|
||||
|
||||
+75
-10
@@ -8,24 +8,89 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
export {
|
||||
};
|
||||
|
||||
import * as awcp from './jex_include/local-awcp-0.2.1/dist/awcp.js';
|
||||
|
||||
/**
|
||||
* @example
|
||||
* ```json
|
||||
* {
|
||||
* // EventData_A2w
|
||||
* "type": "to_waellet",
|
||||
* "data": {
|
||||
* // RpcCall
|
||||
* "jsonrpc": "2.0",
|
||||
* "id": "ske-connect-1",
|
||||
* "method": "connection.open",
|
||||
* "params": {
|
||||
* // Params_A2W_connection_open
|
||||
* "name": "sidekick examples",
|
||||
* "version": 1
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
// method params
|
||||
type a2w_calldata = awcp.EventData_A2W<awcp.RpcCall<string, any>>;
|
||||
|
||||
|
||||
/**
|
||||
* wrap up bs for w2a message
|
||||
*/
|
||||
function
|
||||
mk_w2a_msg_ok
|
||||
<result_t extends any>
|
||||
(method : string,
|
||||
id : string | number,
|
||||
result : result_t)
|
||||
: awcp.EventData_W2A<awcp.RpcResp_ok<string, result_t>>
|
||||
{
|
||||
return {type : "to_aepp",
|
||||
data : {jsonrpc : "2.0",
|
||||
method : method,
|
||||
id : id,
|
||||
result : result}};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handle messages from the content script
|
||||
*
|
||||
* Note to self: `sendResponse` is fake. Doesn't work. Instead just return the
|
||||
* response
|
||||
*/
|
||||
async function
|
||||
bg_a2w_handler
|
||||
(msg: any, sender: any, sendResponse: any)
|
||||
(msg: a2w_calldata, sender: any, sendResponse: any)
|
||||
: Promise<void>
|
||||
{
|
||||
console.log('msg', msg);
|
||||
console.log('sender', sender);
|
||||
console.log('sendResponse', sendResponse);
|
||||
// send them back to content script
|
||||
// @ts-ignore stahp
|
||||
//let the_sender: number = sender.tab.id;
|
||||
//browser.tabs.sendMessage(the_sender, msg);
|
||||
// @ts-ignore stahp
|
||||
//sendResponse(msg);
|
||||
//console.log('msg', msg);
|
||||
//console.log('sender', sender);
|
||||
//console.log('sendResponse', sendResponse);
|
||||
|
||||
let msg_method : string = msg.data.method;
|
||||
let msg_id : string | number = msg.data.id;
|
||||
|
||||
function w2a_ok(result_for_content_script: any) {
|
||||
return mk_w2a_msg_ok(msg_method, msg_id, result_for_content_script);
|
||||
}
|
||||
|
||||
switch (msg.data.method) {
|
||||
case "connection.open":
|
||||
return w2a_ok({id : "jr",
|
||||
name : "JR",
|
||||
networkId : "ae_uat",
|
||||
origin : "foobar",
|
||||
type : "extension"});
|
||||
case "address.subscribe":
|
||||
return w2a_ok({subscription : ["connected"],
|
||||
address : {current : {"boobs": {}},
|
||||
connected : {}}});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+30
-13
@@ -53,28 +53,44 @@ sleep
|
||||
/**
|
||||
* Relays messages from page scripts to the background script
|
||||
*/
|
||||
function
|
||||
async function
|
||||
a2w_handler
|
||||
(msg: {data: {type? : "to_aepp" | "to_waellet"}})
|
||||
{
|
||||
|
||||
//console.error('JR: a2w_handler', {msg: msg});
|
||||
function onSuccessCase(response_from_bg: any) {
|
||||
console.error('JR A2w success case', response_from_bg);
|
||||
window.postMessage(response_from_bg);
|
||||
}
|
||||
function onErrorCase(error: any) {
|
||||
console.error('JR: error from controller', error);
|
||||
}
|
||||
|
||||
// branch
|
||||
if ("to_waellet" === msg.data.type) {
|
||||
browser.runtime.sendMessage(msg.data);
|
||||
console.error('JR: WAEEEEEEE');
|
||||
browser.runtime.sendMessage(msg.data).then(
|
||||
onSuccessCase,
|
||||
onErrorCase
|
||||
);
|
||||
//console.error('BOOBS', response);
|
||||
//window.postMessage(response);
|
||||
}
|
||||
// otherwise ignore
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Relays messages from background scripts to the page script
|
||||
*/
|
||||
function
|
||||
w2a_handler
|
||||
(msg: any)
|
||||
{
|
||||
window.postMessage(msg);
|
||||
}
|
||||
///**
|
||||
// * Relays messages from background scripts to the page script
|
||||
// */
|
||||
//function
|
||||
//w2a_handler
|
||||
// (msg: any)
|
||||
//{
|
||||
// window.postMessage(msg);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
@@ -85,11 +101,12 @@ async function
|
||||
jr_content_main
|
||||
()
|
||||
{
|
||||
|
||||
// relay page messages back to the controller
|
||||
window.addEventListener('message', a2w_handler);
|
||||
|
||||
// relay controller messages back to page
|
||||
browser.runtime.onMessage.addListener(w2a_handler);
|
||||
//// relay controller messages back to page
|
||||
//browser.runtime.onMessage.addListener(w2a_handler);
|
||||
|
||||
// spam detect
|
||||
spam_detect();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user