Auto-deploy: 2026-06-02 18:39:04

This commit is contained in:
Hamza-Ayed
2026-06-02 18:39:04 +03:00
parent 8ebbedad83
commit 979a5bbdae
5 changed files with 186 additions and 63 deletions

View File

@@ -4,25 +4,7 @@
const GEMINI_MODEL = 'gemini-flash-lite-latest';
const GEMINI_URL = `https://generativelanguage.googleapis.com/v1beta/models/${GEMINI_MODEL}:generateContent`;
// ─── Offscreen Document Management ───────────────────────────────────────────
async function setupOffscreenDocument(path) {
const offscreenUrl = chrome.runtime.getURL(path);
const existingContexts = await chrome.runtime.getContexts({
contextTypes: ['OFFSCREEN_DOCUMENT'],
documentUrls: [offscreenUrl]
});
if (existingContexts.length > 0) {
return;
}
await chrome.offscreen.createDocument({
url: path,
reasons: ['USER_MEDIA'],
justification: 'Recording microphone input for speech recognition',
});
}
// (Offscreen document logic removed in favor of iframe approach)
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'GEMINI_REQUEST') {
@@ -43,31 +25,6 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
chrome.tabs.create({ url: chrome.runtime.getURL('permission.html') });
return true;
}
// --- Offscreen Document Relays for Popup ---
if (message.type === 'START_RECORDING_FROM_POPUP') {
setupOffscreenDocument('claude-arabic-voice/offscreen.html')
.then(() => {
chrome.runtime.sendMessage({
type: 'START_RECORDING',
payload: message.payload
}, (response) => {
sendResponse(response || { success: true });
});
})
.catch(err => {
console.error('Failed to setup offscreen doc', err);
sendResponse({ success: false, error: err.message });
});
return true;
}
if (message.type === 'STOP_RECORDING_FROM_POPUP') {
chrome.runtime.sendMessage({ type: 'STOP_RECORDING' }, (response) => {
sendResponse(response || { success: true });
});
return true;
}
});
// ─── Core API call ───────────────────────────────────────────────────────────