86 lines
2.6 KiB
JavaScript
86 lines
2.6 KiB
JavaScript
/**
|
|
* Script to build the background script for the extension
|
|
*/
|
|
const { build } = require('esbuild');
|
|
const { resolve } = require('path');
|
|
const fs = require('fs');
|
|
|
|
async function buildBackground() {
|
|
try {
|
|
console.log('Building background script...');
|
|
|
|
// First, create a simplified background script that doesn't import WASM
|
|
const backgroundContent = `
|
|
// Background Service Worker for SAL Modular Cryptographic Extension
|
|
// This is a simplified version that only handles messaging
|
|
|
|
console.log('Background script initialized');
|
|
|
|
// Store active WebSocket connection
|
|
let activeWebSocket = null;
|
|
let sessionActive = false;
|
|
|
|
// Listen for messages from popup or content scripts
|
|
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
console.log('Background received message:', message.type);
|
|
|
|
if (message.type === 'SESSION_STATUS') {
|
|
sendResponse({ active: sessionActive });
|
|
return true;
|
|
}
|
|
|
|
if (message.type === 'SESSION_UNLOCK') {
|
|
sessionActive = true;
|
|
sendResponse({ success: true });
|
|
return true;
|
|
}
|
|
|
|
if (message.type === 'SESSION_LOCK') {
|
|
sessionActive = false;
|
|
if (activeWebSocket) {
|
|
activeWebSocket.close();
|
|
activeWebSocket = null;
|
|
}
|
|
sendResponse({ success: true });
|
|
return true;
|
|
}
|
|
|
|
if (message.type === 'CONNECT_WEBSOCKET') {
|
|
// Simplified WebSocket handling
|
|
sendResponse({ success: true });
|
|
return true;
|
|
}
|
|
|
|
if (message.type === 'DISCONNECT_WEBSOCKET') {
|
|
if (activeWebSocket) {
|
|
activeWebSocket.close();
|
|
activeWebSocket = null;
|
|
sendResponse({ success: true });
|
|
} else {
|
|
sendResponse({ success: false, error: 'No active WebSocket connection' });
|
|
}
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
});
|
|
|
|
// Initialize notification setup
|
|
chrome.notifications.onClicked.addListener((notificationId) => {
|
|
// Open the extension popup when a notification is clicked
|
|
chrome.action.openPopup();
|
|
});
|
|
`;
|
|
|
|
// Write the simplified background script to a temporary file
|
|
fs.writeFileSync(resolve(__dirname, '../dist/background.js'), backgroundContent);
|
|
|
|
console.log('Background script built successfully!');
|
|
} catch (error) {
|
|
console.error('Error building background script:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
buildBackground();
|