Sound effects demo, and music controller

This commit is contained in:
James Babcock committed 2026-07-07 21:21:02 -07:00
1 parent 5f82981b92
commit 56d0f8c351
13 files changed
+717 -145

No files matched your search

-74
View File
@@ -3,7 +3,6 @@ import { getDefaultSmallFont } from "../../graphics/bdffont";
import { GrayImage } from "../../graphics/image";
import { wrapText } from "../../graphics/textwrap";
import { mediaControllerBridge, type MediaControllerState } from "../../native/media-controller";
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
export class MusicControllerDashboardPlugin extends DashboardPlugin {
@@ -38,81 +37,8 @@ export class MusicControllerDashboardPlugin extends DashboardPlugin {
image.drawText(font, bounds.x + 10, bounds.y + bounds.height - 18, playbackLabel(media), 130);
}
override createFullscreenLayer(getState: () => DashboardPluginState): Layer {
return new MusicControllerLayer(getState);
}
}
class MusicControllerLayer implements Layer {
constructor(private readonly getState: () => DashboardPluginState) {}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(576, 288, 0);
const media = this.getState().media;
image.drawRect(12, 12, 552, 264, 52);
image.drawText(font, 22, 16, "Music controller", 220);
if (!media.accessEnabled) {
const lines = wrapText(
font,
"Notification access is required before Android will expose active media sessions to Faceclaw. Click to open settings.",
520,
);
for (let i = 0; i < lines.length; i++) {
image.drawText(font, 22, 44 + i * 14, lines[i]!, 180);
}
image.drawText(font, 22, 252, "Click: open settings Double-click: back", 110);
return image;
}
if (!media.available) {
image.drawText(font, 22, 44, "No active media session.", 180);
image.drawText(font, 22, 58, "Start playback in another app,", 180);
image.drawText(font, 22, 72, "then reopen this card.", 180);
image.drawText(font, 22, 252, "Double-click: back", 110);
return image;
}
image.drawText(font, 22, 44, media.title || "Unknown title", 220);
image.drawText(font, 22, 60, media.artist || media.album || "Unknown artist", 180);
image.drawText(font, 22, 76, media.packageName, 130);
image.drawText(font, 22, 104, `State: ${playbackLabel(media)}`, 180);
image.drawText(font, 22, 132, "Click: play/pause", 180);
image.drawText(font, 22, 146, "Scroll up: previous", 180);
image.drawText(font, 22, 160, "Scroll down: next", 180);
image.drawText(font, 22, 252, "Double-click: back", 110);
return image;
}
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
const media = this.getState().media;
switch (event.type) {
case "click":
if (!media.accessEnabled) {
mediaControllerBridge.openNotificationAccessSettings();
} else if (media.canPlayPause) {
await mediaControllerBridge.playPause();
}
return;
case "scroll-up":
if (media.canSkipPrevious) {
await mediaControllerBridge.skipPrevious();
}
return;
case "scroll-down":
if (media.canSkipNext) {
await mediaControllerBridge.skipNext();
}
return;
case "double-click":
ctx.stack.pop();
return;
default:
return;
}
}
}
function playbackLabel(media: MediaControllerState): string {
switch (media.playbackState) {