()
| 59 | export type UseTerminalHook = ReturnType<typeof useTerminal>; |
| 60 | |
| 61 | export 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", () => { |
nothing calls this directly
no test coverage detected