mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2025-04-20 18:20:12 +00:00
move logic into background.js
This commit is contained in:
parent
16a52bfdc7
commit
ce827efb05
@ -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
|
||||
|
@ -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)}`);
|
||||
}
|
||||
setStatusIcon(true);
|
||||
}
|
||||
|
||||
function handleError(error) {
|
||||
|
Loading…
Reference in New Issue
Block a user