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
+75 -10
View File
@@ -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
View File
@@ -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