Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots 📖

feat(voice): add the one-shot microphone permission page

Luis Ortiz77a4a046cbb0
diff --git a/src/entrypoints/mic-permission/index.html b/src/entrypoints/mic-permission/index.html
new file mode 100644
index 0000000..1e3697e
--- /dev/null
+++ b/src/entrypoints/mic-permission/index.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <meta name="wxt.exclude" content="['firefox']" />
+ <title>Mimik Microphone Access</title>
+ </head>
+ <body>
+ <div id="root"></div>
+ <script type="module" src="./index.tsx"></script>
+ </body>
+</html>
diff --git a/src/entrypoints/mic-permission/index.tsx b/src/entrypoints/mic-permission/index.tsx
new file mode 100644
index 0000000..626f7eb
--- /dev/null
+++ b/src/entrypoints/mic-permission/index.tsx
@@ -0,0 +1,5 @@
+import ReactDOM from 'react-dom/client';
+import MicPermissionApp from '@/ui/mic-permission/App';
+import '@/ui/global.css';
+
+ReactDOM.createRoot(document.getElementById('root')!).render(<MicPermissionApp />);
diff --git a/src/locales/en.yml b/src/locales/en.yml
index efc7d6f..834f92a 100644
--- a/src/locales/en.yml
+++ b/src/locales/en.yml
@@ -231,3 +231,14 @@ export:
background:
guideOnDomain: "Guide on $1"
newGuide: New Guide
+
+micPermission:
+ title: Allow microphone access
+ checkingMessage: Checking whether Mimik already has microphone access...
+ promptingMessage: Your browser is asking for permission. Choose Allow so Mimik can record your narration while you capture a guide. This tab closes on its own.
+ grantedTitle: Microphone ready
+ grantedMessage: Taking you back to what you were doing.
+ deniedTitle: Microphone access is blocked
+ deniedMessage: Your browser is blocking the microphone for Mimik, so voice narration cannot record. Open the site settings from the icon at the left of the address bar, set Microphone to Allow, then try again. Capturing guides keeps working without it.
+ retry: Try again
+ privacy: Audio is held in memory only while you record and is sent to the transcription provider you configured. Mimik never stores it.
diff --git a/src/locales/es.yml b/src/locales/es.yml
index 4291d45..a71883f 100644
--- a/src/locales/es.yml
+++ b/src/locales/es.yml
@@ -231,3 +231,14 @@ export:
background:
guideOnDomain: "Guía en $1"
newGuide: Nueva guía
+
+micPermission:
+ title: Permitir acceso al micrófono
+ checkingMessage: Comprobando si Mimik ya tiene acceso al micrófono...
+ promptingMessage: Tu navegador está pidiendo permiso. Elige Permitir para que Mimik pueda grabar tu narración mientras capturas una guía. Esta pestaña se cierra sola.
+ grantedTitle: Micrófono listo
+ grantedMessage: Te devolvemos a lo que estabas haciendo.
+ deniedTitle: El acceso al micrófono está bloqueado
+ deniedMessage: Tu navegador está bloqueando el micrófono para Mimik, así que la narración por voz no puede grabar. Abre la configuración del sitio desde el icono a la izquierda de la barra de direcciones, pon Micrófono en Permitir y vuelve a intentarlo. Capturar guías sigue funcionando sin esto.
+ retry: Intentar de nuevo
+ privacy: El audio solo se guarda en memoria mientras grabas y se envía al proveedor de transcripción que hayas configurado. Mimik nunca lo almacena.
diff --git a/src/locales/fr.yml b/src/locales/fr.yml
index 84760b5..de105cd 100644
--- a/src/locales/fr.yml
+++ b/src/locales/fr.yml
@@ -231,3 +231,14 @@ export:
background:
guideOnDomain: "Guide sur $1"
newGuide: Nouveau guide
+
+micPermission:
+ title: Autoriser l'accès au microphone
+ checkingMessage: Vérification de l'accès au microphone de Mimik...
+ promptingMessage: Votre navigateur demande une autorisation. Choisissez Autoriser pour que Mimik puisse enregistrer votre narration pendant la capture d'un guide. Cet onglet se ferme tout seul.
+ grantedTitle: Microphone prêt
+ grantedMessage: Retour à ce que vous étiez en train de faire.
+ deniedTitle: L'accès au microphone est bloqué
+ deniedMessage: Votre navigateur bloque le microphone pour Mimik, la narration vocale ne peut donc pas enregistrer. Ouvrez les paramètres du site depuis l'icône à gauche de la barre d'adresse, réglez Microphone sur Autoriser, puis réessayez. La capture de guides continue de fonctionner sans cela.
+ retry: Réessayer
+ privacy: L'audio reste en mémoire pendant l'enregistrement et n'est envoyé qu'au service de transcription que vous avez configuré. Mimik ne le conserve jamais.
diff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.yml
index 128b480..af04154 100644
--- a/src/locales/pt-BR.yml
+++ b/src/locales/pt-BR.yml
@@ -231,3 +231,14 @@ export:
background:
guideOnDomain: "Guia em $1"
newGuide: Novo guia
+
+micPermission:
+ title: Permitir acesso ao microfone
+ checkingMessage: Verificando se o Mimik já tem acesso ao microfone...
+ promptingMessage: Seu navegador está pedindo permissão. Escolha Permitir para que o Mimik possa gravar sua narração enquanto você captura um guia. Esta aba se fecha sozinha.
+ grantedTitle: Microfone pronto
+ grantedMessage: Levando você de volta ao que estava fazendo.
+ deniedTitle: O acesso ao microfone está bloqueado
+ deniedMessage: Seu navegador está bloqueando o microfone para o Mimik, então a narração por voz não pode gravar. Abra as configurações do site pelo ícone à esquerda da barra de endereços, defina Microfone como Permitir e tente de novo. Capturar guias continua funcionando sem isso.
+ retry: Tentar de novo
+ privacy: O áudio fica apenas na memória enquanto você grava e é enviado ao provedor de transcrição que você configurou. O Mimik nunca o armazena.
diff --git a/src/ui/mic-permission/App.tsx b/src/ui/mic-permission/App.tsx
new file mode 100644
index 0000000..4b7f3c7
--- /dev/null
+++ b/src/ui/mic-permission/App.tsx
@@ -0,0 +1,180 @@
+import { Check, Mic, MicOff } from 'lucide-react';
+import { useCallback, useEffect, useRef, useState } from 'react';
+import { browser, i18n } from '#imports';
+import {
+ VOICE_BACKGROUND_TARGET,
+ VoiceMessage,
+ type VoicePermissionResultEvent,
+ type VoicePermissionState,
+ voiceMessage,
+} from '@/lib/voice-messages';
+
+type Phase = 'checking' | 'prompting' | 'granted' | 'denied';
+
+const MICROPHONE: PermissionDescriptor = { name: 'microphone' as PermissionName };
+
+async function queryState(): Promise<VoicePermissionState> {
+ try {
+ const status = await navigator.permissions.query(MICROPHONE);
+ return status.state as VoicePermissionState;
+ } catch {
+ return 'unknown';
+ }
+}
+
+async function requestMicrophone(): Promise<boolean> {
+ try {
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
+ for (const track of stream.getTracks()) track.stop();
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+function report(state: 'granted' | 'denied'): void {
+ const event = voiceMessage<VoicePermissionResultEvent>({
+ type: VoiceMessage.VOICE_PERMISSION_RESULT,
+ target: VOICE_BACKGROUND_TARGET,
+ state,
+ });
+ browser.runtime.sendMessage(event).catch(() => undefined);
+}
+
+function openerTabId(): number | null {
+ const raw = new URLSearchParams(window.location.search).get('tabId');
+ const id = raw === null ? Number.NaN : Number(raw);
+ return Number.isInteger(id) && id >= 0 ? id : null;
+}
+
+async function returnToOpener(): Promise<void> {
+ const tabId = openerTabId();
+ if (tabId !== null) await browser.tabs.update(tabId, { active: true }).catch(() => undefined);
+ const self = await browser.tabs.getCurrent().catch(() => undefined);
+ if (self?.id !== undefined) await browser.tabs.remove(self.id).catch(() => undefined);
+ else window.close();
+}
+
+export default function MicPermissionApp() {
+ const [phase, setPhase] = useState<Phase>('checking');
+ const settled = useRef(false);
+ const reportedDenied = useRef(false);
+
+ const deny = useCallback(() => {
+ setPhase('denied');
+ if (reportedDenied.current) return;
+ reportedDenied.current = true;
+ report('denied');
+ }, []);
+
+ const grant = useCallback(() => {
+ settled.current = true;
+ setPhase('granted');
+ report('granted');
+ void returnToOpener();
+ }, []);
+
+ const evaluate = useCallback(
+ async (allowPrompt: boolean) => {
+ if (settled.current) return;
+ const state = await queryState();
+ if (state === 'granted') {
+ grant();
+ return;
+ }
+ if (state === 'denied') {
+ deny();
+ return;
+ }
+ if (!allowPrompt) return;
+ setPhase('prompting');
+ if (await requestMicrophone()) grant();
+ else deny();
+ },
+ [deny, grant],
+ );
+
+ useEffect(() => {
+ void evaluate(true);
+ }, [evaluate]);
+
+ useEffect(() => {
+ const onVisibility = () => {
+ if (document.visibilityState === 'visible') void evaluate(false);
+ };
+ document.addEventListener('visibilitychange', onVisibility);
+ return () => document.removeEventListener('visibilitychange', onVisibility);
+ }, [evaluate]);
+
+ useEffect(() => {
+ let status: PermissionStatus | undefined;
+ const onChange = () => {
+ void evaluate(false);
+ };
+ navigator.permissions
+ .query(MICROPHONE)
+ .then((result) => {
+ status = result;
+ result.addEventListener('change', onChange);
+ })
+ .catch(() => undefined);
+ return () => status?.removeEventListener('change', onChange);
+ }, [evaluate]);
+
+ const denied = phase === 'denied';
+ const granted = phase === 'granted';
+ const Icon = denied ? MicOff : granted ? Check : Mic;
+
+ return (
+ <div className="min-h-screen bg-card text-foreground flex items-center justify-center px-6">
+ <div className="w-full max-w-md text-center">
+ <div
+ className={`w-16 h-16 rounded-2xl flex items-center justify-center mx-auto mb-6 ${
+ denied ? 'bg-destructive/10 text-destructive' : 'bg-secondary text-accent'
+ }`}
+ >
+ <Icon size={28} strokeWidth={2} />
+ </div>
+
+ <h1 className="text-2xl font-extrabold leading-tight tracking-tight mb-2">
+ {i18n.t(
+ denied ? 'micPermission.deniedTitle' : granted ? 'micPermission.grantedTitle' : 'micPermission.title',
+ )}
+ </h1>
+
+ <p className="text-sm text-muted-foreground leading-relaxed mb-8">
+ {i18n.t(
+ denied
+ ? 'micPermission.deniedMessage'
+ : granted
+ ? 'micPermission.grantedMessage'
+ : phase === 'checking'
+ ? 'micPermission.checkingMessage'
+ : 'micPermission.promptingMessage',
+ )}
+ </p>
+
+ {denied && (
+ <div className="flex items-center justify-center gap-3">
+ <button
+ onClick={() => void evaluate(true)}
+ className="px-7 py-3 bg-accent text-white rounded-xl font-semibold text-sm hover:bg-accent/90 transition-colors"
+ >
+ {i18n.t('micPermission.retry')}
+ </button>
+ <button
+ onClick={() => void returnToOpener()}
+ className="px-6 py-3 text-muted-foreground rounded-xl font-semibold text-sm hover:text-foreground transition-colors"
+ >
+ {i18n.t('common.close')}
+ </button>
+ </div>
+ )}
+
+ <p className="text-xs text-muted-foreground/80 leading-relaxed mt-10 border-t border-border pt-6">
+ {i18n.t('micPermission.privacy')}
+ </p>
+ </div>
+ </div>
+ );
+}