have page script talking to controller
This commit is contained in:
+32
-75
@@ -9,84 +9,41 @@
|
||||
*/
|
||||
|
||||
|
||||
export type {
|
||||
jr_data,
|
||||
named_keypair,
|
||||
keypair
|
||||
}
|
||||
|
||||
export {
|
||||
// top-level getters/setters
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The data structure we store
|
||||
*/
|
||||
type jr_data
|
||||
= {version : 0,
|
||||
named_keypairs : Array<named_keypair>};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This is the default {@link jr_data}.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
let jr_data_mzero = {version : 0 as 0, // yay ts type inference can't infer 0 is of type 0
|
||||
named_keypairs : []};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Every keypair has to have a name
|
||||
*/
|
||||
type named_keypair
|
||||
= {name : string}
|
||||
& keypair;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* From NaCl
|
||||
*/
|
||||
type keypair
|
||||
= {secretKey : Uint8Array,
|
||||
publicKey : Uint8Array};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the state from the system
|
||||
* Handle messages from the content script
|
||||
*/
|
||||
async function
|
||||
fetch_migrate
|
||||
()
|
||||
: Promise<jr_data>
|
||||
{
|
||||
// try to get data
|
||||
let browser_data = await browser.storage.local.get('jr');
|
||||
// test if it's there
|
||||
if (!!(browser_data.jr))
|
||||
return browser_data.jr;
|
||||
// if the data is not there
|
||||
else
|
||||
return jr_data_mzero;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Put state
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
async function
|
||||
put
|
||||
(state : jr_data)
|
||||
bg_a2w_handler
|
||||
(msg: any, sender: any, sendResponse: any)
|
||||
: Promise<void>
|
||||
{
|
||||
await browser.storage.local.set({jr: state});
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* main function for background thread
|
||||
*/
|
||||
async function
|
||||
jr_bg_main
|
||||
()
|
||||
: Promise<void>
|
||||
{
|
||||
console.log('hi');
|
||||
|
||||
// handle messages from content script
|
||||
browser.runtime.onMessage.addListener(bg_a2w_handler);
|
||||
|
||||
}
|
||||
|
||||
|
||||
jr_bg_main();
|
||||
|
||||
Reference in New Issue
Block a user