Feat: add ctrl+c func

This commit is contained in:
unitwk 2022-08-22 21:49:20 +08:00
parent 8caafc1bf4
commit da14b39868
4 changed files with 3 additions and 17 deletions

View File

@ -11,8 +11,8 @@ export default class PtyStopCommand extends InstanceCommand {
}
async exec(instance: Instance) {
const stopCommand = instance.config.stopCommand;
if (stopCommand.toLocaleLowerCase() == "^c") return instance.failure(new Error($t("pty_stop.ctrlC")));
let stopCommand = instance.config.stopCommand;
if (stopCommand.toLocaleLowerCase() == "^c") stopCommand = "\x03";
if (instance.status() === Instance.STATUS_STOP || !instance.process) return instance.failure(new Error($t("pty_stop.notRunning")));
instance.status(Instance.STATUS_STOPPING);

View File

@ -144,7 +144,6 @@ export default {
},
// src\entity\commands\pty\pty_stop.ts
pty_stop: {
ctrlC: "仿真终端无法使用Ctrl+C命令关闭进程请重新设置关服命令",
notRunning: "实例未处于运行中状态,无法进行停止.",
execCmd: "已执行预设的关闭命令:{{stopCommand}}\n如果无法关闭实例请前往实例设置更改关闭实例的正确命令比如 exitstopend 等",
stopErr:

View File

@ -301,17 +301,6 @@ routerApp.on("instance/stop_asynchronous", (ctx, data) => {
protocol.msg(ctx, "instance/stop_asynchronous", true);
});
// send data stream to application instance
routerApp.on("instance/stdin", (ctx, data) => {
// This route uses a low-compatibility and direct and original way to write data
// because this route will receive every character
const instance = InstanceSubsystem.getInstance(data.instanceUuid);
try {
if (data.ch == "\r") return instance.process.write("\n");
instance.process.write(data.ch);
} catch (err) {}
});
routerApp.on("instance/process_config/list", (ctx, data) => {
const instanceUuid = data.instanceUuid;
const files = data.files;

View File

@ -53,9 +53,7 @@ routerApp.on("stream/auth", (ctx, data) => {
// Cancel forwarding events when registration is disconnected
ctx.socket.on("disconnect", () => {
InstanceSubsystem.stopForward(instance.instanceUuid, ctx.socket);
logger.info(
$t("stream_router.disconnect", { id: ctx.socket.id, address: ctx.socket.handshake.address, uuid: instance.instanceUuid })
);
logger.info($t("stream_router.disconnect", { id: ctx.socket.id, address: ctx.socket.handshake.address, uuid: instance.instanceUuid }));
});
protocol.response(ctx, true);
} catch (error) {