feat(harmony): add screen viewing and control with USB reconnection recovery

This commit is contained in:
2026-09-10 14:15:43 +08:00
parent 44d8cf5c92
commit 170ea4d112
26 changed files with 2085 additions and 26 deletions
+68 -1
View File
@@ -61,13 +61,80 @@ const entries = [
modified: 1788998400,
},
];
let screenId = 0,
screenSequence = 0,
screenControl = false;
let lastInput = "等待操作";
function screenFrame() {
if (!attached) throw new Error("设备已断开(模拟)");
const canvas = document.createElement("canvas");
canvas.width = 600;
canvas.height = 1200;
const context = canvas.getContext("2d");
const gradient = context.createLinearGradient(0, 0, 600, 1200);
gradient.addColorStop(0, "#183958");
gradient.addColorStop(1, "#3d1d52");
context.fillStyle = gradient;
context.fillRect(0, 0, 600, 1200);
context.fillStyle = "#fff";
context.textAlign = "center";
context.font = "bold 70px sans-serif";
context.fillText("Harmony", 300, 260);
context.font = "26px sans-serif";
context.fillText("投屏界面预览 · 模拟画面", 300, 320);
context.fillStyle = "#e9dcff";
context.fillText(lastInput, 300, 600, 550);
context.fillText(`画面 ${++screenSequence}`, 300, 670);
context.fillStyle = "#fff";
context.fillRect(225, 1150, 150, 6);
return {
dataUrl: canvas.toDataURL("image/jpeg", 0.8),
width: 600,
height: 1200,
geometry: 1,
sequence: screenSequence,
captureMs: 180,
control: screenControl,
};
}
window.__TROVE_CONTEXT__ = {
curioId: "dev.trove.harmony-connector",
version: "0.2.0",
version: "0.3.0",
instanceId: "ui-fixture",
platform: "macos",
};
window.__TROVE_BRIDGE__ = createMockBridge({
"@self.hdc.screenStart": () => {
screenControl = false;
return {
session: ++screenId,
control: false,
inputCapabilities: [
"click",
"doubleClick",
"longClick",
"swipe",
"drag",
"text",
"keyEvent",
],
};
},
"@self.hdc.screenFrame": screenFrame,
"@self.hdc.screenStop": () => ({ stopped: true }),
"@self.hdc.screenControl": ({ enabled }) => ({
control: (screenControl = enabled),
}),
"@self.hdc.screenInput": ({ input }) => {
lastInput =
input.kind === "text"
? input.text
: input.kind === "key"
? input.key
: `${input.kind} · ${input.x}, ${input.y}`;
return { executed: true };
},
"@self.hdc.screenSave": () => ({ path: "/ui-fixture/screen.jpg" }),
"@self.hdc.status": () => ({ busy: false, job: null }),
"@self.hdc.tool": () => ({
available: true,