Some checks failed
ci / 정본·보안·린트·타입·테스트 (push) Failing after 50s
ci / 워크스페이스 빌드 검증 (push) Has been skipped
ci / Supabase Edge Functions + Cloudflare Worker (push) Successful in 20s
ci / .NET API 서버 테스트 (push) Successful in 12s
deploy-site / deploy (push) Successful in 39s
ci / 모바일 린트·타입·Jest (push) Failing after 3h10m31s
286 lines
12 KiB
TypeScript
286 lines
12 KiB
TypeScript
// 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<SettingsTabId>(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<LicenseTier>('free')
|
|
const [fallbackMsg, setFallbackMsg] = useState<string | null>(null)
|
|
const [voiceAlert, setVoiceAlert] = useState<{
|
|
message: string
|
|
severity: 'error' | 'warning'
|
|
/** 복구 딥링크(예: STT 모델 없음 → 설정 → STT). 없으면 닫기만. */
|
|
settingsTab: SettingsTabId | null
|
|
} | null>(null)
|
|
const scrollRef = React.useRef<OverlayScrollbarsComponentRef>(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 (
|
|
<Box sx={{ display: 'flex', height: '100vh', flexDirection: 'column', bgcolor: d3roPalette.bg.app }}>
|
|
<TitleBar />
|
|
<Box sx={{ display: 'flex', flex: 1, overflow: 'hidden' }}>
|
|
<AppSidebar
|
|
tier={currentTier}
|
|
onOpenSupport={() => setSupportModalOpen(true)}
|
|
onOpenOllamaGuide={() => setOllamaGuideOpen(true)}
|
|
/>
|
|
|
|
<Box
|
|
component="main"
|
|
sx={{ flexGrow: 1, minWidth: 0, display: 'flex', flexDirection: 'column', bgcolor: d3roPalette.bg.app }}
|
|
>
|
|
<Box sx={{ flex: 1, overflow: 'hidden' }}>
|
|
<OverlayScrollbarsComponent
|
|
ref={scrollRef}
|
|
defer
|
|
options={{
|
|
scrollbars: {
|
|
theme: 'os-theme-dark',
|
|
autoHide: 'move',
|
|
autoHideDelay: 800,
|
|
clickScroll: true,
|
|
},
|
|
}}
|
|
style={{ height: '100%', width: '100%' }}
|
|
>
|
|
{route === 'home' && <HomePage />}
|
|
{route === 'search' && <UnifiedSearchPage />}
|
|
{route === 'records' && <HistoryPage />}
|
|
{route === 'meetings' && <MeetingModePage />}
|
|
{route === 'conversation' && <VoiceConversationPage />}
|
|
{route === 'commands' && <CommandsPage />}
|
|
{route === 'dictionary' && <DictionaryPage />}
|
|
{route === 'knowledge' && <KnowledgeBasePage />}
|
|
{route === 'settings' && <SettingsModal open initialTab={settingsTab} onClose={back} />}
|
|
</OverlayScrollbarsComponent>
|
|
</Box>
|
|
|
|
{currentTier === 'free' && (
|
|
<Box sx={{ px: 2, pb: 1, pt: 0.5, flexShrink: 0 }}>
|
|
<AdBanner
|
|
tier={currentTier}
|
|
onUpgrade={() => void window.electronAPI.license.openBilling({ tier: 'pro' })}
|
|
/>
|
|
</Box>
|
|
)}
|
|
</Box>
|
|
</Box>
|
|
|
|
<LicenseModal open={licenseModalOpen} onClose={() => setLicenseModalOpen(false)} />
|
|
<OnboardingModal open={onboardingOpen} onClose={() => setOnboardingOpen(false)} />
|
|
<SupportModal open={supportModalOpen} onClose={() => setSupportModalOpen(false)} />
|
|
<OllamaGuideModal open={ollamaGuideOpen} onClose={() => setOllamaGuideOpen(false)} />
|
|
<RewardedQuotaModal
|
|
open={rewardedModalOpen}
|
|
onClose={() => setRewardedModalOpen(false)}
|
|
onRewardClaimed={(tokens) => notify({ message: t('shell.rewardClaimed', { tokens }), severity: 'success' })}
|
|
/>
|
|
|
|
<Snackbar
|
|
open={fallbackMsg !== null}
|
|
autoHideDuration={8000}
|
|
onClose={() => setFallbackMsg(null)}
|
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
|
>
|
|
<Alert severity="warning" variant="outlined" onClose={() => setFallbackMsg(null)} sx={{ width: '100%', bgcolor: d3roPalette.bg.elevated }}>
|
|
{fallbackMsg}
|
|
</Alert>
|
|
</Snackbar>
|
|
|
|
<Snackbar
|
|
open={voiceAlert !== null}
|
|
autoHideDuration={6000}
|
|
onClose={() => setVoiceAlert(null)}
|
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
|
>
|
|
<Alert
|
|
severity={voiceAlert?.severity ?? 'error'}
|
|
variant="outlined"
|
|
onClose={() => setVoiceAlert(null)}
|
|
action={
|
|
voiceAlert?.settingsTab ? (
|
|
<>
|
|
<Button
|
|
color="inherit"
|
|
size="small"
|
|
onClick={() => {
|
|
const tab = voiceAlert.settingsTab
|
|
setVoiceAlert(null)
|
|
if (tab) openSettingsTab(tab)
|
|
}}
|
|
>
|
|
{t('nav.settings')}
|
|
</Button>
|
|
<IconButton color="inherit" size="small" aria-label={t('common.close')} onClick={() => setVoiceAlert(null)}>
|
|
<X size={16} />
|
|
</IconButton>
|
|
</>
|
|
) : undefined
|
|
}
|
|
sx={{ width: '100%', bgcolor: d3roPalette.bg.elevated }}
|
|
>
|
|
{voiceAlert?.message ?? ''}
|
|
</Alert>
|
|
</Snackbar>
|
|
</Box>
|
|
)
|
|
}
|
|
|
|
export function AppLayout(): React.ReactElement {
|
|
return (
|
|
<AppNavigationProvider initialRoute="home">
|
|
<NotifyProvider>
|
|
<Shell />
|
|
</NotifyProvider>
|
|
</AppNavigationProvider>
|
|
)
|
|
}
|