move logic into background.js

This commit is contained in:
Kevin Gibbons 2023-02-11 16:42:57 -08:00
parent 16a52bfdc7
commit ce827efb05
2 changed files with 11 additions and 12 deletions

View File

@ -87,10 +87,16 @@ async function getCookieState() {
// send ping to server, return response
async function verifyConnection() {
const path = 'api/ping/';
let response = await sendGet(path);
console.log('verify connection: ' + JSON.stringify(response));
let message = await sendGet(path);
console.log('verify connection: ' + JSON.stringify(message));
return response;
if (message?.response === 'pong') {
return true;
} else if (message?.detail) {
throw new Error(message.detail);
} else {
throw new Error(`got unknown message ${JSON.stringify(message)}`);
}
}
// send youtube link from injected buttons

View File

@ -103,15 +103,8 @@ function sendCookie() {
function pingBackend() {
clearError();
function handleResponse(message) {
// TODO move this check into background.js
if (message?.response === 'pong') {
setStatusIcon(true);
console.log('connection validated');
} else if (message?.detail) {
handleError(message.detail);
} else {
handleError(`got unknown message ${JSON.stringify(message)}`);
}
console.log('connection validated');
setStatusIcon(true);
}
function handleError(error) {