82 lines
3.1 KiB
TypeScript
82 lines
3.1 KiB
TypeScript
// src/main/ipc/file-transcription-handlers.ts
|
|
// Phase 12.1: 파일 전사 IPC 핸들러
|
|
|
|
import { ipcMain, dialog } from 'electron'
|
|
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
|
|
import { ErrorCode, ipcSuccess, ipcError } from '@d3ro/core/errors'
|
|
import { getFileTranscriptionService } from '../services/FileTranscriptionService'
|
|
import { getLogger } from '../services/LoggerService'
|
|
import type { FileTranscriptionStartParams } from '@d3ro/core/types'
|
|
import { SUPPORTED_MEDIA_EXTENSIONS } from '../services/file-transcription/media-formats'
|
|
|
|
const logger = getLogger('file-transcription-handlers')
|
|
|
|
let isShowingFileTranscriptionDialog = false
|
|
|
|
export function registerFileTranscriptionHandlers(): void {
|
|
ipcMain.handle(
|
|
IPC_CHANNELS.FILE_TRANSCRIPTION.START,
|
|
async (_event, params: FileTranscriptionStartParams) => {
|
|
try {
|
|
let filePath = params.filePath
|
|
|
|
// filePath가 없으면 파일 선택 다이얼로그
|
|
if (!filePath) {
|
|
if (isShowingFileTranscriptionDialog) {
|
|
return ipcError(ErrorCode.FileTranscriptionCancelled, 'File selection dialog already active')
|
|
}
|
|
isShowingFileTranscriptionDialog = true
|
|
try {
|
|
const { getMainWindow } = await import('../windows/WindowManager')
|
|
const mainWindow = getMainWindow()
|
|
const dialogOptions = {
|
|
properties: ['openFile'] as ('openFile')[],
|
|
filters: [
|
|
{
|
|
name: 'Audio/Video',
|
|
extensions: [...SUPPORTED_MEDIA_EXTENSIONS],
|
|
},
|
|
],
|
|
}
|
|
const result = mainWindow
|
|
? await dialog.showOpenDialog(mainWindow, dialogOptions)
|
|
: await dialog.showOpenDialog(dialogOptions)
|
|
if (result.canceled || result.filePaths.length === 0) {
|
|
return ipcError(ErrorCode.FileTranscriptionCancelled, 'File selection cancelled')
|
|
}
|
|
filePath = result.filePaths[0]
|
|
} finally {
|
|
isShowingFileTranscriptionDialog = false
|
|
}
|
|
}
|
|
|
|
const service = getFileTranscriptionService()
|
|
const resultData = await service.startTranscription(filePath, params.language)
|
|
return ipcSuccess(resultData)
|
|
} catch (err) {
|
|
const msg = err instanceof Error ? err.message : String(err)
|
|
logger.error('File transcription failed:', msg)
|
|
return ipcError(ErrorCode.FileTranscriptionChunkFailed, msg)
|
|
}
|
|
},
|
|
)
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FILE_TRANSCRIPTION.CANCEL, async () => {
|
|
try {
|
|
getFileTranscriptionService().cancel()
|
|
return ipcSuccess(undefined)
|
|
} catch (err) {
|
|
const msg = err instanceof Error ? err.message : String(err)
|
|
return ipcError(ErrorCode.FileTranscriptionCancelled, msg)
|
|
}
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.FILE_TRANSCRIPTION.GET_STATE, async () => {
|
|
try {
|
|
return ipcSuccess(getFileTranscriptionService().getStateInfo())
|
|
} catch (err) {
|
|
const msg = err instanceof Error ? err.message : String(err)
|
|
return ipcError(ErrorCode.UnknownError, msg)
|
|
}
|
|
})
|
|
}
|