mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 03:33:06 +08:00
feat(electron): create recording through tray (#10526)
- added tray menu for controlling recording status - recording watcher for monitoring system audio input events
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { AppList } from './components/app-list';
|
||||
import { GlobalRecordButton } from './components/global-record-button';
|
||||
import { SavedRecordings } from './components/saved-recordings';
|
||||
|
||||
export function App() {
|
||||
@@ -6,11 +7,15 @@ export function App() {
|
||||
<div className="h-screen bg-gray-50 overflow-hidden">
|
||||
<div className="h-full p-4 flex gap-4 max-w-[1800px] mx-auto">
|
||||
<div className="flex-1 flex flex-col min-h-0">
|
||||
<h1 className="text-xl font-bold text-gray-900 mb-1">
|
||||
Running Applications
|
||||
</h1>
|
||||
<div className="flex justify-between items-center mb-1">
|
||||
<h1 className="text-xl font-bold text-gray-900">
|
||||
Running Applications
|
||||
</h1>
|
||||
<GlobalRecordButton />
|
||||
</div>
|
||||
<p className="text-sm text-gray-500 mb-2">
|
||||
Select an application to start recording its audio
|
||||
Select an application to start recording its audio, or use global
|
||||
recording for system-wide audio
|
||||
</p>
|
||||
<div className="flex-1 bg-white shadow-lg rounded-lg border border-gray-100 overflow-auto">
|
||||
<AppList />
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import { socket } from '../utils';
|
||||
|
||||
export function GlobalRecordButton() {
|
||||
const [isRecording, setIsRecording] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
function handleRecordingStatus(data: {
|
||||
recordings: Array<{ processId: number }>;
|
||||
}) {
|
||||
// Global recording uses processId -1
|
||||
setIsRecording(data.recordings.some(r => r.processId === -1));
|
||||
}
|
||||
|
||||
socket.on('apps:recording', handleRecordingStatus);
|
||||
return () => {
|
||||
socket.off('apps:recording', handleRecordingStatus);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
setIsLoading(true);
|
||||
const endpoint = isRecording ? '/api/global/stop' : '/api/global/record';
|
||||
fetch(endpoint, { method: 'POST' })
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to toggle global recording');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error toggling global recording:', error);
|
||||
})
|
||||
.finally(() => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
}, [isRecording]);
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={handleClick}
|
||||
disabled={isLoading}
|
||||
className={`
|
||||
px-4 py-2 rounded-lg font-medium text-sm
|
||||
transition-colors duration-200
|
||||
${isLoading ? 'opacity-50 cursor-not-allowed' : ''}
|
||||
${
|
||||
isRecording
|
||||
? 'bg-red-100 text-red-700 hover:bg-red-200'
|
||||
: 'bg-blue-100 text-blue-700 hover:bg-blue-200'
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
{isRecording ? (
|
||||
<>
|
||||
<div className="w-2 h-2 rounded-full bg-red-500 animate-pulse" />
|
||||
Stop Global Recording
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="w-2 h-2 rounded-full bg-blue-500" />
|
||||
Record System Audio
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -378,11 +378,12 @@ function RecordingHeader({
|
||||
transcriptionError: string | null;
|
||||
}): ReactElement {
|
||||
const [imgError, setImgError] = React.useState(false);
|
||||
const isGlobalRecording = metadata?.isGlobal;
|
||||
|
||||
return (
|
||||
<div className="flex items-start space-x-4 p-4 bg-gray-50/30">
|
||||
<div className="relative w-12 h-12 flex-shrink-0">
|
||||
{!imgError ? (
|
||||
{!imgError && !isGlobalRecording ? (
|
||||
<img
|
||||
src={`/api/recordings/${fileName}/icon.png`}
|
||||
alt={metadata?.appName || 'Unknown Application'}
|
||||
@@ -401,7 +402,12 @@ function RecordingHeader({
|
||||
<span className="text-gray-900 font-semibold text-base truncate">
|
||||
{metadata?.appName || 'Unknown Application'}
|
||||
</span>
|
||||
<span className="text-xs px-2 py-0.5 bg-blue-50 rounded-full text-blue-600 font-medium border border-blue-100">
|
||||
{isGlobalRecording && (
|
||||
<span className="text-xs px-2 py-0.5 bg-blue-50 rounded-full text-blue-600 font-medium border border-blue-100">
|
||||
System Audio
|
||||
</span>
|
||||
)}
|
||||
<span className="text-xs px-2 py-0.5 bg-gray-50 rounded-full text-gray-600 font-medium border border-gray-100">
|
||||
{duration}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -17,6 +17,8 @@ export interface RecordingStatus {
|
||||
bundleIdentifier: string;
|
||||
name: string;
|
||||
startTime: number;
|
||||
duration: number;
|
||||
isGlobal?: boolean;
|
||||
}
|
||||
|
||||
export interface RecordingMetadata {
|
||||
@@ -31,6 +33,7 @@ export interface RecordingMetadata {
|
||||
totalSamples: number;
|
||||
icon?: Uint8Array;
|
||||
mp3: string;
|
||||
isGlobal?: boolean;
|
||||
}
|
||||
|
||||
export interface TranscriptionMetadata {
|
||||
|
||||
Reference in New Issue
Block a user