A few renames and minor cleanups

This commit is contained in:
Soren Hansen
2025-08-02 22:21:12 -07:00
parent c761b53d41
commit 2bee116ca3
9 changed files with 1052 additions and 361 deletions

1311
js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
import { ConnectionFactory } from "./websocket";
import { Terminal, WebTTY, protocols } from "./webtty";
import { OurXterm } from "./xterm";
import { GoTTYXterm } from "./xterm";
// @TODO remove these
declare var gotty_auth_token: string;
@@ -11,7 +11,7 @@ const elem = document.getElementById("terminal")
if (elem !== null) {
var term: Terminal;
term = new OurXterm(elem);
term = new GoTTYXterm(elem);
const httpsEnabled = window.location.protocol == "https:";
const queryArgs = (gotty_ws_query_args === "") ? "" : "?" + gotty_ws_query_args;

View File

@@ -4,7 +4,7 @@ import { WebLinksAddon } from 'xterm-addon-web-links';
import { WebglAddon } from 'xterm-addon-webgl';
import { ZModemAddon } from "./zmodem";
export class OurXterm {
export class GoTTYXterm {
// The HTMLElement that contains our terminal
elem: HTMLElement;

View File

@@ -1,6 +1,6 @@
import { Component, ComponentChildren, createRef, render } from "preact";
import { ITerminalAddon, Terminal } from "xterm";
import { Browser, Detection, Offer, Sentry, Session } from 'zmodem.js/src/zmodem_browser';
import { Browser, Detection, Offer, Sentry, Session } from "zmodem.js";
import { Button, MyModal } from "./MyModal";
export class ZModemAddon implements ITerminalAddon {
@@ -209,15 +209,17 @@ export class SendFileModal extends Component<SendFileModalProps, SendFileModalSt
send() {
Browser.send_files(this.props.session,
this.filePickerRef.current!.files, {
on_offer_response: (f, xfer) => { this.setState({ state: "started" }) },
}).then(() => {
this.setState({ state: "done" })
this.props.session.close()
on_offer_response: (f, xfer) => {
this.setState({ state: "started" })
},
}
).then(() => {
this.setState({ state: "done" });
this.props.session.close();
if (this.props.onFinish !== undefined) {
this.props.onFinish();
}
})
.catch(e => console.log(e));
}).catch(e => console.log(e));
}
render() {

48
js/typings/zmodem.d.ts vendored Normal file
View File

@@ -0,0 +1,48 @@
declare module 'zmodem.js' {
export function send(data: Buffer): Promise<void>;
export function receive(): Promise<Buffer>;
export interface SendFilesOptions {
on_offer_response?: (file: File, xfer: any) => void;
}
export interface SentryOptions {
to_terminal: (data: Uint8Array) => void;
on_detect: (detection: Detection) => void;
sender: (data: Uint8Array) => void;
on_retract: () => void;
}
export interface FileDetails {
name: string;
size: number;
}
export class Browser {
static save_to_disk(payloads: any, filename: string): void;
static send_files(session: Session, files: FileList | null, options?: SendFilesOptions): Promise<void>;
}
export class Detection {
confirm(): Session;
}
export class Offer {
accept(): Promise<any>;
skip(): void;
get_details(): FileDetails;
get_offset(): number;
}
export class Sentry {
constructor(options: SentryOptions);
consume(data: Uint8Array): void;
}
export class Session {
type: "send" | "receive";
on(event: string, callback: (...args: any[]) => void): void;
start(): void;
close(): void;
}
}