d3ro-voice/apps/desktop/electron.vite.config.ts
Yun Chan 03cd8bf890 feat(desktop): screen text capture (OCR) overlay with selectable text
A rebindable screen-ocr action (default Ctrl+Alt+O) freezes the monitor under the cursor and
covers it with a focusable overlay. Text is selected by flow drag, rectangle drag, double/triple
click, Shift+click or Ctrl+A, then copied, saved as PNG or searchable PDF, translated,
summarized, read aloud, opened as a link or searched.

- Selection, text assembly and the PDF document are pure functions in @d3ro/core/screen-ocr,
  shared by the main process and the overlay.
- Recognition uses Windows.Media.Ocr through powershell.exe -EncodedCommand with 2x upscaling;
  the capture reaches disk only as a temp PNG that is removed right after recognition.
- Capture uses GDI BitBlt for the target monitor (39 ms) because desktopCapturer captured all
  three monitors and took 2.9 s when DXGI duplication timed out.
- The accelerator is reserved only where the feature is available, so macOS does not swallow
  the key for a feature it cannot run (fails closed with a message).

Map: CAP-17 [~], GAP-OCR-01 (live hotkey journey not yet driven in the running app),
GAP-OCR-02 (macOS engine, mixed-language accuracy).
2026-11-20 15:16:37 +09:00

99 lines
3.5 KiB
TypeScript

import { createPublicKey } from 'crypto'
import { copyFileSync, mkdirSync, readdirSync, readFileSync } from 'fs'
import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
const sharedAlias = [
{ find: /^@d3ro\/i18n\/main$/, replacement: resolve(__dirname, '../../packages/i18n/src/main.ts') },
{ find: /^@d3ro\/i18n$/, replacement: resolve(__dirname, '../../packages/i18n/src/index.tsx') },
{ find: /^@d3ro\/core(\/.*)?$/, replacement: `${resolve(__dirname, '../../packages/core/src')}$1` },
{ find: /^@d3ro\/ui(\/.*)?$/, replacement: `${resolve(__dirname, '../../packages/ui/src')}$1` },
]
const copyMainLocalesPlugin = {
name: 'copy-main-locales',
writeBundle(options: { dir?: string }): void {
const outDir = options.dir ?? resolve(__dirname, 'out/main')
const srcDir = resolve(__dirname, '../../packages/i18n/src/locales')
const destDir = resolve(outDir, 'locales')
mkdirSync(destDir, { recursive: true })
for (const file of readdirSync(srcDir)) {
if (file.endsWith('.json')) {
copyFileSync(resolve(srcDir, file), resolve(destDir, file))
}
}
},
}
const workspaceExclude = ['@d3ro/core', '@d3ro/ui', '@d3ro/i18n']
const licensePublicKeyPath = resolve(__dirname, 'resources/license/production-public.pem')
const licensePublicKey = readFileSync(licensePublicKeyPath, 'utf8').trim()
const parsedLicensePublicKey = createPublicKey(licensePublicKey)
if (parsedLicensePublicKey.asymmetricKeyType !== 'ed25519') {
throw new Error(`Desktop license public key must be Ed25519: ${licensePublicKeyPath}`)
}
export default defineConfig({
main: {
// 공개키만 main bundle에 주입한다. 대응 ADMIN_LICENSE_PRIVATE_KEY는 admin 서버 전용이다.
define: {
'process.env.D3RO_LICENSE_PUBLIC_KEY': JSON.stringify(licensePublicKey)
},
plugins: [
externalizeDepsPlugin({
exclude: ['electron-store', ...workspaceExclude]
}),
copyMainLocalesPlugin
],
resolve: { alias: sharedAlias }
},
preload: {
plugins: [externalizeDepsPlugin({ exclude: workspaceExclude })],
build: {
rollupOptions: {
input: {
index: resolve(__dirname, 'src/preload/index.ts'),
popup: resolve(__dirname, 'src/preload/popup.ts')
}
}
},
resolve: { alias: sharedAlias }
},
renderer: {
build: {
rollupOptions: {
input: {
index: resolve(__dirname, 'src/renderer/index.html'),
'popups/recording-tip': resolve(
__dirname,
'src/renderer/popups/recording-tip/index.html'
),
'popups/result-popup': resolve(
__dirname,
'src/renderer/popups/result-popup/index.html'
),
'popups/history-popup': resolve(
__dirname,
'src/renderer/popups/history-popup/index.html'
),
'popups/command-popup': resolve(
__dirname,
'src/renderer/popups/command-popup/index.html'
),
'popups/caption-overlay': resolve(
__dirname,
'src/renderer/popups/caption-overlay/index.html'
),
'popups/suggestion-overlay': resolve(
__dirname,
'src/renderer/popups/suggestion-overlay/index.html'
),
'popups/screen-ocr': resolve(__dirname, 'src/renderer/popups/screen-ocr/index.html')
}
}
},
resolve: { alias: sharedAlias },
plugins: [react()]
}
})