Auto-deploy: 2026-06-02 18:02:41

This commit is contained in:
Hamza-Ayed
2026-06-02 18:02:41 +03:00
parent d5919fbf01
commit 36e4dd42e4
5 changed files with 212 additions and 97 deletions

View File

@@ -4,7 +4,27 @@
const GEMINI_MODEL = 'gemini-flash-lite-latest';
const GEMINI_URL = `https://generativelanguage.googleapis.com/v1beta/models/${GEMINI_MODEL}:generateContent`;
// ─── Message listener ────────────────────────────────────────────────────────
// ─── Offscreen Document Management ───────────────────────────────────────────
let recordingTabId = null;
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',
});
}
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'GEMINI_REQUEST') {
@@ -20,6 +40,38 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
.catch(err => sendResponse({ success: false, error: err.message }));
return true; // Keep message channel open for async
}
// --- Offscreen Document Relays ---
if (message.type === 'START_RECORDING_FROM_CONTENT') {
recordingTabId = sender.tab ? sender.tab.id : null;
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_CONTENT') {
chrome.runtime.sendMessage({ type: 'STOP_RECORDING' }, (response) => {
sendResponse(response || { success: true });
});
return true;
}
if (message.type.startsWith('OFFSCREEN_RECORDING_')) {
if (recordingTabId) {
chrome.tabs.sendMessage(recordingTabId, message).catch(() => {});
}
}
});
// ─── Core API call ───────────────────────────────────────────────────────────