MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / useTerminal

Function useTerminal

frontend/src/hooks/useTerminal.ts:61–396  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59export type UseTerminalHook = ReturnType<typeof useTerminal>;
60
61export function useTerminal() {
62 const { hasBgImage } = useAppConfigStore();
63
64 const events = new EventEmitter();
65 let socket: Socket<DefaultEventsMap, DefaultEventsMap> | undefined;
66 const state = ref<InstanceDetail>();
67 const isReady = ref<boolean>(false);
68 const terminal = ref<Terminal>();
69 const isConnect = ref<boolean>(false);
70 const socketAddress = ref("");
71 let isManualDisconnect = false;
72
73 const isGlobalTerminal = computed(() => {
74 return state.value?.config.nickname === GLOBAL_INSTANCE_NAME;
75 });
76
77 const isDockerMode = computed(() => {
78 return state.value?.config.processType === "docker";
79 });
80
81 let fitAddonTask: NodeJS.Timer;
82 let cachedSize = {
83 w: 160,
84 h: 40
85 };
86
87 const execute = async (config: UseTerminalParams) => {
88 isReady.value = false;
89 isManualDisconnect = false;
90
91 if (socket) {
92 return socket;
93 }
94
95 const res = await setUpTerminalStreamChannel().execute({
96 params: {
97 daemonId: config.daemonId,
98 uuid: config.instanceId
99 }
100 });
101 const remoteInfo = unref(res.value);
102 if (!remoteInfo) throw new Error(t("TXT_CODE_181f2f08"));
103
104 let addr = remoteInfo.addr,
105 prefix = remoteInfo.prefix;
106 if (remoteInfo.remoteMappings) {
107 const mapped = mapDaemonAddress(remoteInfo.remoteMappings);
108 if (mapped) {
109 addr = mapped.addr;
110 prefix = mapped.prefix;
111 }
112 }
113 socketAddress.value = parseForwardAddress(addr, "ws");
114 const password = remoteInfo.password;
115
116 socket = makeSocketIo(addr, prefix);
117
118 socket.on("connect", () => {

Callers

nothing calls this directly

Calls 5

encodeConsoleColorFunction · 0.85
onMethod · 0.80
emitMethod · 0.80
disconnectMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected