File size: 2,097 Bytes
5f3e9f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { useEffect, useState } from 'react'
import { api } from '../api/client'

export type BackendPlatform = 'windows' | 'non-windows' | 'unknown'

export interface BackendCapabilities {
  platform: BackendPlatform
  /**
   * True when the backend reports a usable video engine (PowerPoint COM
   * on Windows *or* MoviePy on Linux/macOS). Controls the MP4 output
   * option in the wizard.
   */
  videoEngineReady: boolean
  /**
   * True when the backend can emit .pptx decks — still requires a
   * Windows host with PowerPoint COM automation, since the MoviePy
   * engine only produces MP4.
   */
  pptxReady: boolean
}

/**
 * Peek at the backend's platform + video engine capabilities via the
 * (cached) preflight response.
 *
 * Used to gate MP4 / PowerPoint output. The MP4 gate now opens when
 * *either* engine is available so a Linux backend with MoviePy can
 * export video even though PowerPoint COM is Windows-only.
 */
export function useBackendPlatform(): BackendPlatform {
  return useBackendCapabilities().platform
}

export function useBackendCapabilities(): BackendCapabilities {
  const [caps, setCaps] = useState<BackendCapabilities>({
    platform: 'unknown',
    videoEngineReady: false,
    pptxReady: false,
  })

  useEffect(() => {
    let cancelled = false
    api
      .preflight()
      .then((r) => {
        if (cancelled) return
        const detail = (r.checks.platform?.detail ?? '').toLowerCase()
        const platform: BackendPlatform = detail.startsWith('windows')
          ? 'windows'
          : detail
            ? 'non-windows'
            : 'unknown'
        const pptxReady = r.checks.powerpoint?.ok === true
        const videoEngineReady =
          r.checks.video_engine?.ok === true || pptxReady
        setCaps({ platform, videoEngineReady, pptxReady })
      })
      .catch(() => {
        if (!cancelled) {
          setCaps({
            platform: 'unknown',
            videoEngineReady: false,
            pptxReady: false,
          })
        }
      })
    return () => {
      cancelled = true
    }
  }, [])

  return caps
}