feat:项目打包成Electron
This commit is contained in:
@@ -6,6 +6,18 @@
|
||||
import { useCallback, useRef, useState } from "react";
|
||||
import { useI18n } from "../../lib/i18n";
|
||||
|
||||
// Electron API 类型
|
||||
interface ElectronAPI {
|
||||
requestMicAccess: () => Promise<boolean>;
|
||||
isElectron: boolean;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
electronAPI?: ElectronAPI;
|
||||
}
|
||||
}
|
||||
|
||||
export function useMicrophone() {
|
||||
const { t } = useI18n();
|
||||
const [stream, setStream] = useState<MediaStream | null>(null);
|
||||
@@ -14,6 +26,17 @@ export function useMicrophone() {
|
||||
|
||||
const startMic = useCallback(async () => {
|
||||
try {
|
||||
// Electron 环境:先通过 IPC 请求系统级权限
|
||||
if (window.electronAPI?.isElectron) {
|
||||
const granted = await window.electronAPI.requestMicAccess();
|
||||
if (!granted) {
|
||||
const msg = t("error.micAccess");
|
||||
setError(msg);
|
||||
console.warn("[Mic] macOS 系统麦克风权限被拒绝");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const mediaStream = await navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
sampleRate: 16000,
|
||||
|
||||
Reference in New Issue
Block a user