tkadkghdlf commited on
Commit
7d7998b
ยท
verified ยท
1 Parent(s): 9a65a94

Sync DemoService a52863f711870ea20565d7cf9f3bb3d0973f8aa3

Browse files
main/app/_components/AppLayout.tsx CHANGED
@@ -117,7 +117,7 @@ export default function AppLayout({ children }: { children: React.ReactNode }) {
117
  exit={{ opacity: 0 }}
118
  transition={motionPresets.page}
119
  >
120
- <TopBar title="Run The Shape" />
121
  </motion.div>
122
  ) : null}
123
  </AnimatePresence>
 
117
  exit={{ opacity: 0 }}
118
  transition={motionPresets.page}
119
  >
120
+ <TopBar title="Run The Shape" showWearableStatus={pathname === "/lobby"} />
121
  </motion.div>
122
  ) : null}
123
  </AnimatePresence>
main/app/_components/TopBar.tsx CHANGED
@@ -13,6 +13,7 @@ import {
13
  } from "../_utils/profileImage";
14
 
15
  import { initializeNativeWearBridge } from "../_utils/nativeWearBridge";
 
16
 
17
  interface TopBarProps {
18
  homeHref?: string;
@@ -20,6 +21,7 @@ interface TopBarProps {
20
  userName?: string;
21
  largeBrand?: boolean;
22
  onMenuClick?: () => void;
 
23
  }
24
 
25
  const HEADER_HEIGHT = 72;
@@ -87,6 +89,7 @@ const TopBar = forwardRef<HTMLElement, TopBarProps>(
87
  userName,
88
  largeBrand = false,
89
  onMenuClick,
 
90
  },
91
  ref,
92
  ) => {
@@ -190,6 +193,8 @@ const TopBar = forwardRef<HTMLElement, TopBarProps>(
190
  </h1>
191
  </Link>
192
 
 
 
193
  {/* ๋ฉ”๋‰ด ๋ฒ„ํŠผ */}
194
  {onMenuClick && (
195
  <button
 
13
  } from "../_utils/profileImage";
14
 
15
  import { initializeNativeWearBridge } from "../_utils/nativeWearBridge";
16
+ import WearableConnectionStatus from "./WearableConnectionStatus";
17
 
18
  interface TopBarProps {
19
  homeHref?: string;
 
21
  userName?: string;
22
  largeBrand?: boolean;
23
  onMenuClick?: () => void;
24
+ showWearableStatus?: boolean;
25
  }
26
 
27
  const HEADER_HEIGHT = 72;
 
89
  userName,
90
  largeBrand = false,
91
  onMenuClick,
92
+ showWearableStatus = false,
93
  },
94
  ref,
95
  ) => {
 
193
  </h1>
194
  </Link>
195
 
196
+ {showWearableStatus && <WearableConnectionStatus />}
197
+
198
  {/* ๋ฉ”๋‰ด ๋ฒ„ํŠผ */}
199
  {onMenuClick && (
200
  <button
main/app/_components/WearableConnectionStatus.tsx CHANGED
@@ -1,6 +1,6 @@
1
  "use client";
2
 
3
- import { useCallback, useEffect, useState } from "react";
4
  import { hasNativeWearBridge, initializeNativeWearBridge, isNativeAppEnvironment, readNativeWearDeviceStatus, reconnectNativeWearBridge, requestNativeWearDeviceStatus, type NativeWearDeviceStatus } from "../_utils/nativeWearBridge";
5
  import { wearConnectionState } from "../_utils/wearConnectionState";
6
 
@@ -13,6 +13,7 @@ function createStatusRequestId(): string {
13
  }
14
 
15
  export default function WearableConnectionStatus() {
 
16
  const [status, setStatus] = useState<NativeWearDeviceStatus | null>(null);
17
  const [nativeApp, setNativeApp] = useState(false);
18
  const [now, setNow] = useState(0);
@@ -41,10 +42,15 @@ export default function WearableConnectionStatus() {
41
  useEffect(() => {
42
  const update = () => { setStatus(readNativeWearDeviceStatus()); setNow(Date.now()); };
43
  const visible = () => { if (document.visibilityState === "visible") refresh(); };
 
 
 
 
44
  window.addEventListener("nativeWearDeviceStatusChanged", update);
45
  window.addEventListener("nativeWearBridgeReady", refresh);
46
  window.addEventListener("focus", refresh);
47
  document.addEventListener("visibilitychange", visible);
 
48
  refresh();
49
  const retry = window.setInterval(poll, 3000);
50
  const clock = window.setInterval(() => {
@@ -57,6 +63,7 @@ export default function WearableConnectionStatus() {
57
  window.clearInterval(retry);
58
  window.clearInterval(clock);
59
  document.removeEventListener("visibilitychange", visible);
 
60
  };
61
  }, [refresh, poll]);
62
 
@@ -68,7 +75,7 @@ export default function WearableConnectionStatus() {
68
  ? "bridge-unavailable"
69
  : wearConnectionState(bridgeAvailable && (!requestId || status?.requestId === requestId) ? status : null, now, requestedAt);
70
  const connected = state === "connected" || state === "device-connected";
71
- const paired = state === "paired";
72
  const names = status?.devices.filter((device) => device.connectionState === "connected").map((device) => device.displayName).join(", ") || status?.devices.map((device) => device.displayName).join(", ");
73
  const labels = {
74
  "query-error": ["์›Œ์น˜ ์กฐํšŒ ์‹คํŒจ", "ํœด๋Œ€ํฐ ์•ฑ์˜ ์‘๋‹ต์€ ๋ฐ›์•˜์ง€๋งŒ Wear OS ์—ฐ๊ฒฐ ์กฐํšŒ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ์ž ์‹œ ํ›„ ์ƒˆ๋กœ๊ณ ์นจํ•ด ์ฃผ์„ธ์š”."],
@@ -86,11 +93,29 @@ export default function WearableConnectionStatus() {
86
  };
87
  const [title, detail] = labels[state];
88
 
89
- return <section className="rounded-2xl border border-[#e5e5e5] bg-[#fafafa] px-4 py-3 shadow-sm" aria-live="polite">
90
- <div className="flex items-center justify-between gap-3">
91
- <div className="flex min-w-0 items-center gap-2"><span className={`h-2.5 w-2.5 shrink-0 rounded-full ${connected ? "bg-[#18a957]" : paired ? "bg-[#e9a23b]" : "bg-[#a3a3a3]"}`} /><div><p className="text-sm font-semibold text-black">{title}</p><p className="mt-0.5 text-xs text-[#525252]">{detail}</p></div></div>
92
- <button type="button" onClick={state === "bridge-unavailable" ? reconnectNativeWearBridge : refresh} className="shrink-0 rounded-lg border border-black/10 bg-white px-2.5 py-1.5 text-xs font-semibold text-[#111111]">{state === "bridge-unavailable" ? "์•ฑ ํ†ต์‹  ๋ณต๊ตฌ" : "์ƒˆ๋กœ๊ณ ์นจ"}</button>
93
- </div>
94
- {status?.sessionActive && <p className="mt-2 text-xs text-[#525252]">ํ˜„์žฌ ๋Ÿฌ๋‹ ์„ธ์…˜ ์›Œ์น˜ ์ˆ˜์‹ : {status.sessionReceived ? "ํ™•์ธ๋จ" : "์•„์ง ํ™•์ธ๋˜์ง€ ์•Š์Œ"}</p>}
95
- </section>;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
 
1
  "use client";
2
 
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
  import { hasNativeWearBridge, initializeNativeWearBridge, isNativeAppEnvironment, readNativeWearDeviceStatus, reconnectNativeWearBridge, requestNativeWearDeviceStatus, type NativeWearDeviceStatus } from "../_utils/nativeWearBridge";
5
  import { wearConnectionState } from "../_utils/wearConnectionState";
6
 
 
13
  }
14
 
15
  export default function WearableConnectionStatus() {
16
+ const disclosure = useRef<HTMLDetailsElement>(null);
17
  const [status, setStatus] = useState<NativeWearDeviceStatus | null>(null);
18
  const [nativeApp, setNativeApp] = useState(false);
19
  const [now, setNow] = useState(0);
 
42
  useEffect(() => {
43
  const update = () => { setStatus(readNativeWearDeviceStatus()); setNow(Date.now()); };
44
  const visible = () => { if (document.visibilityState === "visible") refresh(); };
45
+ const dismissOutside = (event: PointerEvent) => {
46
+ const element = disclosure.current;
47
+ if (element?.open && event.target instanceof Node && !element.contains(event.target)) element.open = false;
48
+ };
49
  window.addEventListener("nativeWearDeviceStatusChanged", update);
50
  window.addEventListener("nativeWearBridgeReady", refresh);
51
  window.addEventListener("focus", refresh);
52
  document.addEventListener("visibilitychange", visible);
53
+ document.addEventListener("pointerdown", dismissOutside);
54
  refresh();
55
  const retry = window.setInterval(poll, 3000);
56
  const clock = window.setInterval(() => {
 
63
  window.clearInterval(retry);
64
  window.clearInterval(clock);
65
  document.removeEventListener("visibilitychange", visible);
66
+ document.removeEventListener("pointerdown", dismissOutside);
67
  };
68
  }, [refresh, poll]);
69
 
 
75
  ? "bridge-unavailable"
76
  : wearConnectionState(bridgeAvailable && (!requestId || status?.requestId === requestId) ? status : null, now, requestedAt);
77
  const connected = state === "connected" || state === "device-connected";
78
+ const knownDisconnected = state === "disconnected" || state === "bluetooth-off";
79
  const names = status?.devices.filter((device) => device.connectionState === "connected").map((device) => device.displayName).join(", ") || status?.devices.map((device) => device.displayName).join(", ");
80
  const labels = {
81
  "query-error": ["์›Œ์น˜ ์กฐํšŒ ์‹คํŒจ", "ํœด๋Œ€ํฐ ์•ฑ์˜ ์‘๋‹ต์€ ๋ฐ›์•˜์ง€๋งŒ Wear OS ์—ฐ๊ฒฐ ์กฐํšŒ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ์ž ์‹œ ํ›„ ์ƒˆ๋กœ๊ณ ์นจํ•ด ์ฃผ์„ธ์š”."],
 
93
  };
94
  const [title, detail] = labels[state];
95
 
96
+ return <details ref={disclosure} className="relative ml-auto shrink-0" onKeyDown={(event) => {
97
+ if (event.key !== "Escape" || !disclosure.current?.open) return;
98
+ disclosure.current.open = false;
99
+ disclosure.current.querySelector("summary")?.focus();
100
+ }}>
101
+ <summary
102
+ aria-label={`์›Œ์น˜ ์—ฐ๊ฒฐ ์ƒํƒœ: ${title}`}
103
+ className="relative grid h-11 w-11 cursor-pointer list-none place-items-center rounded-md text-[#16211b] hover:bg-black/5 focus-visible:outline focus-visible:outline-2 [&::-webkit-details-marker]:hidden"
104
+ >
105
+ <svg aria-hidden="true" width="27" height="27" viewBox="0 0 28 28" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
106
+ <path d="m10 7 1-3h6l1 3m-8 14 1 3h6l1-3" />
107
+ <circle cx="14" cy="14" r="7.8" />
108
+ {!connected && <path d="M4 4 24 24" />}
109
+ </svg>
110
+ <span aria-hidden="true" className={`pointer-events-none absolute right-1 top-1 h-3 w-3 rounded-full border-2 border-white ${connected ? "bg-[#16a34a]" : knownDisconnected ? "bg-[#dc2626]" : "bg-[#737373]"}`} />
111
+ </summary>
112
+ <section className="absolute right-0 top-full mt-2 w-[min(18rem,calc(100vw-2rem))] rounded-2xl border border-black/10 bg-white p-3 shadow-lg" aria-label="์›Œ์น˜ ์—ฐ๊ฒฐ ์ƒ์„ธ">
113
+ <div aria-live="polite">
114
+ <p className="text-sm font-semibold text-black">{title}</p>
115
+ <p className="mt-1 text-xs leading-relaxed text-[#525252]">{detail}</p>
116
+ {status?.sessionActive && <p className="mt-2 text-xs text-[#525252]">ํ˜„์žฌ ๋Ÿฌ๋‹ ์„ธ์…˜ ์›Œ์น˜ ์ˆ˜์‹ : {status.sessionReceived ? "ํ™•์ธ๋จ" : "์•„์ง ํ™•์ธ๋˜์ง€ ์•Š์Œ"}</p>}
117
+ </div>
118
+ <button type="button" onClick={state === "bridge-unavailable" ? reconnectNativeWearBridge : refresh} className="mt-3 rounded-lg border border-black/10 bg-white px-2.5 py-1.5 text-xs font-semibold text-[#111111]">{state === "bridge-unavailable" ? "์•ฑ ํ†ต์‹  ๋ณต๊ตฌ" : "์ƒˆ๋กœ๊ณ ์นจ"}</button>
119
+ </section>
120
+ </details>;
121
  }
main/app/lobby/page.tsx CHANGED
@@ -3,7 +3,6 @@
3
  import { useEffect, useState } from "react";
4
  import { useRouter } from "next/navigation";
5
  import LeafletMap from "../_components/LeafletMap";
6
- import WearableConnectionStatus from "../_components/WearableConnectionStatus";
7
  import MotionDialog from "../_components/MotionDialog";
8
  import { FLOW_KEYS, issueUiFlowPermit } from "../_utils/uiFlowGuard";
9
  import { requestNativeAppExit } from "../_utils/nativeWearBridge";
@@ -821,10 +820,6 @@ export default function Page() {
821
  }}
822
  >
823
  <section className="relative mx-auto flex min-h-[calc(100dvh-164px)] w-full max-w-none flex-col gap-3 overflow-y-auto px-4 pb-6 pt-4 max-[700px]:gap-3 max-[700px]:pb-6 max-[700px]:pt-4 md:max-w-3xl md:px-6 lg:grid lg:max-w-6xl lg:grid-cols-[minmax(0,1.15fr)_minmax(360px,0.85fr)] lg:content-start lg:items-start lg:gap-6 lg:px-8 lg:py-6">
824
- <div className="lg:col-span-2">
825
- <WearableConnectionStatus />
826
- </div>
827
-
828
  <section className="relative rounded-[22px] border border-white/75 bg-white/74 p-3 shadow-[0_12px_28px_rgba(27,54,42,0.12)] backdrop-blur-md lg:p-6">
829
  <div className="flex min-h-[64px] items-start justify-between gap-4">
830
  <div className="min-w-0">
 
3
  import { useEffect, useState } from "react";
4
  import { useRouter } from "next/navigation";
5
  import LeafletMap from "../_components/LeafletMap";
 
6
  import MotionDialog from "../_components/MotionDialog";
7
  import { FLOW_KEYS, issueUiFlowPermit } from "../_utils/uiFlowGuard";
8
  import { requestNativeAppExit } from "../_utils/nativeWearBridge";
 
820
  }}
821
  >
822
  <section className="relative mx-auto flex min-h-[calc(100dvh-164px)] w-full max-w-none flex-col gap-3 overflow-y-auto px-4 pb-6 pt-4 max-[700px]:gap-3 max-[700px]:pb-6 max-[700px]:pt-4 md:max-w-3xl md:px-6 lg:grid lg:max-w-6xl lg:grid-cols-[minmax(0,1.15fr)_minmax(360px,0.85fr)] lg:content-start lg:items-start lg:gap-6 lg:px-8 lg:py-6">
 
 
 
 
823
  <section className="relative rounded-[22px] border border-white/75 bg-white/74 p-3 shadow-[0_12px_28px_rgba(27,54,42,0.12)] backdrop-blur-md lg:p-6">
824
  <div className="flex min-h-[64px] items-start justify-between gap-4">
825
  <div className="min-w-0">
main/tests/nativeAppVisibility.cjs CHANGED
@@ -33,10 +33,10 @@ assert.equal(environment({ referrer: 'android-app://other.app/' }), false);
33
 
34
  const quality = load('app/_utils/wearConnectionState.ts', {});
35
  function card({ nativeApp, bridge, status = null, now = 30000, requestedAt = 10000 }) {
36
- const states = [status, nativeApp, now, requestedAt];
37
  const component = load('app/_components/WearableConnectionStatus.tsx', {
38
  require: name => name === 'react'
39
- ? { ...React, useState: () => [states.shift(), () => {}], useCallback: fn => fn, useEffect() {} }
40
  : name.includes('nativeWearBridge') ? { hasNativeWearBridge: () => bridge }
41
  : name.includes('wearConnectionState') ? quality : require(name),
42
  }).default;
@@ -47,7 +47,13 @@ assert.match(card({ nativeApp: true, bridge: false }), /์•ฑ ํ†ต์‹  ์—ฐ๊ฒฐ ํ•„์š”
47
  const connected = { connected: true, devices: [], updatedAt: 30000 };
48
  assert.doesNotMatch(card({ nativeApp: true, bridge: false, status: connected }), /์›Œ์น˜ ์—ฐ๊ฒฐ๋จ/);
49
  assert.match(card({ nativeApp: true, bridge: false, now: 15000 }), /์›Œ์น˜ ์—ฐ๊ฒฐ ํ™•์ธ ์ค‘/);
50
- assert.match(card({ nativeApp: true, bridge: true, status: connected }), /์›Œ์น˜ ์—ฐ๊ฒฐ๋จ/);
 
 
 
51
  assert.match(card({ nativeApp: true, bridge: true }), /์›Œ์น˜ ์ƒํƒœ ํ™•์ธ ๋ถˆ๊ฐ€/);
52
- assert.match(card({ nativeApp: true, bridge: true, status: { ...connected, connected: false } }), /์›Œ์น˜ ์—ฐ๊ฒฐ ์•ˆ ๋จ/);
 
 
 
53
  console.log('PASS: 7 app identity and 7 card visibility/status scenarios');
 
33
 
34
  const quality = load('app/_utils/wearConnectionState.ts', {});
35
  function card({ nativeApp, bridge, status = null, now = 30000, requestedAt = 10000 }) {
36
+ const states = [status, nativeApp, now, requestedAt, ''];
37
  const component = load('app/_components/WearableConnectionStatus.tsx', {
38
  require: name => name === 'react'
39
+ ? { ...React, useRef: current => ({ current }), useState: () => [states.shift(), () => {}], useCallback: fn => fn, useEffect() {} }
40
  : name.includes('nativeWearBridge') ? { hasNativeWearBridge: () => bridge }
41
  : name.includes('wearConnectionState') ? quality : require(name),
42
  }).default;
 
47
  const connected = { connected: true, devices: [], updatedAt: 30000 };
48
  assert.doesNotMatch(card({ nativeApp: true, bridge: false, status: connected }), /์›Œ์น˜ ์—ฐ๊ฒฐ๋จ/);
49
  assert.match(card({ nativeApp: true, bridge: false, now: 15000 }), /์›Œ์น˜ ์—ฐ๊ฒฐ ํ™•์ธ ์ค‘/);
50
+ const connectedIcon = card({ nativeApp: true, bridge: true, status: connected });
51
+ assert.match(connectedIcon, /์›Œ์น˜ ์—ฐ๊ฒฐ๋จ/);
52
+ assert.ok(connectedIcon.includes('bg-[#16a34a]'));
53
+ assert.doesNotMatch(connectedIcon, /M4 4 24 24/);
54
  assert.match(card({ nativeApp: true, bridge: true }), /์›Œ์น˜ ์ƒํƒœ ํ™•์ธ ๋ถˆ๊ฐ€/);
55
+ const disconnectedIcon = card({ nativeApp: true, bridge: true, status: { ...connected, connected: false } });
56
+ assert.match(disconnectedIcon, /์›Œ์น˜ ์—ฐ๊ฒฐ ์•ˆ ๋จ/);
57
+ assert.ok(disconnectedIcon.includes('bg-[#dc2626]'));
58
+ assert.match(disconnectedIcon, /M4 4 24 24/);
59
  console.log('PASS: 7 app identity and 7 card visibility/status scenarios');