Compare commits
14 Commits
c79c776225
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b588f113e3 | |||
| a9c827fa4c | |||
| e4f2c5a844 | |||
| 0675ce138f | |||
| 66c0fe3ad0 | |||
| e0fbf4f434 | |||
| 22b99c3562 | |||
| a03c1a8ee4 | |||
| 2bf050cff9 | |||
| 46d308ce35 | |||
| 7cd85a3315 | |||
| fd338d2dad | |||
| 6dbe2f6e20 | |||
| 36d23c3d74 |
@@ -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,10 +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 titleStatus = false;
|
|
||||||
private checkStatus = false;
|
|
||||||
private connectStatus = false;
|
private connectStatus = false;
|
||||||
|
private hostTitle = "";
|
||||||
|
private postAttachCommand = [];
|
||||||
|
private postAttachCommandStatus = false;
|
||||||
|
private workdir = "";
|
||||||
|
private containerStatus = "";
|
||||||
private beforeCommand?: string;
|
private beforeCommand?: string;
|
||||||
constructor(
|
constructor(
|
||||||
private options: XtermOptions,
|
private options: XtermOptions,
|
||||||
@@ -186,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');
|
||||||
@@ -266,7 +268,7 @@ export class Xterm {
|
|||||||
|
|
||||||
@bind
|
@bind
|
||||||
public changeStatus(v: boolean){
|
public changeStatus(v: boolean){
|
||||||
this.status = v;
|
this.connectStatus = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
@@ -281,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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,26 +358,23 @@ export class Xterm {
|
|||||||
)
|
)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
if (this.workdir === ''){
|
||||||
|
this.workdir = data.workdir;
|
||||||
|
}
|
||||||
if (data.status !== '4' && data.status !== '0') {
|
if (data.status !== '4' && data.status !== '0') {
|
||||||
|
if(this.containerStatus !== data.status){
|
||||||
this.sendData(data.command);
|
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') {
|
||||||
fetch(
|
const parts = data.command.split('\n');
|
||||||
'http://' + options.get('domain') + ':'+ options.get('port') +'/' +
|
this.sendData(parts[0]+"\n");
|
||||||
options.get('user') +
|
this.postAttachCommand = parts;
|
||||||
'/' +
|
|
||||||
options.get('repo') +
|
|
||||||
'/devcontainer/command?' +
|
|
||||||
params
|
|
||||||
)
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
this.sendData(data.command);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -379,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;
|
||||||
@@ -422,43 +428,43 @@ 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({
|
||||||
|
repo: options.get('repoid') as string,
|
||||||
|
user: options.get('userid') as string,
|
||||||
|
});
|
||||||
if (options.get('type') === 'docker') {
|
if (options.get('type') === 'docker') {
|
||||||
|
// 保存host的标题
|
||||||
|
if (this.hostTitle === ""){
|
||||||
|
this.hostTitle = textDecoder.decode(data).replace(/\s/g, '');
|
||||||
|
}
|
||||||
|
// 检测是否退出devcontainer,标题等于host的标题
|
||||||
|
if (this.connectStatus && textDecoder.decode(data).replace(/\s/g, '').includes(this.hostTitle)){
|
||||||
|
this.connectStatus = false
|
||||||
|
}
|
||||||
|
// this.connectStatus = true 连接完成
|
||||||
if (
|
if (
|
||||||
this.status === false &&
|
this.connectStatus === false &&
|
||||||
textDecoder.decode(data).replace(/\s/g, '').includes('Successfully connected to the container'.replace(/\s/g, ''))
|
textDecoder.decode(data).replace(/\s/g, '').includes('Successfully connected to the devcontainer'.replace(/\s/g, ''))
|
||||||
) {
|
) {
|
||||||
if(this.connectStatus == true){
|
|
||||||
this.status = true;
|
|
||||||
}
|
|
||||||
this.connectStatus = true;
|
this.connectStatus = true;
|
||||||
|
clearInterval(this.intervalID);
|
||||||
}
|
}
|
||||||
if (this.checkStatus) {
|
// 连接完成之前,不输出标题和docker命令
|
||||||
if (textDecoder.decode(data).replace(/\s/g, '').includes('You have out the container. Please refresh the terminal to reconnect.'.replace(/\s/g, ''))) {
|
|
||||||
this.checkStatus = false;
|
|
||||||
this.status = false;
|
|
||||||
this.connectStatus = false;
|
|
||||||
}
|
|
||||||
if(textDecoder.decode(data).includes('\x1b')){
|
|
||||||
this.checkStatus = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.titleStatus && textDecoder.decode(data).includes('\x1b')) {
|
|
||||||
this.titleStatus = false;
|
|
||||||
this.checkStatus = true;
|
|
||||||
this.sendData(
|
|
||||||
`echo $WEB_TERMINAL\n`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
!(this.status === false && (textDecoder.decode(data).includes('\x1b') || textDecoder.decode(data).replace(/\s/g, '').includes('docker'))) &&
|
!(this.connectStatus === false &&
|
||||||
this.titleStatus !== true &&
|
(textDecoder.decode(data).includes('\x1b') ||
|
||||||
this.checkStatus !== true
|
textDecoder.decode(data).replace(/\s/g, '').includes('docker-H')))
|
||||||
){
|
){
|
||||||
this.writeFunc(data);
|
this.writeFunc(data);
|
||||||
}
|
}
|
||||||
if (textDecoder.decode(data).replace(/\s/g, '').includes('exit')) {
|
// 连接完成且出现容器的标题,且没有执行过postAttach命令
|
||||||
this.titleStatus = true;
|
if (this.connectStatus && textDecoder.decode(data).replace(/\s/g, '').includes(this.workdir) && !this.postAttachCommandStatus){
|
||||||
|
for (let i = 1; i < this.postAttachCommand.length; i++){
|
||||||
|
this.sendData(this.postAttachCommand[i]+"\n");
|
||||||
|
}
|
||||||
|
this.postAttachCommandStatus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "ttyd",
|
"name": "webTerminal",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {}
|
"packages": {}
|
||||||
|
|||||||
32364
src/html.h
generated
32364
src/html.h
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user