check to code-server-like

This commit is contained in:
Cai
2025-09-21 15:33:00 +08:00
parent 252c426c3e
commit 271672c904
10 changed files with 129416 additions and 1673 deletions

View File

@@ -135,6 +135,7 @@ def save_file():
if not os.path.exists(filepath):
return jsonify({"error": "File not found"}), 404
try:
print(f"savefile {filepath} \n content{content}")
with open(filepath, 'w') as file:
file.write(content)
return jsonify({"message": "File saved successfully"})

View File

@@ -66,7 +66,7 @@ body {
}
/* 可以根据需要设置按钮的大小和间距 */
#newFileBtn, #newFolderBtn, #toggleSearchBtn, #refreshBtn {
#newFileBtn, #newFolderBtn, #toggleSearchBtn, #refreshBtn, #openTerminalBtn, #saveBtn {
margin-right: 10px;
}

View File

@@ -1,9 +1,24 @@
let vs_socket = null;
let debounceTimeout;
// 缓冲器函数(防抖)
function debounceSendToServer(data, delay) {
if (debounceTimeout) {
clearTimeout(debounceTimeout);
}
debounceTimeout = setTimeout(() => {
sendToServer(data);
}, delay);
}
function sendToServer(data){
try {
if (!vs_socket) {
return;
}
console.log('Sending data to Flask server:', data);
vs_socket.emit('message', data)
} catch (error) {
console.error('Error sending data to Flask server:', error);
@@ -42,16 +57,7 @@ vs_socket.on('disconnect', () => {
});
vs_socket.on('terminal',(data)=>{
// vscode.window.showInformationMessage('Terminal command received'+data);
term.write(data.data);
socket.emit("pty_input", {"input": data.data+'\r\n'}, function(response) {
});
})
// 缓冲器函数(防抖)
function debounceSendToServer(data, delay) {
if (debounceTimeout) {
clearTimeout(debounceTimeout);
}
debounceTimeout = setTimeout(() => {
sendToServer(data);
}, delay);
}

View File

@@ -1,5 +1,6 @@
let term = null;
let socket=null;
document.addEventListener('DOMContentLoaded', () => {
Terminal.applyAddon(fullscreen)
Terminal.applyAddon(fit)
@@ -23,7 +24,7 @@
});
});
const socket = io('https://hsamooc.com/vsc-like',{path:'/vsc-like-ws'});
socket = io('https://hsamooc.com/vsc-like',{path:'/vsc-like-ws'});
const status = document.getElementById("status")
socket.on("pty_output", function(data){

View File

@@ -106,7 +106,7 @@
});
// 防抖处理非粘贴的编辑操作
const content = event.document.getText();
const content = changes.text;
debounceSendToServer({
type: 'fileEdit',
filePath: filePath,
@@ -155,23 +155,29 @@
}
let socket = null;
function openTerminal(event) {
event.stopPropagation();
const terminalDiv = document.getElementById('terminal');
terminalDiv.style.display = (terminalDiv.style.display === 'none' || terminalDiv.style.display === '') ? 'block' : 'none';
if (socket == null) {
socket = io.connect('http://' + document.domain + ':5200/vsc-like/terminal');
// document.getElementById('terminal').style.display = 'block';
if (document.getElementById('terminal').style.display === 'none' || document.getElementById('terminal').style.display === '') {
document.getElementById('terminal').style.display = 'block';
}else{
document.getElementById('terminal').style.display = 'none';
}
socket.on('connected', function(data) {
console.log('Terminal connected');
});
socket.on('terminal_output', function(data) {
const terminalDiv = document.getElementById('terminal');
terminalDiv.textContent += data.data;
});
// event.stopPropagation();
// const terminalDiv = document.getElementById('terminal');
// terminalDiv.style.display = (terminalDiv.style.display === 'none' || terminalDiv.style.display === '') ? 'block' : 'none';
// if (socket == null) {
// socket = io.connect('http://' + document.domain + ':5200/vsc-like/terminal');
// }
// socket.on('connected', function(data) {
// console.log('Terminal connected');
// });
// socket.on('terminal_output', function(data) {
// const terminalDiv = document.getElementById('terminal');
// terminalDiv.textContent += data.data;
// });
function sendTerminalInput(input) {
socket.emit('send_input', { input: input });
}
// function sendTerminalInput(input) {
// socket.emit('send_input', { input: input });
// }
}
// 按钮绑定事件