// src/renderer/components/AppLayout.tsx // 메인 창 셸 — 2026-09-28 정보 구조 개편 ("기록이 주인공인 조용한 계기"). // 타이틀바 · 사이드바(1급 홈·기록·회의 / 도구 / 설정) · 본문. 상태바는 없앴다: // 버전·모델은 설정에, 시계는 OS 에 있고, "100% LOCAL PRIVACY · ZERO CLOUD SYNC"는 기기 간 동기화와 모순된 문구였다. // 의미 있는 상태(로컬 AI 연결·자막·회의 녹음 중)는 사이드바 아래 한 줄로 옮겼다. import React, { useState, useEffect, useCallback } from 'react' import { Alert, Box, Button, IconButton, Snackbar } from '@mui/material' import { X } from 'lucide-react' import { OverlayScrollbarsComponent } from 'overlayscrollbars-react' import type { OverlayScrollbarsComponentRef } from 'overlayscrollbars-react' import { d3roPalette } from '@d3ro/ui/theme' import { useI18n } from '@d3ro/i18n' import type { LicenseTier } from '@d3ro/core/types' import { HomePage } from '../pages/HomePage' import { HistoryPage } from '../pages/HistoryPage' import { DictionaryPage } from '../pages/DictionaryPage' import { CommandsPage } from '../pages/CommandsPage' import { VoiceConversationPage } from '../pages/VoiceConversationPage' import { KnowledgeBasePage } from '../pages/KnowledgeBasePage' import { MeetingModePage } from '../pages/MeetingModePage' import { UnifiedSearchPage } from '../pages/UnifiedSearchPage' import { SettingsModal } from './SettingsModal' import { OPEN_SETTINGS_EVENT, readOpenSettingsTab, DEFAULT_SETTINGS_TAB } from '../navigation/settingsTabs' import type { SettingsTabId } from '../navigation/settingsTabs' import { presentError, settingsTabOf } from '../navigation/error-recovery' import { AppNavigationProvider, PRIMARY_ROUTES, useAppNavigation, useRouteRequest } from '../navigation/app-navigation' import { LicenseModal } from './LicenseModal' import { OnboardingModal } from './OnboardingModal' import { OllamaGuideModal } from './OllamaGuideModal' import { AdBanner } from './ads/AdBanner' import { RewardedQuotaModal } from './ads/RewardedQuotaModal' import { SupportModal } from './support/SupportModal' import { TitleBar } from './TitleBar' import { AppSidebar } from './shell/AppSidebar' import { NotifyProvider, useNotify } from './shared' /** 입력 요소에 포커스가 있으면 전역 단축키를 무시한다 — 타자 중에 화면이 바뀌면 안 된다. */ function isTypingTarget(target: EventTarget | null): boolean { if (!(target instanceof HTMLElement)) return false return target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName) } function Shell(): React.ReactElement { const { t } = useI18n() const { route, navigate, back } = useAppNavigation() const notify = useNotify() const [settingsTab, setSettingsTab] = useState(DEFAULT_SETTINGS_TAB) const [onboardingOpen, setOnboardingOpen] = useState(false) const [licenseModalOpen, setLicenseModalOpen] = useState(false) const [supportModalOpen, setSupportModalOpen] = useState(false) const [rewardedModalOpen, setRewardedModalOpen] = useState(false) const [ollamaGuideOpen, setOllamaGuideOpen] = useState(false) const [currentTier, setCurrentTier] = useState('free') const [fallbackMsg, setFallbackMsg] = useState(null) const [voiceAlert, setVoiceAlert] = useState<{ message: string severity: 'error' | 'warning' /** 복구 딥링크(예: STT 모델 없음 → 설정 → STT). 없으면 닫기만. */ settingsTab: SettingsTabId | null } | null>(null) const scrollRef = React.useRef(null) // 화면을 바꾸면 새 화면은 맨 위에서 시작한다 useEffect(() => { scrollRef.current?.osInstance()?.elements().viewport.scrollTo({ top: 0 }) }, [route]) useRouteRequest('settings', (params) => { if (params.settingsTab) setSettingsTab(params.settingsTab) }) useEffect(() => { window.electronAPI.config.getAll().then((r) => { if (r.success && !r.data.onboardingCompleted) { setOnboardingOpen(true) } }) }, []) useEffect(() => { window.electronAPI.license.getInfo().then((r) => { if (r.success) setCurrentTier(r.data.tier) }) const unsubTier = window.electronAPI.license.onTierChanged((info) => { setCurrentTier(info.tier) }) const unsubUpgrade = window.electronAPI.license.onUpgradePrompt(() => { setLicenseModalOpen(true) }) const handleOpenLicenseModal = (): void => setLicenseModalOpen(true) window.addEventListener('d3ro:open-license-modal', handleOpenLicenseModal) // detail.tab 은 타입 없는 DOM 경계라 검증한다 — 모르는 값이면 기본 탭(빈 설정 화면 방지) const handleOpenSettings = (e: Event): void => { const tab = readOpenSettingsTab(e) setSettingsTab(tab) navigate('settings', { settingsTab: tab }) } window.addEventListener(OPEN_SETTINGS_EVENT, handleOpenSettings) const handleOpenGuide = (): void => setOllamaGuideOpen(true) window.addEventListener('d3ro:open-ollama-guide', handleOpenGuide) const unsubVoiceError = window.electronAPI.voice.onError((e) => { // 분류·복구는 error-recovery 정책이 정한다. STT 모델 없음(101)은 예전처럼 닫을 수 없는 온보딩을 // 열지 않고, 모델을 받을 수 있는 설정 → STT 탭으로 가는 동작을 알림에 붙인다. const severity = e.severity ?? 'error' const presentation = presentError({ context: 'voice', code: e.errorCode, severity }) const message = presentation.messageKey ? t(presentation.messageKey) : e.message setVoiceAlert({ message, severity, settingsTab: settingsTabOf(presentation) }) }) const unsubFallback = window.electronAPI.llm.premium.onFallback((e) => { setFallbackMsg(e.reason) }) const unsubUpgradeReq = window.electronAPI.llm.premium.onUpgradeRequired(() => { setLicenseModalOpen(true) }) return () => { unsubTier() unsubUpgrade() unsubFallback() unsubUpgradeReq() unsubVoiceError() window.removeEventListener('d3ro:open-license-modal', handleOpenLicenseModal) window.removeEventListener(OPEN_SETTINGS_EVENT, handleOpenSettings) window.removeEventListener('d3ro:open-ollama-guide', handleOpenGuide) } }, [t, navigate]) // 키보드: Ctrl+K = 통합 검색, Ctrl+1..3 = 1급 화면, Ctrl+, = 설정. useEffect(() => { const onKeyDown = (e: KeyboardEvent): void => { if (!(e.ctrlKey || e.metaKey) || e.altKey || e.shiftKey) return if (e.key.toLocaleLowerCase() === 'k') { e.preventDefault() if (route !== 'search') navigate('search') return } if (isTypingTarget(e.target)) return const index = ['1', '2', '3'].indexOf(e.key) if (index >= 0) { e.preventDefault() navigate(PRIMARY_ROUTES[index]) } else if (e.key === ',') { e.preventDefault() navigate('settings') } } window.addEventListener('keydown', onKeyDown) return () => window.removeEventListener('keydown', onKeyDown) }, [navigate, route]) const openSettingsTab = useCallback( (tab: SettingsTabId) => { setSettingsTab(tab) navigate('settings', { settingsTab: tab }) }, [navigate], ) return ( setSupportModalOpen(true)} onOpenOllamaGuide={() => setOllamaGuideOpen(true)} /> {route === 'home' && } {route === 'search' && } {route === 'records' && } {route === 'meetings' && } {route === 'conversation' && } {route === 'commands' && } {route === 'dictionary' && } {route === 'knowledge' && } {route === 'settings' && } {currentTier === 'free' && ( void window.electronAPI.license.openBilling({ tier: 'pro' })} /> )} setLicenseModalOpen(false)} /> setOnboardingOpen(false)} /> setSupportModalOpen(false)} /> setOllamaGuideOpen(false)} /> setRewardedModalOpen(false)} onRewardClaimed={(tokens) => notify({ message: t('shell.rewardClaimed', { tokens }), severity: 'success' })} /> setFallbackMsg(null)} anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} > setFallbackMsg(null)} sx={{ width: '100%', bgcolor: d3roPalette.bg.elevated }}> {fallbackMsg} setVoiceAlert(null)} anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} > setVoiceAlert(null)} action={ voiceAlert?.settingsTab ? ( <> setVoiceAlert(null)}> ) : undefined } sx={{ width: '100%', bgcolor: d3roPalette.bg.elevated }} > {voiceAlert?.message ?? ''} ) } export function AppLayout(): React.ReactElement { return ( ) }