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(settings): show whether the browser has granted microphone access

Luis Ortizc67304449564
diff --git a/src/locales/de.yml b/src/locales/de.yml
index 5f84c21..4c3779e 100644
--- a/src/locales/de.yml
+++ b/src/locales/de.yml
@@ -112,10 +112,14 @@ settings:
microphoneGrantAccess: Mikrofonzugriff erlauben
microphoneNone: Kein Mikrofon gefunden. Schließe eines an, dann erscheint es hier.
microphoneUnavailable: Nicht verfügbares Mikrofon
+ microphoneStatusAllowed: Erlaubt
+ microphoneStatusBlocked: Blockiert
+ microphoneStatusPending: Noch nicht erlaubt
+ microphoneBlocked: Dein Browser blockiert das Mikrofon für Mimik. Öffne die Website-Einstellungen über das Symbol links in der Adressleiste und setze Mikrofon auf Zulassen.
+ microphoneUnblockHow: Wie hebe ich die Blockierung auf?
microphoneMissing: Das gewählte Mikrofon ist gerade nicht verfügbar, daher nutzt Mimik den Systemstandard.
microphoneTest: Mikrofon testen
microphoneTestStop: Test beenden
- microphoneTestHint: "Probleme mit dem Mikrofon? Starte einen Test und sag etwas, um zu prüfen, ob es funktioniert."
microphoneTestFailed: Dieses Mikrofon konnte nicht geöffnet werden. Wähle ein anderes und versuche es erneut.
saveSettings: Einstellungen speichern
saved: Gespeichert
diff --git a/src/locales/en.yml b/src/locales/en.yml
index f38167f..330dd76 100644
--- a/src/locales/en.yml
+++ b/src/locales/en.yml
@@ -100,8 +100,12 @@ settings:
microphoneUnavailable: Unavailable microphone
microphoneMissing: The microphone you picked is not available right now, so Mimik will use the system default.
microphoneTest: Test microphone
+ microphoneStatusAllowed: Allowed
+ microphoneStatusBlocked: Blocked
+ microphoneStatusPending: Not allowed yet
+ microphoneBlocked: Your browser is blocking the microphone for Mimik. Open the site settings from the icon at the left of the address bar and set Microphone to Allow.
+ microphoneUnblockHow: How do I unblock it?
microphoneTestStop: Stop test
- microphoneTestHint: "Having mic issues? Start a test and say something to check that your microphone is working."
microphoneTestFailed: That microphone could not be opened. Pick another one and try again.
targetColor: "Brand colour"
targetColorHint: "Click highlights and export accents"
diff --git a/src/locales/es.yml b/src/locales/es.yml
index bbfaa04..fa00fad 100644
--- a/src/locales/es.yml
+++ b/src/locales/es.yml
@@ -100,8 +100,12 @@ settings:
microphoneUnavailable: "Micrófono no disponible"
microphoneMissing: "El micrófono que elegiste no está disponible ahora mismo, así que Mimik usará el predeterminado del sistema."
microphoneTest: "Probar micrófono"
+ microphoneStatusAllowed: Permitido
+ microphoneStatusBlocked: Bloqueado
+ microphoneStatusPending: Aún sin permiso
+ microphoneBlocked: Tu navegador está bloqueando el micrófono para Mimik. Abre la configuración del sitio desde el icono a la izquierda de la barra de direcciones y pon Micrófono en Permitir.
+ microphoneUnblockHow: ¿Cómo lo desbloqueo?
microphoneTestStop: Detener prueba
- microphoneTestHint: "¿Problemas con el micro? Empieza una prueba y di algo para comprobar que funciona."
microphoneTestFailed: "No se pudo abrir ese micrófono. Elige otro e inténtalo de nuevo."
targetColor: "Color de marca"
targetColorHint: "Resaltados de clic y acentos de exportación"
diff --git a/src/locales/fr.yml b/src/locales/fr.yml
index 678b20b..e3a2a9d 100644
--- a/src/locales/fr.yml
+++ b/src/locales/fr.yml
@@ -100,8 +100,12 @@ settings:
microphoneUnavailable: "Micro indisponible"
microphoneMissing: "Le micro que vous avez choisi n'est pas disponible pour le moment : Mimik utilisera celui par défaut du système."
microphoneTest: "Tester le micro"
+ microphoneStatusAllowed: Autorisé
+ microphoneStatusBlocked: Bloqué
+ microphoneStatusPending: Pas encore autorisé
+ microphoneBlocked: Votre navigateur bloque le micro pour Mimik. Ouvrez les paramètres du site depuis l'icône à gauche de la barre d'adresse et réglez Microphone sur Autoriser.
+ microphoneUnblockHow: Comment le débloquer ?
microphoneTestStop: "Arrêter le test"
- microphoneTestHint: "Un souci de micro ? Lancez un test et dites quelque chose pour vérifier qu'il fonctionne."
microphoneTestFailed: "Ce micro n'a pas pu être ouvert. Choisissez-en un autre et réessayez."
targetColor: "Couleur de marque"
targetColorHint: "Surbrillance des clics et accents des exports"
diff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.yml
index 7a204b6..22b6a1c 100644
--- a/src/locales/pt-BR.yml
+++ b/src/locales/pt-BR.yml
@@ -100,8 +100,12 @@ settings:
microphoneUnavailable: "Microfone indisponível"
microphoneMissing: "O microfone que você escolheu não está disponível agora, então o Mimik vai usar o padrão do sistema."
microphoneTest: Testar microfone
+ microphoneStatusAllowed: Permitido
+ microphoneStatusBlocked: Bloqueado
+ microphoneStatusPending: Ainda sem permissão
+ microphoneBlocked: Seu navegador está bloqueando o microfone pro Mimik. Abre as configurações do site pelo ícone à esquerda da barra de endereço e deixa Microfone como Permitir.
+ microphoneUnblockHow: Como desbloquear?
microphoneTestStop: Parar teste
- microphoneTestHint: "Problema com o microfone? Inicia um teste e fala alguma coisa pra ver se ele tá funcionando."
microphoneTestFailed: "Não deu pra abrir esse microfone. Escolhe outro e tenta de novo."
targetColor: "Cor da marca"
targetColorHint: "Destaques de clique e acentos da exportação"
diff --git a/src/ui/shared/MicrophonePicker.tsx b/src/ui/shared/MicrophonePicker.tsx
index 5e360b3..b5589da 100644
--- a/src/ui/shared/MicrophonePicker.tsx
+++ b/src/ui/shared/MicrophonePicker.tsx
@@ -1,4 +1,4 @@
-import { Mic, Square, TriangleAlert } from 'lucide-react';
+import { Check, ChevronRight, Mic, MicOff, Square, TriangleAlert } from 'lucide-react';
import { useCallback, useEffect, useId, useRef, useState } from 'react';
import { i18n } from '#imports';
import { getActiveTab } from '@/lib/browser-api';
@@ -8,7 +8,10 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
import {
isMicrophoneMissing,
type MicrophoneDevice,
+ type MicrophonePermission,
+ type MicrophoneStatus,
microphoneListState,
+ microphoneStatus,
nextMicLevel,
SPEAKING_LEVEL,
SYSTEM_DEFAULT_VALUE,
@@ -32,11 +35,36 @@ const MICROPHONE: PermissionDescriptor = { name: 'microphone' as PermissionName
const ANALYSER_FFT_SIZE = 2048;
const METER_INTERVAL_MS = 80;
+const STATUS_STYLES: Record<MicrophoneStatus, string> = {
+ allowed: 'bg-success/10 text-success',
+ blocked: 'bg-destructive/10 text-destructive',
+ pending: 'bg-secondary text-muted-foreground',
+};
+
+const STATUS_LABELS: Record<MicrophoneStatus, string> = {
+ allowed: 'settings.microphoneStatusAllowed',
+ blocked: 'settings.microphoneStatusBlocked',
+ pending: 'settings.microphoneStatusPending',
+};
+
+function StatusBadge({ status }: { status: MicrophoneStatus }) {
+ const Icon = status === 'allowed' ? Check : status === 'blocked' ? MicOff : Mic;
+ return (
+ <span
+ className={`inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[9px] font-semibold ${STATUS_STYLES[status]}`}
+ >
+ <Icon size={9} />
+ {i18n.t(STATUS_LABELS[status])}
+ </span>
+ );
+}
+
export default function MicrophonePicker({ value, onChange }: MicrophonePickerProps) {
const [devices, setDevices] = useState<MicrophoneDevice[]>([]);
const [testing, setTesting] = useState(false);
const [level, setLevel] = useState(0);
const [testFailed, setTestFailed] = useState(false);
+ const [permission, setPermission] = useState<MicrophonePermission>('unknown');
const test = useRef<MicTest | null>(null);
const triggerId = useId();
@@ -67,18 +95,23 @@ export default function MicrophonePicker({ value, onChange }: MicrophonePickerPr
document.addEventListener('visibilitychange', onVisible);
let status: PermissionStatus | undefined;
+ const onPermission = () => {
+ setPermission(status?.state ?? 'unknown');
+ void refresh();
+ };
navigator.permissions
?.query(MICROPHONE)
.then((result) => {
status = result;
- result.addEventListener('change', refresh);
+ setPermission(result.state);
+ result.addEventListener('change', onPermission);
})
.catch(() => undefined);
return () => {
media?.removeEventListener('devicechange', refresh);
document.removeEventListener('visibilitychange', onVisible);
- status?.removeEventListener('change', refresh);
+ status?.removeEventListener('change', onPermission);
};
}, [refresh]);
@@ -128,38 +161,56 @@ export default function MicrophonePicker({ value, onChange }: MicrophonePickerPr
const state = microphoneListState(devices);
const options = toMicrophoneOptions(devices);
const missing = isMicrophoneMissing(value, options);
+ const status = microphoneStatus(permission, state);
+ const blocked = status === 'blocked';
return (
<div>
- <label
- htmlFor={state === 'ready' ? triggerId : undefined}
- className="block text-[11px] font-semibold text-foreground mb-1"
- >
- {i18n.t('settings.microphone')}
- </label>
-
- {state === 'no-devices' && (
+ <div className="flex items-center justify-between gap-2 mb-1">
+ <label
+ htmlFor={state === 'ready' ? triggerId : undefined}
+ className="text-[11px] font-semibold text-foreground"
+ >
+ {i18n.t('settings.microphone')}
+ </label>
+ <StatusBadge status={status} />
+ </div>
+
+ {state === 'no-devices' && !blocked && (
<p className="text-[10px] text-muted-foreground leading-relaxed">{i18n.t('settings.microphoneNone')}</p>
)}
- {state === 'unlabelled' && (
+ {(state === 'unlabelled' || blocked) && (
<div className="space-y-2">
- <p className="text-[10px] text-muted-foreground leading-relaxed">
- {i18n.t('settings.microphoneNeedsAccess')}
- </p>
+ {!blocked && (
+ <p className="text-[10px] text-muted-foreground leading-relaxed">
+ {i18n.t('settings.microphoneNeedsAccess')}
+ </p>
+ )}
<Button
variant="outline"
size="sm"
onClick={() => void requestAccess()}
- className="w-full text-[11px] font-semibold"
+ className="w-full rounded-lg bg-card text-[11px] font-semibold"
>
<Mic size={12} />
- {i18n.t('settings.microphoneGrantAccess')}
+ {i18n.t(blocked ? 'micPermission.retry' : 'settings.microphoneGrantAccess')}
</Button>
+ {blocked && (
+ <details className="group">
+ <summary className="flex items-center gap-1 text-[10px] font-semibold text-accent cursor-pointer list-none">
+ <ChevronRight size={10} className="transition-transform group-open:rotate-90" />
+ {i18n.t('settings.microphoneUnblockHow')}
+ </summary>
+ <p className="mt-1.5 text-[10px] text-muted-foreground leading-relaxed">
+ {i18n.t('settings.microphoneBlocked')}
+ </p>
+ </details>
+ )}
</div>
)}
- {state === 'ready' && (
+ {state === 'ready' && !blocked && (
<div className="space-y-2">
<Select
value={toSelectValue(value)}
@@ -199,13 +250,13 @@ export default function MicrophonePicker({ value, onChange }: MicrophonePickerPr
variant="outline"
size="sm"
onClick={() => (testing ? stopTest() : void startTest())}
- className="w-full text-[11px] font-semibold"
+ className="w-full rounded-lg bg-card text-[11px] font-semibold"
>
{testing ? <Square size={11} /> : <Mic size={11} />}
{i18n.t(testing ? 'settings.microphoneTestStop' : 'settings.microphoneTest')}
</Button>
- {testing ? (
+ {testing && (
<div className="space-y-1">
<div aria-hidden="true" className="h-1.5 w-full rounded-full bg-secondary overflow-hidden">
<div
@@ -217,8 +268,6 @@ export default function MicrophonePicker({ value, onChange }: MicrophonePickerPr
{i18n.t(level > SPEAKING_LEVEL ? 'voice.micHearing' : 'voice.micQuiet')}
</p>
</div>
- ) : (
- <p className="text-[10px] text-muted-foreground leading-relaxed">{i18n.t('settings.microphoneTestHint')}</p>
)}
{testFailed && (
diff --git a/src/ui/shared/__tests__/microphones.test.ts b/src/ui/shared/__tests__/microphones.test.ts
index 198fa94..0b8a1e7 100644
--- a/src/ui/shared/__tests__/microphones.test.ts
+++ b/src/ui/shared/__tests__/microphones.test.ts
@@ -5,6 +5,7 @@ import {
isMicrophoneMissing,
type MicrophoneOption,
microphoneListState,
+ microphoneStatus,
nextMicLevel,
SPEAKING_LEVEL,
SYSTEM_DEFAULT_VALUE,
@@ -13,7 +14,7 @@ import {
toStoredMicrophoneId,
} from '../microphones';
-const LOCALES = ['en', 'es', 'fr', 'pt-BR'];
+const LOCALES = ['en', 'de', 'es', 'fr', 'pt-BR'];
const MICROPHONE_KEYS = [
'settings.microphone',
@@ -25,8 +26,13 @@ const MICROPHONE_KEYS = [
'settings.microphoneMissing',
'settings.microphoneTest',
'settings.microphoneTestStop',
- 'settings.microphoneTestHint',
'settings.microphoneTestFailed',
+ 'settings.microphoneUnblockHow',
+ 'settings.microphoneStatusAllowed',
+ 'settings.microphoneStatusBlocked',
+ 'settings.microphoneStatusPending',
+ 'settings.microphoneBlocked',
+ 'micPermission.retry',
'voice.micHearing',
'voice.micQuiet',
];
@@ -119,6 +125,26 @@ describe('microphoneListState', () => {
});
});
+describe('microphoneStatus', () => {
+ it('separates a blocked microphone from one that was never asked for', () => {
+ expect(microphoneStatus('denied', 'unlabelled')).toBe('blocked');
+ expect(microphoneStatus('prompt', 'unlabelled')).toBe('pending');
+ });
+
+ it('reports blocked even when no device is plugged in', () => {
+ expect(microphoneStatus('denied', 'no-devices')).toBe('blocked');
+ });
+
+ it('reports allowed once the browser grants access', () => {
+ expect(microphoneStatus('granted', 'unlabelled')).toBe('allowed');
+ });
+
+ it('falls back to the device labels when permissions cannot be queried', () => {
+ expect(microphoneStatus('unknown', 'ready')).toBe('allowed');
+ expect(microphoneStatus('unknown', 'unlabelled')).toBe('pending');
+ });
+});
+
describe('select value round trip', () => {
it('shows the system default option for the empty stored id', () => {
expect(toSelectValue('')).toBe(SYSTEM_DEFAULT_VALUE);
diff --git a/src/ui/shared/microphones.ts b/src/ui/shared/microphones.ts
index 0e5351f..ba3dc18 100644
--- a/src/ui/shared/microphones.ts
+++ b/src/ui/shared/microphones.ts
@@ -34,6 +34,16 @@ export function microphoneListState(devices: readonly MicrophoneDevice[]): Micro
return withheld ? 'unlabelled' : 'ready';
}
+export type MicrophonePermission = PermissionState | 'unknown';
+
+export type MicrophoneStatus = 'allowed' | 'blocked' | 'pending';
+
+export function microphoneStatus(permission: MicrophonePermission, list: MicrophoneListState): MicrophoneStatus {
+ if (permission === 'denied') return 'blocked';
+ if (permission === 'granted' || list === 'ready') return 'allowed';
+ return 'pending';
+}
+
export function toSelectValue(storedId: string): string {
return storedId.trim() || SYSTEM_DEFAULT_VALUE;
}