Compare commits
9 Commits
46d308ce35
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b588f113e3 | |||
| a9c827fa4c | |||
| e4f2c5a844 | |||
| 0675ce138f | |||
| 66c0fe3ad0 | |||
| e0fbf4f434 | |||
| 22b99c3562 | |||
| a03c1a8ee4 | |||
| 2bf050cff9 |
@@ -61,9 +61,10 @@ export class Terminal extends Component<Props, State> {
|
|||||||
if (data.status !== '-1') {
|
if (data.status !== '-1') {
|
||||||
if (options.get('type') === 'docker') {
|
if (options.get('type') === 'docker') {
|
||||||
this.xterm.open(this.container);
|
this.xterm.open(this.container);
|
||||||
|
this.xterm.changeContainerStatus(data.status);
|
||||||
this.xterm.connect();
|
this.xterm.connect();
|
||||||
} else {
|
} else {
|
||||||
this.intervalID = setInterval(this.loadOutput, 3000);
|
this.intervalID = setInterval(this.loadOutput, 8000);
|
||||||
this.xterm.open(this.container);
|
this.xterm.open(this.container);
|
||||||
this.xterm.changeUrl(this.currentDevcontainer.ip, this.currentDevcontainer.port)
|
this.xterm.changeUrl(this.currentDevcontainer.ip, this.currentDevcontainer.port)
|
||||||
this.xterm.changeStatus(true);
|
this.xterm.changeStatus(true);
|
||||||
|
|||||||
@@ -103,11 +103,12 @@ export class Xterm {
|
|||||||
private closeOnDisconnect = false;
|
private closeOnDisconnect = false;
|
||||||
private intervalID: NodeJS.Timeout;
|
private intervalID: NodeJS.Timeout;
|
||||||
private writeFunc = (data: ArrayBuffer) => this.writeData(new Uint8Array(data));
|
private writeFunc = (data: ArrayBuffer) => this.writeData(new Uint8Array(data));
|
||||||
private status = false;
|
private connectStatus = false;
|
||||||
private hostTitle = "";
|
private hostTitle = "";
|
||||||
private postAttachCommand = [];
|
private postAttachCommand = [];
|
||||||
private postAttachCommandStatus = false;
|
private postAttachCommandStatus = false;
|
||||||
private workdir = "";
|
private workdir = "";
|
||||||
|
private containerStatus = "";
|
||||||
private beforeCommand?: string;
|
private beforeCommand?: string;
|
||||||
constructor(
|
constructor(
|
||||||
private options: XtermOptions,
|
private options: XtermOptions,
|
||||||
@@ -187,7 +188,7 @@ export class Xterm {
|
|||||||
register(
|
register(
|
||||||
terminal.onData(data =>
|
terminal.onData(data =>
|
||||||
{
|
{
|
||||||
if (this.status) {
|
if (this.connectStatus) {
|
||||||
sendData(data);
|
sendData(data);
|
||||||
} else {
|
} else {
|
||||||
this.writeData('\b \b');
|
this.writeData('\b \b');
|
||||||
@@ -267,7 +268,7 @@ export class Xterm {
|
|||||||
|
|
||||||
@bind
|
@bind
|
||||||
public changeStatus(v: boolean){
|
public changeStatus(v: boolean){
|
||||||
this.status = v;
|
this.connectStatus = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
@@ -282,7 +283,11 @@ export class Xterm {
|
|||||||
register(addEventListener(socket, 'error', () => (this.doReconnect = false)));
|
register(addEventListener(socket, 'error', () => (this.doReconnect = false)));
|
||||||
const options = new URLSearchParams(decodeURIComponent(window.location.search));
|
const options = new URLSearchParams(decodeURIComponent(window.location.search));
|
||||||
if (options.get('type') === 'docker') {
|
if (options.get('type') === 'docker') {
|
||||||
this.intervalID = setInterval(this.loadCommand, 3000);
|
if(this.containerStatus === '4' || this.containerStatus === '-1'){
|
||||||
|
this.intervalID = setInterval(this.loadCommand, 1000);
|
||||||
|
}else{
|
||||||
|
this.intervalID = setInterval(this.loadCommand, 8000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,9 +362,15 @@ export class Xterm {
|
|||||||
this.workdir = data.workdir;
|
this.workdir = data.workdir;
|
||||||
}
|
}
|
||||||
if (data.status !== '4' && data.status !== '0') {
|
if (data.status !== '4' && data.status !== '0') {
|
||||||
this.sendData(data.command);
|
if(this.containerStatus !== data.status){
|
||||||
|
this.sendData(data.command);
|
||||||
|
}
|
||||||
|
this.containerStatus = data.status;
|
||||||
} else {
|
} else {
|
||||||
clearInterval(this.intervalID);
|
if(this.containerStatus !== '4'){
|
||||||
|
this.writeData("\x1b[31mCreation completed. Please refresh the page to connect to the devcontainer\x1b[0m");
|
||||||
|
}
|
||||||
|
this.containerStatus = data.status;
|
||||||
if (data.status === '4') {
|
if (data.status === '4') {
|
||||||
const parts = data.command.split('\n');
|
const parts = data.command.split('\n');
|
||||||
this.sendData(parts[0]+"\n");
|
this.sendData(parts[0]+"\n");
|
||||||
@@ -371,7 +382,10 @@ export class Xterm {
|
|||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@bind
|
||||||
|
public changeContainerStatus(v: string){
|
||||||
|
this.containerStatus = v;
|
||||||
|
}
|
||||||
@bind
|
@bind
|
||||||
private parseOptsFromUrlQuery(query: string): Preferences {
|
private parseOptsFromUrlQuery(query: string): Preferences {
|
||||||
const { terminal } = this;
|
const { terminal } = this;
|
||||||
@@ -414,6 +428,7 @@ export class Xterm {
|
|||||||
const data = rawData.slice(1);
|
const data = rawData.slice(1);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case Command.OUTPUT:
|
case Command.OUTPUT:
|
||||||
|
console.log('[ttyd] output:', textDecoder.decode(data));
|
||||||
const options = new URLSearchParams(decodeURIComponent(window.location.search));
|
const options = new URLSearchParams(decodeURIComponent(window.location.search));
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
repo: options.get('repoid') as string,
|
repo: options.get('repoid') as string,
|
||||||
@@ -425,51 +440,27 @@ export class Xterm {
|
|||||||
this.hostTitle = textDecoder.decode(data).replace(/\s/g, '');
|
this.hostTitle = textDecoder.decode(data).replace(/\s/g, '');
|
||||||
}
|
}
|
||||||
// 检测是否退出devcontainer,标题等于host的标题
|
// 检测是否退出devcontainer,标题等于host的标题
|
||||||
if (this.status && textDecoder.decode(data).replace(/\s/g, '').includes(this.hostTitle)){
|
if (this.connectStatus && textDecoder.decode(data).replace(/\s/g, '').includes(this.hostTitle)){
|
||||||
this.status = false
|
this.connectStatus = false
|
||||||
}
|
}
|
||||||
// this.status = true 连接完成
|
// this.connectStatus = true 连接完成
|
||||||
if (
|
if (
|
||||||
this.status === false &&
|
this.connectStatus === false &&
|
||||||
textDecoder.decode(data).replace(/\s/g, '').includes('Successfully connected to the devcontainer'.replace(/\s/g, ''))
|
textDecoder.decode(data).replace(/\s/g, '').includes('Successfully connected to the devcontainer'.replace(/\s/g, ''))
|
||||||
) {
|
) {
|
||||||
this.status = true;
|
this.connectStatus = true;
|
||||||
fetch('http://' + options.get('domain') + ':'+ options.get('port') +'/' +
|
clearInterval(this.intervalID);
|
||||||
options.get('user') +
|
|
||||||
'/' +
|
|
||||||
options.get('repo') +
|
|
||||||
'/devcontainer/output?' +
|
|
||||||
params
|
|
||||||
).then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
this.writeData(data.output);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error('[ttyd] Failed to get output:', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// 连接完成之前,不输出标题和docker命令
|
// 连接完成之前,不输出标题和docker命令
|
||||||
if (
|
if (
|
||||||
!(this.status === false && (textDecoder.decode(data).includes('\x1b') || textDecoder.decode(data).replace(/\s/g, '').includes('docker')))
|
!(this.connectStatus === false &&
|
||||||
|
(textDecoder.decode(data).includes('\x1b') ||
|
||||||
|
textDecoder.decode(data).replace(/\s/g, '').includes('docker-H')))
|
||||||
){
|
){
|
||||||
this.writeFunc(data);
|
this.writeFunc(data);
|
||||||
fetch('http://' + options.get('domain') + ':'+ options.get('port') +'/' +
|
|
||||||
options.get('user') +
|
|
||||||
'/' +
|
|
||||||
options.get('repo') +
|
|
||||||
'/devcontainer/output?' +
|
|
||||||
params, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'text/plain'
|
|
||||||
},
|
|
||||||
body: textDecoder.decode(data),
|
|
||||||
}).catch(err => {
|
|
||||||
console.error('[ttyd] Failed to send output:', err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (this.status && textDecoder.decode(data).replace(/\s/g, '').includes(this.workdir) && !this.postAttachCommandStatus){
|
// 连接完成且出现容器的标题,且没有执行过postAttach命令
|
||||||
|
if (this.connectStatus && textDecoder.decode(data).replace(/\s/g, '').includes(this.workdir) && !this.postAttachCommandStatus){
|
||||||
for (let i = 1; i < this.postAttachCommand.length; i++){
|
for (let i = 1; i < this.postAttachCommand.length; i++){
|
||||||
this.sendData(this.postAttachCommand[i]+"\n");
|
this.sendData(this.postAttachCommand[i]+"\n");
|
||||||
}
|
}
|
||||||
|
|||||||
32359
src/html.h
generated
32359
src/html.h
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user