Skip to content

Commit 092e6fe

Browse files
nicomiguelinoclaude
andcommitted
feat(peripheral-demo): add Raw Peripheral State card to maintenance view
- Install highlight.js for JSON syntax highlighting - Store last peripheral WebSocket message in module-level state - Add Raw Peripheral State glass card to maintenance screen - Render highlighted JSON via highlight.js (Monokai theme) on maintenance view load Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 86e5699 commit 092e6fe

File tree

8 files changed

+94
-2
lines changed

8 files changed

+94
-2
lines changed

edge-apps/peripheral-integration-demo/bun.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

edge-apps/peripheral-integration-demo/index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,30 @@
363363
</div>
364364
</div>
365365
</div>
366+
367+
<div class="glass-card glass-card--left">
368+
<div class="glass-card-heading">
369+
<svg
370+
class="glass-card-icon"
371+
width="48"
372+
height="48"
373+
viewBox="0 0 24 24"
374+
fill="none"
375+
stroke="currentColor"
376+
stroke-width="1.5"
377+
stroke-linecap="round"
378+
stroke-linejoin="round"
379+
>
380+
<polyline points="16 18 22 12 16 6" />
381+
<polyline points="8 6 2 12 8 18" />
382+
</svg>
383+
<span class="glass-card-title">Raw Peripheral State</span>
384+
</div>
385+
<pre
386+
id="maintenance-raw-state"
387+
class="maintenance-raw-state"
388+
><code class="language-json">No data yet</code></pre>
389+
</div>
366390
</div>
367391
</main>
368392

edge-apps/peripheral-integration-demo/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@
3131
"npm-run-all2": "^8.0.4",
3232
"prettier": "^3.8.1",
3333
"typescript": "^5.9.3"
34+
},
35+
"dependencies": {
36+
"highlight.js": "^11.11.1"
3437
}
3538
}

edge-apps/peripheral-integration-demo/src/core/screen.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@ import {
66
getTimeZone,
77
} from '@screenly/edge-apps'
88
import { Hardware } from '@screenly/edge-apps'
9+
import hljs from 'highlight.js/lib/core'
10+
import json from 'highlight.js/lib/languages/json'
911

10-
import { subscribe, getState, setScreen, type ScreenType } from './state'
12+
import {
13+
subscribe,
14+
getState,
15+
setScreen,
16+
type ScreenType,
17+
getLastPeripheralState,
18+
} from './state'
1119
import {
1220
waitForScreenDataPrepared,
1321
dispatchScreenDataPrepared,
1422
} from './screen-events'
1523
import { getNetworkStatus } from '../utils/network'
1624
import { updateOperatorDashboard } from '../features/operator-dashboard'
1725

26+
hljs.registerLanguage('json', json)
27+
1828
function delay(ms: number): Promise<void> {
1929
return new Promise((resolve) => setTimeout(resolve, ms))
2030
}
@@ -79,6 +89,14 @@ async function loadMaintenanceInfo() {
7989
} catch {
8090
getEl('maintenance-timezone').textContent = '—'
8191
}
92+
93+
const rawState = getLastPeripheralState()
94+
const codeEl = getEl('maintenance-raw-state').querySelector('code')!
95+
if (rawState) {
96+
codeEl.innerHTML = hljs.highlight(JSON.stringify(rawState, null, 2), {
97+
language: 'json',
98+
}).value
99+
}
82100
}
83101

84102
async function preloadScreenData(role: ScreenType): Promise<void> {

edge-apps/peripheral-integration-demo/src/core/state.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,13 @@ export function setSensorReadings(readings: {
6565
export function getState(): Readonly<AppState> {
6666
return { ...state }
6767
}
68+
69+
let lastPeripheralState: unknown = null
70+
71+
export function setLastPeripheralState(raw: unknown) {
72+
lastPeripheralState = raw
73+
}
74+
75+
export function getLastPeripheralState(): unknown {
76+
return lastPeripheralState
77+
}

edge-apps/peripheral-integration-demo/src/css/style.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,14 @@ auto-scaler {
370370

371371
/* Maintenance rows */
372372

373+
#screen-maintenance {
374+
flex: 1;
375+
}
376+
377+
#screen-maintenance .glass-card:last-child {
378+
flex: 0 1 auto;
379+
}
380+
373381
.maintenance-rows {
374382
display: flex;
375383
flex-direction: column;
@@ -425,3 +433,20 @@ auto-scaler {
425433
font-weight: 600;
426434
color: #e33876;
427435
}
436+
437+
.maintenance-raw-state {
438+
width: 100%;
439+
flex: 1;
440+
overflow: hidden;
441+
border-radius: 16px;
442+
font-size: 18px;
443+
line-height: 1.6;
444+
margin: 0;
445+
}
446+
447+
.maintenance-raw-state code {
448+
display: block;
449+
height: 100%;
450+
padding: 1.5rem;
451+
white-space: pre;
452+
}

edge-apps/peripheral-integration-demo/src/features/peripherals.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { createPeripheralClient } from '@screenly/edge-apps'
22
import type { PeripheralStateMessage } from '@screenly/edge-apps'
33

4-
import { getState, setSensorReadings } from '../core/state'
4+
import {
5+
getState,
6+
setSensorReadings,
7+
setLastPeripheralState,
8+
} from '../core/state'
59
import { showWelcomeThenSwitch } from '../core/screen'
610
import { restartLogoutTimer } from '../core/timer'
711
import { authenticate } from './authenticate'
@@ -14,6 +18,8 @@ export function initPeripherals() {
1418
client.register(edgeAppId)
1519

1620
client.watchState((msg: PeripheralStateMessage) => {
21+
setLastPeripheralState(msg.request.edge_app_source_state)
22+
1723
const readings = msg.request.edge_app_source_state.states
1824

1925
const tempReading = readings.find((r) => 'ambient_temperature' in r)

edge-apps/peripheral-integration-demo/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import './css/style.css'
2+
import 'highlight.js/styles/monokai.css'
23
import '@screenly/edge-apps/components'
34

45
import {

0 commit comments

Comments
 (0)