Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions miniapps/dev-hud/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {copyFile, rm} from "fs/promises"
import {reactSingletonPlugin} from "@mentra/miniapp-cli/build-helpers"

const distDir = "./dist"

await rm(distDir, {recursive: true, force: true})

const define: Record<string, string> = {}
for (const [key, value] of Object.entries(process.env)) {
if (key.startsWith("MENTRA_PUBLIC_") && typeof value === "string") {
define[`process.env.${key}`] = JSON.stringify(value)
}
}

const backgroundResult = await Bun.build({
entrypoints: ["./src/background/index.ts"],
outdir: `${distDir}/background`,
target: "browser",
format: "iife",
minify: false,
define,
})
if (!backgroundResult.success) {
console.error("Background build failed:")
for (const log of backgroundResult.logs) console.error(log)
process.exit(1)
}

const tailwind = (await import("bun-plugin-tailwind")).default
const uiResult = await Bun.build({
entrypoints: ["./src/ui/index.html"],
outdir: `${distDir}/ui`,
target: "browser",
plugins: [tailwind, reactSingletonPlugin(import.meta.url)],
minify: true,
define,
})
if (!uiResult.success) {
console.error("UI build failed:")
for (const log of uiResult.logs) console.error(log)
process.exit(1)
}

await copyFile("./miniapp.json", `${distDir}/miniapp.json`)
await copyFile("./icon.png", `${distDir}/icon.png`)

console.log("built dev-hud -> dist/background/index.js + dist/ui + dist/icon.png + dist/miniapp.json")
Binary file added miniapps/dev-hud/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions miniapps/dev-hud/miniapp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "./node_modules/@mentra/miniapp-cli/schema/miniapp.schema.json",
"packageName": "com.mentra.dev-hud",
"version": "0.1.0",
"name": "Dev HUD",
"description": "Local development status HUD for GitHub PRs and Codex threads.",
"type": "background",
"sdkVersion": "0.3.0",
"minHostVersion": "1.42.0",
"port": 3148,
"entry": {
"background": "background/index.js",
"ui": "ui/index.html"
},
"permissions": [],
"hardwareRequirements": [
{
"type": "DISPLAY",
"level": "REQUIRED",
"description": "Shows GitHub and Codex development status on glasses"
}
],
"icon": "icon.png"
}
27 changes: 27 additions & 0 deletions miniapps/dev-hud/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "dev-hud",
"private": true,
"description": "Local MentraOS miniapp for GitHub PR and Codex thread status on glasses",
"scripts": {
"dev": "bun scripts/dev.ts",
"miniapp:dev": "mentra-miniapp dev",
"sidecar:dev": "bun --watch sidecar/index.ts",
"sidecar:start": "bun sidecar/index.ts",
"build": "bun run build.ts",
"pack": "mentra-miniapp pack"
},
"dependencies": {
"@mentra/miniapp": "workspace:*",
"lucide-react": "^0.511.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tailwindcss": "^4.0.8"
},
"devDependencies": {
"@mentra/miniapp-cli": "workspace:*",
"@types/bun": "^1.3.14",
"@types/react": "^19.1.6",
"@types/react-dom": "^19.1.6",
"bun-plugin-tailwind": "^0.1.2"
}
}
71 changes: 71 additions & 0 deletions miniapps/dev-hud/scripts/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {networkInterfaces} from "os"
import {join} from "path"

const root = join(import.meta.dir, "..")
const port = process.env.DEV_HUD_PORT ?? "3147"
const endpoint = process.env.MENTRA_PUBLIC_DEV_HUD_ENDPOINT ?? `http://${localIpAddress() ?? "127.0.0.1"}:${port}`

console.log(`[dev-hud] endpoint for phone/glasses: ${endpoint}`)
console.log("[dev-hud] starting sidecar and miniapp dev server")

const children: Bun.Subprocess[] = []

const sidecar = spawn("sidecar", ["bun", "--watch", "sidecar/index.ts"], {
DEV_HUD_PORT: port,
DEV_HUD_PUBLIC_ENDPOINT: endpoint,
})

await Bun.sleep(500)

const miniapp = spawn("miniapp", ["bun", "run", "miniapp:dev"], {
MENTRA_PUBLIC_DEV_HUD_ENDPOINT: endpoint,
})

const cleanup = () => {
for (const child of children) {
try {
child.kill()
} catch {
/* ignore */
}
}
}

process.on("SIGINT", () => {
cleanup()
process.exit(130)
})
process.on("SIGTERM", () => {
cleanup()
process.exit(143)
})

const exitCode = await Promise.race([sidecar.exited, miniapp.exited])
cleanup()
process.exit(exitCode ?? 0)

function spawn(name: string, command: string[], env: Record<string, string>): Bun.Subprocess {
console.log(`[dev-hud] ${name}: ${command.join(" ")}`)
const child = Bun.spawn(command, {
cwd: root,
env: {...process.env, ...env},
stdout: "inherit",
stderr: "inherit",
stdin: "inherit",
})
children.push(child)
return child
}

function localIpAddress(): string | null {
const nets = networkInterfaces()
for (const name of ["en0", "en1", "bridge100"]) {
const found = nets[name]?.find((entry) => entry.family === "IPv4" && !entry.internal)
if (found) return found.address
}
for (const entries of Object.values(nets)) {
const found = entries?.find((entry) => entry.family === "IPv4" && !entry.internal)
if (found) return found.address
}
return null
}
Loading