-
-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demo): use tabby as terminal emulator (#541)
- Loading branch information
Showing
51 changed files
with
2,429 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
export * from './command-bar'; | ||
export * from './connect'; | ||
export * from './demo-mode-panel'; | ||
export * from './device-view'; | ||
export * from './error-dialog'; | ||
export * from './external-link'; | ||
export * from './grid'; | ||
export * from './hex-viewer'; | ||
export * from "./command-bar"; | ||
export * from "./connect"; | ||
export * from "./demo-mode-panel"; | ||
export * from "./device-view"; | ||
export * from "./error-dialog"; | ||
export * from "./external-link"; | ||
export * from "./grid"; | ||
export * from "./hex-viewer"; | ||
export * from "./list-selection"; | ||
export * from './log-view'; | ||
export * from './resize-observer'; | ||
export * from "./log-view"; | ||
export * from "./resize-observer"; | ||
export * from "./tabby-frame-manager"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { AdbProxyServer } from "@yume-chan/adb-backend-proxy"; | ||
import { autorun } from "mobx"; | ||
import getConfig from "next/config"; | ||
import { GLOBAL_STATE } from "../state"; | ||
|
||
let proxy: AdbProxyServer | undefined; | ||
let resizeObserver: ResizeObserver | undefined; | ||
let frame: HTMLIFrameElement | undefined; | ||
|
||
function syncDevice() { | ||
if (proxy) { | ||
proxy.dispose(); | ||
proxy = undefined; | ||
} | ||
|
||
if (GLOBAL_STATE.device && frame) { | ||
const proxy = new AdbProxyServer(GLOBAL_STATE.device); | ||
const info = proxy.createPort(); | ||
frame.contentWindow?.postMessage( | ||
{ | ||
type: "adb", | ||
...info, | ||
}, | ||
"*", | ||
[info.port] | ||
); | ||
} | ||
} | ||
|
||
export function attachTabbyFrame(container: HTMLDivElement | null) { | ||
if (container === null) { | ||
if (resizeObserver !== undefined) { | ||
resizeObserver.disconnect(); | ||
} | ||
if (frame !== undefined) { | ||
frame.style.visibility = "hidden"; | ||
} | ||
return; | ||
} | ||
|
||
if (!frame) { | ||
const { | ||
publicRuntimeConfig: { basePath }, | ||
} = getConfig(); | ||
|
||
frame = document.createElement("iframe"); | ||
frame.src = `${basePath}/tabby-frame`; | ||
frame.style.display = "block"; | ||
frame.style.position = "fixed"; | ||
frame.style.border = "none"; | ||
document.body.appendChild(frame); | ||
|
||
window.addEventListener("message", (e) => { | ||
// Wait for Tabby to be ready | ||
if (e.source === frame?.contentWindow && e.data === "adb") { | ||
syncDevice(); | ||
} | ||
}); | ||
|
||
// Sync device when it's changed | ||
autorun(syncDevice); | ||
} | ||
|
||
// Because re-parent an iframe will cause it to reload, | ||
// use visibility to show/hide it | ||
// and use a ResizeObserver to put it in the right place. | ||
frame.style.visibility = "visible"; | ||
resizeObserver = new ResizeObserver(() => { | ||
const { top, left, width, height } = container.getBoundingClientRect(); | ||
if (width === 0 || height === 0) { | ||
// zero size makes xterm.js wrap lines incorrectly | ||
return; | ||
} | ||
frame!.style.top = `${top}px`; | ||
frame!.style.left = `${left}px`; | ||
frame!.style.width = `${width}px`; | ||
frame!.style.height = `${height}px`; | ||
}); | ||
resizeObserver.observe(container); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
04d7c08
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ya-webadb – ./
ya-webadb-yume-chan.vercel.app
ya-webadb-git-main-yume-chan.vercel.app
ya-webadb.vercel.app
www.tangoapp.dev
tangoapp.dev