Compare commits
4 Commits
66c0fe3ad0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b588f113e3 | |||
| a9c827fa4c | |||
| e4f2c5a844 | |||
| 0675ce138f |
@@ -61,6 +61,7 @@ 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, 8000);
|
this.intervalID = setInterval(this.loadOutput, 8000);
|
||||||
|
|||||||
@@ -283,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, 8000);
|
if(this.containerStatus === '4' || this.containerStatus === '-1'){
|
||||||
|
this.intervalID = setInterval(this.loadCommand, 1000);
|
||||||
|
}else{
|
||||||
|
this.intervalID = setInterval(this.loadCommand, 8000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,21 +367,11 @@ export class Xterm {
|
|||||||
}
|
}
|
||||||
this.containerStatus = data.status;
|
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') {
|
||||||
fetch('http://' + options.get('domain') + ':'+ options.get('port') +'/' +
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
const parts = data.command.split('\n');
|
const parts = data.command.split('\n');
|
||||||
this.sendData(parts[0]+"\n");
|
this.sendData(parts[0]+"\n");
|
||||||
this.postAttachCommand = parts;
|
this.postAttachCommand = parts;
|
||||||
@@ -388,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;
|
||||||
@@ -431,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,
|
||||||
@@ -451,27 +449,17 @@ export class Xterm {
|
|||||||
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.connectStatus = true;
|
this.connectStatus = true;
|
||||||
|
clearInterval(this.intervalID);
|
||||||
}
|
}
|
||||||
// 连接完成之前,不输出标题和docker命令
|
// 连接完成之前,不输出标题和docker命令
|
||||||
if (
|
if (
|
||||||
!(this.connectStatus === 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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// 连接完成且出现容器的标题,且没有执行过postAttach命令
|
||||||
if (this.connectStatus && textDecoder.decode(data).replace(/\s/g, '').includes(this.workdir) && !this.postAttachCommandStatus){
|
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");
|
||||||
|
|||||||
32385
src/html.h
generated
32385
src/html.h
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user