committing because switching branches

This commit is contained in:
2023-07-18 14:48:23 -06:00
parent 19203cc003
commit ff8670d592
5 changed files with 1504 additions and 24 deletions
+12
View File
@@ -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
View File
@@ -9,5 +9,5 @@
"browser_action" : {"default_icon" : "art/jrx-icon-32.png", "browser_action" : {"default_icon" : "art/jrx-icon-32.png",
"default_title" : "Jæck Russell", "default_title" : "Jæck Russell",
"default_popup" : "popup.html"}, "default_popup" : "popup.html"},
"background" : {"scripts": ["dist/background.js"]}, "background" : {"page" : "background.html"},
"permissions" : ["storage"]} "permissions" : ["storage"]}
+75 -10
View File
@@ -8,24 +8,89 @@
* @module * @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 * Handle messages from the content script
*
* Note to self: `sendResponse` is fake. Doesn't work. Instead just return the
* response
*/ */
async function async function
bg_a2w_handler bg_a2w_handler
(msg: any, sender: any, sendResponse: any) (msg: a2w_calldata, sender: any, sendResponse: any)
: Promise<void> : Promise<void>
{ {
console.log('msg', msg); //console.log('msg', msg);
console.log('sender', sender); //console.log('sender', sender);
console.log('sendResponse', sendResponse); //console.log('sendResponse', sendResponse);
// send them back to content script
// @ts-ignore stahp let msg_method : string = msg.data.method;
//let the_sender: number = sender.tab.id; let msg_id : string | number = msg.data.id;
//browser.tabs.sendMessage(the_sender, msg);
// @ts-ignore stahp function w2a_ok(result_for_content_script: any) {
//sendResponse(msg); 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
View File
@@ -53,28 +53,44 @@ sleep
/** /**
* Relays messages from page scripts to the background script * Relays messages from page scripts to the background script
*/ */
function async function
a2w_handler a2w_handler
(msg: {data: {type? : "to_aepp" | "to_waellet"}}) (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 // branch
if ("to_waellet" === msg.data.type) { 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 // otherwise ignore
} }
/** ///**
* Relays messages from background scripts to the page script // * Relays messages from background scripts to the page script
*/ // */
function //function
w2a_handler //w2a_handler
(msg: any) // (msg: any)
{ //{
window.postMessage(msg); // window.postMessage(msg);
} //}
@@ -85,11 +101,12 @@ async function
jr_content_main jr_content_main
() ()
{ {
// relay page messages back to the controller // relay page messages back to the controller
window.addEventListener('message', a2w_handler); window.addEventListener('message', a2w_handler);
// relay controller messages back to page //// relay controller messages back to page
browser.runtime.onMessage.addListener(w2a_handler); //browser.runtime.onMessage.addListener(w2a_handler);
// spam detect // spam detect
spam_detect(); spam_detect();
File diff suppressed because it is too large Load Diff