Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 减少远程桌面横屏键盘开合时的横移 (#4341)
Dasha28a8981dbf3
diff --git a/apps/mobile/src/remote-desktop/__tests__/viewer.test.ts b/apps/mobile/src/remote-desktop/__tests__/viewer.test.tsindex baabec655b..258e3fa8a4 100644--- a/apps/mobile/src/remote-desktop/__tests__/viewer.test.ts+++ b/apps/mobile/src/remote-desktop/__tests__/viewer.test.ts@@ -306,7 +306,9 @@ describe("remote desktop viewport", () => {expect(v.elements.image.style.width).toBe("400px");expect(parseFloat(v.elements.image.style.top)).toBeGreaterThan(0);});- it.each([1, 2])("keeps landscape scale %sx and centers the cursor above keyboard overlays", (scale) => {+ it.each([+ [1, .1], [1, .5], [1, .9], [2, .1], [2, .5], [2, .9],+ ])("keeps landscape scale %sx with minimal horizontal movement for cursor %s", (scale, cursorX) => {const v = viewer();v.elements.stage.clientWidth = 800;v.elements.stage.clientHeight = 400;@@ -322,20 +324,31 @@ describe("remote desktop viewport", () => {v.pointer("pointerup", 2, 500, 200);}v.send({ type: "frame", jpeg: "", cursor: {- x: .9, y: .85, width: 18, height: 18, hotX: 9, hotY: 9,+ x: cursorX, y: .85, width: 18, height: 18, hotX: 9, hotY: 9,visible: true, png: "iVBORw0KGgo=",} });+ v.send({ type: "mouseButtons", keyboardOpen: false, bottomInset: 0, leftInset: 50, rightInset: 80 });+ for (let i = 0; i < 30; i++) v.frame();const width = v.elements.image.style.width;expect(parseFloat(v.elements.image.style.height)).toBeCloseTo(400 * scale);+ // Removing the toolbar before the keyboard has a measured height must not shift the image.+ const originalLeft = v.elements.image.style.left;+ v.send({ type: "mouseButtons", keyboardOpen: true, bottomInset: 0, leftInset: 50, rightInset: 0 });+ expect(parseFloat(v.elements.image.style.left)).toBeCloseTo(parseFloat(originalLeft));// Header, computer keyboard, phone keyboard, and closing the keyboard.for (const bottomInset of [60, 260, 300, 0]) {- v.send({ type: "mouseButtons", keyboardOpen: bottomInset > 0, bottomInset, leftInset: 50, rightInset: 0 });+ const previousLeft = parseFloat(v.elements.image.style.left);+ const previousCursorX = previousLeft + cursorX * parseFloat(width);+ const rightInset = bottomInset > 0 ? 0 : 80;+ const expectedCursorX = Math.max(67, Math.min(800 - rightInset - 17, previousCursorX));+ v.send({ type: "mouseButtons", keyboardOpen: bottomInset > 0, bottomInset, leftInset: 50, rightInset });v.blur();for (let i = 0; i < 30; i++) v.frame();const image = v.elements.image.style;expect(image.width).toBe(width);expect(parseFloat(image.height)).toBeCloseTo(400 * scale);- expect(parseFloat(image.left) + .9 * parseFloat(image.width)).toBeCloseTo(425);+ expect(parseFloat(image.left) + cursorX * parseFloat(image.width)).toBeCloseTo(expectedCursorX);+ expect(parseFloat(image.left)).toBeCloseTo(previousLeft + expectedCursorX - previousCursorX);expect(parseFloat(image.top) + .85 * parseFloat(image.height)).toBeCloseTo((400 - bottomInset) / 2);}});@@ -345,6 +358,22 @@ describe("remote desktop viewport", () => {v.send({ type: "mouseButtons", keyboardOpen: true, bottomInset: 260 });expect(v.elements.image.style).toEqual(before);});+ it("preserves horizontal position when the keyboard closes before measurement", () => {+ const v = viewer();+ v.elements.stage.clientWidth = 800;+ v.elements.stage.clientHeight = 400;+ v.send({ type: "init", epoch: "quick-keyboard", width: 1920, height: 1080, fillHeight: true });+ v.send({ type: "mouseButtons", keyboardOpen: false, bottomInset: 0, leftInset: 50, rightInset: 80 });+ const before = { ...v.elements.image.style };+ for (let i = 0; i < 2; i++) {+ v.send({ type: "mouseButtons", keyboardOpen: true, bottomInset: 0, leftInset: 50, rightInset: 0 });+ v.send({ type: "mouseButtons", keyboardOpen: false, bottomInset: 0, leftInset: 50, rightInset: 80 });+ expect(v.elements.image.style).toEqual(before);+ v.blur();+ for (let j = 0; j < 30; j++) v.frame();+ expect(v.elements.image.style).toEqual(before);+ }+ });it("initializes when the native engine cannot serialize function source", () => {const stringify = vi.spyOn(Function.prototype, "toString")diff --git a/apps/mobile/src/remote-desktop/viewerHtml.ts b/apps/mobile/src/remote-desktop/viewerHtml.tsindex 23baf5fe24..b4939a9607 100644--- a/apps/mobile/src/remote-desktop/viewerHtml.ts+++ b/apps/mobile/src/remote-desktop/viewerHtml.ts@@ -86,6 +86,7 @@ const VIEWER_SCRIPT = String.raw`const clamp=(v)=>Math.max(0,Math.min(1,v));let fillHeight=false;let panAnimation=null,viewportRightInset=0,viewportLeftInset=0,viewportBottomInset=0,keyboardViewportInset=0;+ let keyboardViewportOpen=false;let cursorNeedsEntry=true,manualViewMoved=false,followRest=null;// Insets guide centering and pan limits without clipping the full-screen// video surface or adding an opaque strip beside the Dynamic Island.@@ -312,16 +313,35 @@ const VIEWER_SCRIPT = String.raw`case 'resume':if(video.srcObject)video.play().catch(()=>{});break;case 'releaseInput':release();break;case 'theme':if(/^#[0-9a-f]{3,8}$/i.test(message.surface)){document.body.style.background=message.surface;document.documentElement.style.background=message.surface;document.documentElement.style.setProperty('--surface',message.surface);}if(/^#[0-9a-f]{3,8}$/i.test(message.foreground)){cursor.style.borderColor=message.foreground;document.documentElement.style.setProperty('--foreground',message.foreground);}break;- case 'mouseButtons':if(Number.isFinite(message.bottomInset))viewportBottomInset=Math.max(0,Math.min(stage.clientHeight-1,message.bottomInset));if(Number.isFinite(message.leftInset)){const left=Math.max(0,Math.min(stage.clientWidth-1,message.leftInset));if(left!==viewportLeftInset){viewportLeftInset=left;settlePan();render();}}if(Number.isFinite(message.rightInset)){const inset=Math.max(0,Math.min(stage.clientWidth-1,message.rightInset));if(inset!==viewportRightInset){viewportRightInset=inset;settlePan();render();}}const keyboardInset=fillHeight&&message.keyboardOpen===true?viewportBottomInset:0;+ case 'mouseButtons':{+ const before=layout(),keyboardOpen=fillHeight&&message.keyboardOpen===true;+ const keepHorizontal=fillHeight&&(keyboardOpen||keyboardViewportOpen);+ // Opening is observable before the native keyboard has a measured height.+ keyboardViewportOpen=keyboardOpen;+ let sideInsetsChanged=false;+ if(Number.isFinite(message.bottomInset))viewportBottomInset=Math.max(0,Math.min(stage.clientHeight-1,message.bottomInset));+ if(Number.isFinite(message.leftInset)){const inset=Math.max(0,Math.min(stage.clientWidth-1,message.leftInset));sideInsetsChanged=sideInsetsChanged||inset!==viewportLeftInset;viewportLeftInset=inset;}+ if(Number.isFinite(message.rightInset)){const inset=Math.max(0,Math.min(stage.clientWidth-1,message.rightInset));sideInsetsChanged=sideInsetsChanged||inset!==viewportRightInset;viewportRightInset=inset;}+ // Hiding the side toolbar changes the viewport center. Keep the image's+ // actual horizontal position instead of following that center sideways.+ if(keepHorizontal){stopPanAnimation();const r=layout();place(before.x,r.y,r);}+ const keyboardInset=keyboardOpen?viewportBottomInset:0;if(keyboardInset!==keyboardViewportInset){const wasOpen=keyboardViewportInset>0;keyboardViewportInset=keyboardInset;if(fillHeight&&(keyboardInset>0||wasOpen)){- stopPanAnimation();const r=layout(),v=cursorViewport();- place((v.minX+v.maxX)/2-cx*r.width,(v.minY+v.maxY)/2-cy*r.height,r);- followRest={fx,fy,zoom};cursorNeedsEntry=false;manualViewMoved=false;render();+ const r=layout(),v=cursorViewport();+ place(r.x,(v.minY+v.maxY)/2-cy*r.height,r);+ cursorNeedsEntry=false;manualViewMoved=false;}}+ if(keepHorizontal){+ // Restoring the toolbar can cover the cursor even after a zero-height opening.+ if(!keyboardOpen||keyboardInset>0){const r=layout(),v=cursorViewport(),x=r.x+cx*r.width;place(r.x+bounded(x,v.minX,v.maxX)-x,r.y,r);}+ followRest={fx,fy,zoom};render();+ }+ else if(sideInsetsChanged){settlePan();render();}if(!message.enabled){for(const button of heldMouse.keys())queue({kind:'button',button,down:false,x:cx,y:cy});heldMouse.clear();resetWheel();flush();}for(const [edge,value] of [['bottom',message.bottomInset],['right',message.rightInset]])if(Number.isFinite(value)&&value>=0&&value<=4096)mouseButtons.style[edge]=value+'px';showMouseButtons=message.enabled===true;for(const name of ['left','right','wheel'])if(typeof message.labels?.[name]==='string')document.getElementById('mouse-'+name).setAttribute('aria-label',message.labels[name]);updateMouseButtons();break;+ }case 'init':followRest=null;cursorNeedsEntry=true;stopPanAnimation();resetCursor();control=false;release();pending=[];sending=false;seq=0;epoch=message.epoch;dw=message.width;dh=message.height;fillHeight=message.fillHeight===true;video.muted=!message.audio;trickleIce=message.trickleIce===true;retries=0;render();connect();break;case 'viewport':fillHeight=message.fillHeight===true;release();render();break;case 'answer':if(message.epoch===epoch)void receiveAnswer(message);break;