-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
173 lines (164 loc) · 5.64 KB
/
Copy pathApp.tsx
File metadata and controls
173 lines (164 loc) · 5.64 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { useEffect, useRef, useState } from "react";
import hudReferenceUrl from "../docs/design/selected-peripheral-focus.png";
import {
drawHudReference,
transmitCanvas,
transmitHardwareBmp,
transmitHybridCanvas,
transmitOfficialSample,
} from "./glasses";
import { drawCalibrationPattern } from "./calibration";
import {
drawDenseCanvasHud,
getAdjacentHudPage,
HUD_PAGES,
type HudPage,
} from "./canvas-hud";
import {
drawHybridHudBackground,
formatHybridHudText,
} from "./hybrid-hud";
type AppProps = {
autoStart?: boolean;
};
export function App({ autoStart = true }: AppProps) {
const calibrationMode = window.location.pathname === "/calibration-max";
const canvasHudMode = window.location.pathname === "/hud-canvas";
const hybridHudMode = window.location.pathname === "/hud-hybrid";
const hardwareBmpMode = window.location.pathname === "/diagnostic-v10";
const diagnosticMode = window.location.pathname.startsWith("/diagnostic-v")
|| new URLSearchParams(window.location.search).get("mode") === "diagnostic";
const canvasRef = useRef<HTMLCanvasElement>(null);
const [status, setStatus] = useState(
autoStart ? "HUD 이미지 준비 중" : "자동 전송 비활성",
);
useEffect(() => {
if (!autoStart || !canvasRef.current) return;
let cancelled = false;
let unsubscribe: (() => void) | undefined;
let page: HudPage = HUD_PAGES[0];
const canvas = canvasRef.current;
const report = (message: string) => {
if (!cancelled) setStatus(message);
};
const drawCurrentPage = () => {
drawDenseCanvasHud(canvas, new Date(), page);
};
void (async () => {
if (calibrationMode) {
drawCalibrationPattern(canvas);
} else if (canvasHudMode) {
drawCurrentPage();
} else if (hybridHudMode) {
drawHybridHudBackground(canvas);
} else {
await drawHudReference(canvas, hudReferenceUrl);
}
report("Even 앱 브리지 연결 대기 중 · Safari에서는 미리보기만 표시됩니다");
unsubscribe = hardwareBmpMode
? await transmitHardwareBmp(report)
: diagnosticMode
? await transmitOfficialSample(report)
: hybridHudMode
? await transmitHybridCanvas(
canvas,
formatHybridHudText(page),
report,
async (direction) => {
page = getAdjacentHudPage(page, direction);
return formatHybridHudText(page);
},
)
: await transmitCanvas(
canvas,
report,
undefined,
undefined,
canvasHudMode
? async (direction) => {
page = getAdjacentHudPage(page, direction);
drawCurrentPage();
}
: undefined,
);
})().catch((error: unknown) => {
report(error instanceof Error ? error.message : String(error));
});
return () => {
cancelled = true;
unsubscribe?.();
};
}, [
autoStart,
calibrationMode,
canvasHudMode,
diagnosticMode,
hardwareBmpMode,
hybridHudMode,
]);
return (
<main className="preview-stage">
<header className="preview-header">
<div>
<strong>RELIC / G2 RASTER TEST</strong>
<span>
{hardwareBmpMode
? "1-BIT BMP · CLICK TO SEND"
: diagnosticMode
? "OFFICIAL SAMPLE.PNG · RAW BYTES"
: calibrationMode
? "576×288 MAX BOUNDARY"
: hybridHudMode
? "STATIC CANVAS + NATIVE TEXT · SCROLL · 4 PAGES"
: canvasHudMode
? "576×288 · CANVAS HUD · SCROLL · 4 PAGES"
: "576×288 · 4 IMAGE TILES"}
{" · STATIC MOCK"}
</span>
</div>
<output aria-live="polite">{status}</output>
</header>
<section
className="hud-frame"
data-testid="hud-frame"
data-logical-size="576x288"
data-renderer={
hybridHudMode
? "hybrid"
: canvasHudMode
? "canvas"
: calibrationMode
? "calibration"
: "image"
}
data-text-containers={diagnosticMode ? "2" : "1"}
data-image-containers={diagnosticMode ? "1" : "4"}
data-pages={
canvasHudMode || hybridHudMode ? HUD_PAGES.length : undefined
}
aria-label="RELIC 이미지 전송 시안"
>
<canvas
ref={canvasRef}
width="576"
height="288"
role="img"
aria-label="RELIC HUD 안경 프레임"
/>
</section>
<p className="preview-note">
{hardwareBmpMode
? "안경에 준비 문구를 표시한 뒤 링/터치바를 클릭하면 200×100 1-bit BMP를 전송합니다."
: diagnosticMode
? "진단 모드에서는 Even Realities 공식 sample.png 원본 바이트를 그대로 전송합니다."
: calibrationMode
? "외곽 띠, 보조 테두리, 중앙 십자와 32px 눈금을 네 타일로 전송합니다."
: hybridHudMode
? "Canvas에는 정적 배경만 보이며, 실제 안경 문구는 네이티브 Text로 한 번에 전환됩니다."
: canvasHudMode
? "기본 뉴스 화면에서 아래 스크롤은 다음, 위 스크롤은 이전 페이지를 네 타일로 전송합니다."
: "이 Canvas가 네 장의 PNG로 나뉘어 안경에 순차 전송됩니다."}
</p>
</main>
);
}