d3ro-voice/apps/desktop/src/renderer/components/SettingsModal.tsx

917 lines
39 KiB
TypeScript

// src/renderer/components/SettingsModal.tsx
// 설정 화면 — v4(2026-09-28)부터 모달이 아니라 메인 창의 전체 화면 라우트로 렌더된다(이름은 호환용으로 유지).
// open 은 "이 화면이 현재 보이는가" — 보일 때만 설정·장치·모델을 불러온다. onClose 는 이전 화면으로 돌아간다.
// 본문 문법: 구획(h3 + 1px 선) 안에 설정 행(왼쪽 라벨·설명, 오른쪽 컨트롤) — settings/SettingsRows.
import { useState, useEffect, useCallback, useMemo } from 'react'
import {
Tabs,
Tab,
Box,
TextField,
Select,
MenuItem,
Switch,
FormControlLabel,
Typography,
FormControl,
Button,
} from '@mui/material'
import { Keyboard, Mic, Lock, Cloud, RefreshCw, Play, HelpCircle, TextCursorInput } from 'lucide-react'
import { d3roPalette, d3roRadius, d3roTransition, d3roTypo, typoSx } from '@d3ro/ui/theme'
import { Led } from '@d3ro/ui/components/ds'
import { LicenseTab } from './LicenseTab'
import { CloudSyncSection } from './CloudSyncSection'
import { STTTab } from './STTTab'
import { CaptionModelSelect } from './CaptionModelSelect'
import { InputConsentPanel } from './input-insights/InputConsentPanel'
import { KeyBindingField } from './keybinding/KeyBindingField'
import { asTranslationKey } from './keybinding/translation-key'
import { SettingNote, SettingRow, SettingsSection, SETTING_CONTROL_WIDTH } from './settings/SettingsRows'
import { UpdateSection } from './settings/UpdateSection'
import { useI18n, LOCALE_META } from '@d3ro/i18n'
import type { Locale } from '@d3ro/i18n'
import type { KeyBindingActionGroup } from '@d3ro/core/keybinding'
import { auditKeyBindingMap, KEYBINDING_ACTIONS } from '@d3ro/core/keybinding'
import type { ThemeMode, AppConfig, AudioDevice, LLMModel, LLMStatus, STTModel } from '@d3ro/core/types'
import { useKeyBindingMap } from '../hooks/useKeyBindingMap'
import { DEFAULT_SETTINGS_TAB, SETTINGS_TAB_ORDER } from '../navigation/settingsTabs'
import type { SettingsTabId } from '../navigation/settingsTabs'
interface SettingsModalProps {
open: boolean
initialTab?: SettingsTabId
onClose: () => void
}
interface TabPanelProps {
children: React.ReactNode
value: SettingsTabId
tab: SettingsTabId
}
function TabPanel({ children, value, tab }: TabPanelProps): React.ReactElement | null {
if (value !== tab) return null
return <Box sx={{ pt: 2 }}>{children}</Box>
}
/** 행 오른쪽 Select·TextField 공통 폭 */
const controlSx = { width: SETTING_CONTROL_WIDTH, maxWidth: '100%' } as const
/** 행 오른쪽 스위치 — 라벨은 행 왼쪽 글자(aria-labelledby)가 맡는다. */
function RowSwitch({
labelId,
checked,
onChange,
}: {
labelId: string
checked: boolean
onChange: (checked: boolean) => void
}): React.ReactElement {
return (
<Switch
checked={checked}
onChange={(e) => onChange(e.target.checked)}
inputProps={{ 'aria-labelledby': labelId }}
/>
)
}
// ── 액션 그룹 섹션 ─────────────────────────────────────
const ACTION_GROUP_LABEL_KEYS: Readonly<Record<KeyBindingActionGroup, string>> = {
voice: 'keybinding.ui.sectionVoice',
window: 'keybinding.ui.sectionWindow',
input: 'keybinding.ui.sectionInput',
}
const ACTION_GROUP_ORDER: readonly KeyBindingActionGroup[] = ['voice', 'window', 'input']
/** 설치된 모델이 없을 때도 고를 수 있게 보여 주는 기본 후보 */
const RECOMMENDED_OLLAMA_MODEL = 'gemma4:e4b'
const FALLBACK_OLLAMA_MODELS = ['llama3.2:3b', 'qwen2.5:3b'] as const
type OllamaFeedback = { tone: 'info' | 'error'; message: string }
export function SettingsModal({ open, initialTab = DEFAULT_SETTINGS_TAB, onClose }: SettingsModalProps): React.ReactElement {
const { t, locale, setLocale } = useI18n()
const [activeTab, setActiveTab] = useState<SettingsTabId>(initialTab)
const tabMeta = useMemo<Record<SettingsTabId, { label: string; icon?: React.ReactElement }>>(
() => ({
general: { label: t('settings.tabs.general'), icon: <Keyboard size={14} /> },
audio: { label: t('settings.tabs.audio'), icon: <Mic size={14} /> },
stt: { label: t('settings.tabs.stt') },
llm: { label: t('settings.tabs.llm') },
input: { label: t('input.tab'), icon: <TextCursorInput size={14} /> },
license: { label: t('license.nav'), icon: <Lock size={14} /> },
cloud: { label: t('settings.tabs.cloud'), icon: <Cloud size={14} /> },
about: { label: t('settings.tabs.about') },
}),
[t],
)
const [config, setConfig] = useState<Partial<AppConfig>>({})
const [loading, setLoading] = useState(true)
const [appVersion, setAppVersion] = useState<string | null>(null)
const keybindingMap = useKeyBindingMap()
const keybindingIssues = useMemo(
() => (keybindingMap === null ? [] : auditKeyBindingMap(keybindingMap)),
[keybindingMap]
)
useEffect(() => {
if (open && initialTab !== undefined) {
setActiveTab(initialTab)
}
}, [open, initialTab])
useEffect(() => {
if (!open) return
let cancelled = false
void window.electronAPI.system.getVersion()
.then((result) => {
if (!cancelled && result.success) setAppVersion(result.data)
})
.catch(() => {
if (!cancelled) setAppVersion(null)
})
return () => {
cancelled = true
}
}, [open])
// 전역 단축키 on/off (개별 바인딩은 KeyBindingField 가 담당한다)
const [keybindingEnabled, setKeybindingEnabled] = useState(true)
// 오디오 디바이스
const [audioDevices, setAudioDevices] = useState<AudioDevice[]>([])
const [selectedDeviceId, setSelectedDeviceId] = useState<string>('default')
const [micTesting, setMicTesting] = useState(false)
const [micLevel, setMicLevel] = useState(0)
const [micTestFailed, setMicTestFailed] = useState(false)
// 실시간 자막 모델 선택지 — 받아 둔 로컬 Whisper 모델만
const [downloadedSttModels, setDownloadedSttModels] = useState<STTModel[]>([])
useEffect(() => {
if (!open) return
window.electronAPI.stt.getModels().then((res) => {
if (res.success && res.data) setDownloadedSttModels(res.data.filter((m) => m.downloaded))
})
}, [open])
// Ollama 상태 — null 은 "아직 조회하지 않음"(연결됨/오프라인으로 단정하지 않는다)
const [ollamaStatus, setOllamaStatus] = useState<LLMStatus | null>(null)
const [ollamaModels, setOllamaModels] = useState<LLMModel[]>([])
const [checkingOllama, setCheckingOllama] = useState(false)
const [startingOllama, setStartingOllama] = useState(false)
const [ollamaFeedback, setOllamaFeedback] = useState<OllamaFeedback | null>(null)
const refreshOllama = useCallback(async () => {
setCheckingOllama(true)
try {
const res = await window.electronAPI.llm.checkConnection()
if (res.success && res.data) {
setOllamaModels(res.data.models)
}
const st = await window.electronAPI.llm.getStatus()
if (st.success) setOllamaStatus(st.data)
} finally {
setCheckingOllama(false)
}
}, [])
// 설정 로드
useEffect(() => {
if (!open) return
setLoading(true)
refreshOllama()
Promise.all([
window.electronAPI.config.getAll(),
window.electronAPI.keybinding.isEnabled(),
])
.then(([configResult, enabledResult]) => {
if (configResult.success) setConfig(configResult.data)
if (enabledResult.success) setKeybindingEnabled(enabledResult.data)
})
.finally(() => setLoading(false))
Promise.all([
window.electronAPI.audio.getDevices(),
window.electronAPI.audio.getSelectedDevice(),
]).then(([devicesResult, selectedResult]) => {
if (devicesResult.success) setAudioDevices(devicesResult.data)
if (selectedResult.success && selectedResult.data) setSelectedDeviceId(selectedResult.data)
})
}, [open, refreshOllama])
const updateConfig = useCallback((key: keyof AppConfig, value: AppConfig[keyof AppConfig]) => {
setConfig((prev) => ({ ...prev, [key]: value }))
window.electronAPI.config.set({ key, value })
}, [])
const handleKeybindingToggle = useCallback((enabled: boolean) => {
setKeybindingEnabled(enabled)
void window.electronAPI.keybinding.setEnabled({ enabled })
}, [])
const handleLanguageChange = useCallback((newLocale: string) => {
setLocale(newLocale as Locale)
setConfig((prev) => ({ ...prev, language: newLocale }))
}, [setLocale])
const handleMicTest = useCallback(async () => {
if (micTesting) {
// 메인 프로세스 캡처까지 실제로 중지 — done 이벤트가 구독 해제를 마무리
await window.electronAPI.audio.stopTest()
setMicTesting(false)
setMicLevel(0)
return
}
setMicTesting(true)
setMicTestFailed(false)
setMicLevel(0)
// level 0은 무음/초기화 중일 뿐 — 종료 판정은 done 플래그로만
const unsub = window.electronAPI.audio.onTestLevel((e) => {
setMicLevel(e.level)
if (e.done) {
setMicTesting(false)
setMicLevel(0)
unsub()
}
})
const result = await window.electronAPI.audio.testDevice({ deviceId: selectedDeviceId })
if (!result.success) {
setMicTesting(false)
setMicLevel(0)
setMicTestFailed(true)
unsub()
}
}, [micTesting, selectedDeviceId])
const handleStartOllama = useCallback(async () => {
setStartingOllama(true)
setOllamaFeedback(null)
try {
const res = await window.electronAPI.llm.startServer()
if (!res.success) {
setOllamaFeedback({ tone: 'error', message: t('settings.llm.feedback.failed') })
} else if (res.data === 'running') {
setOllamaFeedback({ tone: 'info', message: t('settings.llm.feedback.running') })
} else if (res.data === 'starting') {
setOllamaFeedback({ tone: 'info', message: t('settings.llm.feedback.started') })
setTimeout(() => refreshOllama(), 2000)
} else if (res.data === 'not-installed') {
setOllamaFeedback({ tone: 'error', message: t('settings.llm.feedback.notInstalled') })
}
} finally {
setStartingOllama(false)
}
}, [refreshOllama, t])
if (loading) {
return (
<Box role="status" sx={{ px: 5, py: 4, color: d3roPalette.text.tertiary, fontSize: d3roTypo.compact.size }}>
{t('common.loading')}
</Box>
)
}
const ollamaConnected = ollamaStatus?.connectionState === 'connected'
const ollamaStatusText =
ollamaStatus === null
? t('settings.llm.ollamaChecking')
: ollamaConnected
? ollamaStatus.serverVersion
? t('settings.llm.ollamaConnectedVersion', { version: ollamaStatus.serverVersion, count: ollamaModels.length })
: t('settings.llm.ollamaConnected', { count: ollamaModels.length })
: t('settings.llm.ollamaOffline')
const activeOllamaModel = config.llmModelId ?? RECOMMENDED_OLLAMA_MODEL
// v4: 설정은 모달이 아니라 전체 화면 — 왼쪽 세로 탭 + 오른쪽 한 열(읽기 폭 제한).
// 모달 폭 600px 에 탭 8개가 넘쳐 '클라우드·정보'가 잘리던 문제(2026-09-28 실측)를 구조로 해결한다.
return (
<Box sx={{ display: 'flex', minHeight: '100%' }}>
<Box sx={{ width: 208, flexShrink: 0, borderRight: `1px solid ${d3roPalette.border.subtle}` }}>
<Box sx={{ position: 'sticky', top: 0, px: 1.5, py: 3 }}>
<Typography
component="h1"
sx={{ ...typoSx('title'), color: d3roPalette.text.primary, px: 1.5, mb: 2 }}
>
{t('settings.title')}
</Typography>
<Tabs
orientation="vertical"
value={activeTab}
onChange={(_, v: SettingsTabId) => setActiveTab(v)}
aria-label={t('settings.title')}
sx={{
'& .MuiTabs-indicator': { display: 'none' },
'& .MuiTab-root': {
alignItems: 'center',
justifyContent: 'flex-start',
gap: 1,
minHeight: 36,
px: 1.5,
py: 0,
borderRadius: d3roRadius.button,
color: d3roPalette.text.secondary,
fontSize: d3roTypo.compact.size,
fontWeight: 400,
textAlign: 'left',
'&:hover': { color: d3roPalette.text.primary, bgcolor: d3roPalette.surface.overlaySoft },
'&.Mui-selected': { color: d3roPalette.text.primary, fontWeight: 500, bgcolor: d3roPalette.surface.overlayStrong },
'& svg': { margin: 0 },
},
}}
>
{SETTINGS_TAB_ORDER.map((tab) => (
<Tab key={tab} value={tab} label={tabMeta[tab].label} icon={tabMeta[tab].icon} iconPosition="start" />
))}
</Tabs>
</Box>
</Box>
<Box sx={{ flex: 1, minWidth: 0, maxWidth: 760, px: 5, py: 4 }}>
<Typography component="h2" sx={{ ...typoSx('title'), color: d3roPalette.text.primary, mb: 1 }}>
{tabMeta[activeTab].label}
</Typography>
{/* ── 일반 탭 ─────────────────────────────── */}
<TabPanel value={activeTab} tab="general">
<SettingsSection
title={t('settings.shortcuts')}
action={
<FormControlLabel
sx={{ mr: 0 }}
labelPlacement="start"
control={
<Switch
checked={keybindingEnabled}
onChange={(e) => handleKeybindingToggle(e.target.checked)}
/>
}
label={
<Typography sx={{ ...typoSx('small'), color: d3roPalette.text.secondary, mr: 1 }}>
{t('keybinding.ui.globalEnabled')}
</Typography>
}
/>
}
description={
<Box component="span" aria-live="polite" sx={{ display: 'block' }}>
<Box
component="span"
sx={{ display: 'block', color: keybindingIssues.length === 0 ? d3roPalette.text.tertiary : d3roPalette.status.warning }}
>
{keybindingIssues.length === 0
? t('keybinding.ui.auditClear')
: t('keybinding.ui.auditIssues', { count: keybindingIssues.length })}
</Box>
{keybindingIssues.slice(0, 3).map((issue) => {
const action = KEYBINDING_ACTIONS.find((entry) => entry.id === issue.actionId)
const actionLabel = action ? t(asTranslationKey(action.labelKey)) : issue.actionId
const conflictLabels = issue.conflictActionIds
.map((actionId) => {
const conflict = KEYBINDING_ACTIONS.find((entry) => entry.id === actionId)
return conflict ? t(asTranslationKey(conflict.labelKey)) : actionId
})
.join(', ')
return (
<Box
component="span"
key={`${issue.actionId}-${issue.bindingIndex}-${issue.kind}`}
sx={{ display: 'block', color: d3roPalette.text.secondary }}
>
{issue.kind === 'invalid'
? t('keybinding.ui.auditInvalid', {
action: actionLabel,
reason: issue.reasonKey ? t(asTranslationKey(issue.reasonKey)) : t('keybinding.ui.auditUnknown')
})
: t('keybinding.ui.auditConflict', { action: actionLabel, conflicts: conflictLabels })}
</Box>
)
})}
</Box>
}
>
{ACTION_GROUP_ORDER.map((group) => {
const actions = KEYBINDING_ACTIONS.filter((action) => action.group === group)
if (actions.length === 0) return null
return (
<Box key={group} sx={{ mt: 1.5 }}>
<Typography
component="h4"
sx={{ ...typoSx('compact'), fontWeight: 500, color: d3roPalette.text.secondary, mb: 0.25 }}
>
{t(asTranslationKey(ACTION_GROUP_LABEL_KEYS[group]))}
</Typography>
{actions.map((action) => (
<KeyBindingField key={action.id} actionId={action.id} />
))}
</Box>
)
})}
</SettingsSection>
<SettingsSection title={t('settings.interface')}>
<SettingRow
labelId="settings-theme"
label={t('settings.theme')}
control={
<FormControl size="small" sx={controlSx}>
<Select
labelId="settings-theme"
value={config.theme ?? 'auto'}
onChange={(e) => updateConfig('theme', e.target.value as ThemeMode)}
>
<MenuItem value="auto">{t('settings.theme.system')}</MenuItem>
<MenuItem value="light">{t('settings.theme.light')}</MenuItem>
<MenuItem value="dark">{t('settings.theme.dark')}</MenuItem>
<MenuItem value="nord">{t('settings.theme.nord')}</MenuItem>
<MenuItem value="solarized">{t('settings.theme.solarized')}</MenuItem>
<MenuItem value="catppuccin">{t('settings.theme.catppuccin')}</MenuItem>
<MenuItem value="dracula">{t('settings.theme.dracula')}</MenuItem>
</Select>
</FormControl>
}
/>
<SettingRow
labelId="settings-language"
label={t('settings.language')}
control={
<FormControl size="small" sx={controlSx}>
<Select
labelId="settings-language"
value={locale}
onChange={(e) => handleLanguageChange(e.target.value)}
>
{LOCALE_META.map((meta) => (
<MenuItem key={meta.code} value={meta.code}>
{meta.nativeName}
</MenuItem>
))}
</Select>
</FormControl>
}
/>
</SettingsSection>
<SettingsSection title={t('settings.appBehavior')}>
<SettingRow
labelId="settings-close-to-tray"
label={t('settings.closeToTray')}
description={t('settings.closeToTray.desc')}
control={
<RowSwitch
labelId="settings-close-to-tray"
checked={config.closeToTray ?? true}
onChange={(checked) => updateConfig('closeToTray', checked)}
/>
}
/>
<SettingRow
labelId="settings-auto-launch"
label={t('settings.autoLaunch')}
description={t('settings.autoLaunch.desc')}
control={
<RowSwitch
labelId="settings-auto-launch"
checked={config.autoLaunch ?? false}
onChange={(checked) => updateConfig('autoLaunch', checked)}
/>
}
/>
<SettingRow
labelId="settings-auto-insert"
label={t('settings.autoInsert')}
description={t('settings.autoInsert.desc')}
control={
<RowSwitch
labelId="settings-auto-insert"
checked={config.autoInsert ?? true}
onChange={(checked) => updateConfig('autoInsert', checked)}
/>
}
/>
<SettingRow
labelId="settings-sound"
label={t('settings.soundEffects')}
description={t('settings.soundEffects.desc')}
control={
<RowSwitch
labelId="settings-sound"
checked={config.soundEnabled ?? true}
onChange={(checked) => updateConfig('soundEnabled', checked)}
/>
}
/>
</SettingsSection>
</TabPanel>
{/* ── 오디오 탭 ────────────────────────────── */}
<TabPanel value={activeTab} tab="audio">
<SettingsSection title={t('settings.microphone')}>
<SettingRow
labelId="settings-input-device"
label={t('settings.inputDevice')}
control={
<FormControl size="small" sx={{ width: 320, maxWidth: '100%' }}>
<Select
labelId="settings-input-device"
value={selectedDeviceId}
onChange={(e) => {
const deviceId = e.target.value
setSelectedDeviceId(deviceId)
window.electronAPI.audio.setSelectedDevice({ deviceId })
}}
>
{audioDevices.map((device, idx) => (
<MenuItem key={`${device.deviceId}-${idx}`} value={device.deviceId}>
{device.label}{device.isDefault ? ` ${t('settings.deviceDefault')}` : ''}
</MenuItem>
))}
</Select>
</FormControl>
}
/>
<SettingRow
label={t('settings.micTest')}
description={t('settings.micTest.desc')}
control={
<Button variant="outlined" size="small" onClick={handleMicTest} sx={{ minWidth: 72 }}>
{micTesting ? t('common.stop') : t('common.test')}
</Button>
}
>
<Box
role="meter"
aria-label={t('settings.micTest.level')}
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={Math.round(Math.min(100, micLevel * 100))}
sx={{ height: 6, bgcolor: d3roPalette.bg.inset, borderRadius: d3roRadius.xs, overflow: 'hidden' }}
>
<Box
sx={{
width: `${Math.min(100, micLevel * 100)}%`,
height: '100%',
bgcolor: micLevel > 0.7 ? d3roPalette.status.warning : d3roPalette.accent.main,
transition: d3roTransition('width'),
}}
/>
</Box>
{micTestFailed && (
<Box sx={{ mt: 1 }}>
<SettingNote color={d3roPalette.status.danger}>{t('settings.micTest.failed')}</SettingNote>
</Box>
)}
</SettingRow>
</SettingsSection>
<SettingsSection title={t('settings.caption')}>
<SettingRow
labelId="settings-caption-source"
label={t('settings.captionSource')}
control={
<FormControl size="small" sx={controlSx}>
<Select
labelId="settings-caption-source"
value={(config as Record<string, unknown>)['captionAudioSource'] as string ?? 'mic'}
onChange={(e) => {
updateConfig('captionAudioSource' as keyof AppConfig, e.target.value as never)
// CaptionService 설정도 갱신
window.electronAPI.caption.setConfig({ audioSource: e.target.value as 'mic' | 'system' | 'both' })
}}
>
<MenuItem value="mic">{t('settings.captionSource.mic')}</MenuItem>
<MenuItem value="system">{t('settings.captionSource.system')}</MenuItem>
<MenuItem value="both">{t('settings.captionSource.both')}</MenuItem>
</Select>
</FormControl>
}
/>
<CaptionModelSelect
value={config.captionSttModelId}
models={downloadedSttModels}
onChange={(modelId) => updateConfig('captionSttModelId', modelId)}
/>
<SettingRow
labelId="settings-caption-refine"
label={t('settings.captionRefine')}
description={t('settings.captionRefine.desc')}
control={
<RowSwitch
labelId="settings-caption-refine"
checked={config.captionRefineEnabled !== false}
onChange={(checked) => updateConfig('captionRefineEnabled', checked)}
/>
}
/>
</SettingsSection>
<SettingsSection title={t('settings.textInsert')}>
<SettingRow
labelId="settings-insert-method"
label={t('settings.insertMethod')}
control={
<FormControl size="small" sx={controlSx}>
<Select
labelId="settings-insert-method"
value={config.insertMethod ?? 'clipboard'}
onChange={(e) => updateConfig('insertMethod', e.target.value as 'clipboard' | 'keyboard')}
>
<MenuItem value="clipboard">{t('settings.insertClipboard')}</MenuItem>
<MenuItem value="keyboard">{t('settings.insertKeyboard')}</MenuItem>
</Select>
</FormControl>
}
/>
</SettingsSection>
</TabPanel>
{/* ── STT 탭 ───────────────────────────────── */}
<TabPanel value={activeTab} tab="stt">
<STTTab config={config} updateConfig={updateConfig} />
</TabPanel>
{/* ── LLM 탭 ──────────────────────────────── */}
<TabPanel value={activeTab} tab="llm">
<SettingsSection title={t('settings.llm.engineSection')}>
<SettingRow
labelId="settings-llm-engine"
label={t('settings.llm.engine')}
description={t('settings.llm.engine.desc')}
control={
<FormControl size="small" sx={{ width: 320, maxWidth: '100%' }}>
<Select
labelId="settings-llm-engine"
value={config.llmBackend ?? 'local'}
onChange={(e) => {
const val = e.target.value as 'local' | 'online'
updateConfig('llmBackend', val)
updateConfig('appUsageMode', val)
}}
>
<MenuItem value="local">{t('settings.llm.engine.local')}</MenuItem>
<MenuItem value="online">{t('settings.llm.engine.online')}</MenuItem>
</Select>
</FormControl>
}
/>
{/* 로컬 Ollama */}
{config.llmBackend !== 'online' && (
<>
<SettingRow
label={t('settings.llm.ollamaStatus')}
description={
<Box component="span" role="status" sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.75 }}>
{ollamaStatus !== null && <Led color={ollamaConnected ? 'green' : 'red'} size={6} />}
{ollamaStatusText}
</Box>
}
control={
<>
<Button
size="small"
variant="outlined"
startIcon={<RefreshCw size={13} className={checkingOllama ? 'animate-spin' : ''} />}
onClick={refreshOllama}
disabled={checkingOllama}
>
{t('settings.llm.checkConnection')}
</Button>
{ollamaStatus !== null && !ollamaConnected && (
<Button
size="small"
variant="contained"
startIcon={<Play size={13} />}
onClick={handleStartOllama}
disabled={startingOllama}
>
{startingOllama ? t('settings.llm.startingOllama') : t('settings.llm.startOllama')}
</Button>
)}
</>
}
>
{ollamaFeedback && (
<SettingNote color={ollamaFeedback.tone === 'error' ? d3roPalette.status.danger : d3roPalette.text.secondary}>
{ollamaFeedback.message}
</SettingNote>
)}
</SettingRow>
<SettingRow
label={t('settings.llm.guide')}
description={t('settings.llm.guide.desc')}
control={
<Button
size="small"
variant="text"
startIcon={<HelpCircle size={13} />}
onClick={() => window.dispatchEvent(new CustomEvent('d3ro:open-ollama-guide'))}
>
{t('settings.llm.openGuide')}
</Button>
}
/>
<SettingRow
labelId="settings-ollama-model"
label={t('settings.llm.activeModel')}
description={t('settings.llm.activeModel.desc')}
control={
<FormControl size="small" sx={controlSx}>
<Select
labelId="settings-ollama-model"
value={activeOllamaModel}
onChange={(e) => {
const val = e.target.value
updateConfig('llmModelId', val)
window.electronAPI.llm.setModel({ modelId: val })
}}
>
{ollamaModels.map((m) => (
<MenuItem key={m.id} value={m.name}>
{m.name} · {Math.round(m.sizeBytes / (1024 * 1024 * 1024) * 10) / 10} GB
</MenuItem>
))}
{/* 설치된 모델이 없으면 권장 모델을, 흔한 기본 후보는 설치 여부를 밝혀 보여 준다 */}
{ollamaModels.length === 0 && (
<MenuItem value={RECOMMENDED_OLLAMA_MODEL}>
{t('settings.llm.modelRecommended', { name: RECOMMENDED_OLLAMA_MODEL })}
</MenuItem>
)}
{FALLBACK_OLLAMA_MODELS.filter((name) => !ollamaModels.some((m) => m.name === name)).map((name) => (
<MenuItem key={name} value={name}>
{t('settings.llm.modelNotInstalled', { name })}
</MenuItem>
))}
</Select>
</FormControl>
}
/>
<SettingRow
labelId="settings-ollama-url"
label={t('settings.ollamaUrl')}
description={t('settings.llm.serverUrl.desc')}
control={
<TextField
value={config.ollamaServerUrl ?? 'http://localhost:11434'}
onChange={(e) => updateConfig('ollamaServerUrl', e.target.value)}
size="small"
sx={controlSx}
inputProps={{ 'aria-labelledby': 'settings-ollama-url', spellCheck: false }}
/>
}
/>
</>
)}
{/* 온라인 API */}
{config.llmBackend === 'online' && (
<>
<SettingRow
labelId="settings-online-url"
label={t('settings.llm.onlineUrl')}
control={
<TextField
value={config.onlineApiUrl ?? 'http://localhost:5000'}
onChange={(e) => updateConfig('onlineApiUrl', e.target.value)}
size="small"
sx={controlSx}
inputProps={{ 'aria-labelledby': 'settings-online-url', spellCheck: false }}
/>
}
/>
<SettingRow
label={t('settings.llm.account')}
description={
config.authToken
? config.userEmail
? t('settings.llm.accountSignedIn', { email: config.userEmail })
: t('settings.llm.accountSignedInNoEmail')
: t('settings.llm.accountSignedOut')
}
/>
</>
)}
</SettingsSection>
<SettingsSection title={t('settings.postProcess')}>
<SettingRow
labelId="settings-default-action"
label={t('settings.defaultAction')}
description={t('settings.actionHint')}
control={
<FormControl size="small" sx={controlSx}>
<Select
labelId="settings-default-action"
value={config.defaultLLMAction ?? 'refine'}
onChange={(e) => updateConfig('defaultLLMAction', e.target.value)}
>
<MenuItem value="none">{t('settings.action.none')}</MenuItem>
<MenuItem value="refine">{t('settings.action.refine')}</MenuItem>
<MenuItem value="translate">{t('settings.action.translate')}</MenuItem>
<MenuItem value="summarize">{t('settings.action.summarize')}</MenuItem>
<MenuItem value="grammar">{t('settings.action.grammar')}</MenuItem>
<MenuItem value="custom">{t('settings.action.custom')}</MenuItem>
</Select>
</FormControl>
}
/>
<SettingRow
labelId="settings-voice-commands"
label={t('settings.voiceCommands')}
description={t('settings.voiceCommands.desc')}
control={
<RowSwitch
labelId="settings-voice-commands"
checked={(config as Record<string, unknown>)['voiceCommandsEnabled'] as boolean ?? false}
onChange={(checked) => {
updateConfig('voiceCommandsEnabled' as keyof AppConfig, checked as never)
void window.electronAPI.voiceCommand.setEnabled({ enabled: checked })
}}
/>
}
/>
<SettingRow
labelId="settings-screen-context"
label={t('settings.screenContext')}
description={t('settings.screenContext.desc')}
control={
<RowSwitch
labelId="settings-screen-context"
checked={config.screenContextEnabled ?? false}
onChange={(checked) => {
updateConfig('screenContextEnabled', checked)
void window.electronAPI.context.setEnabled({ enabled: checked })
}}
/>
}
/>
</SettingsSection>
</TabPanel>
{/* ── 입력 인사이트 탭 ─────────────────────────── */}
<TabPanel value={activeTab} tab="input">
<InputConsentPanel />
</TabPanel>
{/* ── 라이선스 탭 ────────────────────────────── */}
<TabPanel value={activeTab} tab="license">
<LicenseTab />
</TabPanel>
{/* ── Cloud Sync 탭 ──────────────────────────── */}
<TabPanel value={activeTab} tab="cloud">
<CloudSyncSection />
</TabPanel>
{/* ── 정보 탭 ──────────────────────────────── */}
<TabPanel value={activeTab} tab="about">
<UpdateSection />
<SettingsSection title={t('settings.about.appName')} description={t('settings.about.summary')}>
<SettingRow
label={t('settings.about.version')}
control={
<Typography sx={{ ...typoSx('compact'), color: d3roPalette.text.secondary, fontVariantNumeric: 'tabular-nums' }}>
{appVersion === null ? '—' : `v${appVersion}`}
</Typography>
}
/>
<SettingRow label={t('settings.about.techStack')} description={t('settings.about.techStackValue')} />
<SettingRow label={t('settings.about.voiceEngine')} description={t('settings.about.voiceEngineValue')} />
</SettingsSection>
<SettingsSection title={t('settings.about.helpSection')}>
<SettingRow
label={t('settings.about.restartOnboarding')}
description={t('settings.about.restartOnboarding.desc')}
control={
<Button
variant="outlined"
size="small"
onClick={() => {
window.electronAPI.config.set({
key: 'onboardingCompleted',
value: false,
})
onClose()
setTimeout(() => window.location.reload(), 300)
}}
>
{t('settings.about.restartOnboarding.action')}
</Button>
}
/>
</SettingsSection>
</TabPanel>
</Box>
</Box>
)
}