feat:项目打包成Electron

This commit is contained in:
2026-06-14 18:10:58 +08:00
parent 7a0443ebcc
commit 8970b63800
20 changed files with 3895 additions and 11 deletions

View File

@@ -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,