From 365c915103770d2316311f64c2d1bbc5d9ca6f6f Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Thu, 16 May 2024 23:25:31 +0800 Subject: [PATCH] feat(websocket): add external control --- src/components/Device.vue | 45 +++++++++++++++++++--- src/i18n/en-US.json | 12 +++++- src/i18n/index.ts | 3 +- src/i18n/zh-CN.json | 12 +++++- src/store/global.ts | 3 ++ src/websocket.ts | 81 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 147 insertions(+), 9 deletions(-) create mode 100644 src/websocket.ts diff --git a/src/components/Device.vue b/src/components/Device.vue index c14d544..0fb6115 100644 --- a/src/components/Device.vue +++ b/src/components/Device.vue @@ -40,13 +40,13 @@ import { useMessage, NInputGroup, } from "naive-ui"; -import { CloseCircle, InformationCircle } from "@vicons/ionicons5"; -import { Refresh } from "@vicons/ionicons5"; +import { CloseCircle, InformationCircle, Refresh } from "@vicons/ionicons5"; import { UnlistenFn, listen } from "@tauri-apps/api/event"; import { Store } from "@tauri-apps/plugin-store"; import { shutdown } from "../frontcommand/scrcpyMaskCmd"; import { useGlobalStore } from "../store/global"; import { useI18n } from "vue-i18n"; +import { closeExternalControl, connectExternalControl } from "../websocket"; const { t } = useI18n(); const dialog = useDialog(); @@ -54,7 +54,8 @@ const store = useGlobalStore(); const message = useMessage(); const port = ref(27183); -const address = ref(""); +const wireless_address = ref(""); +const ws_address = ref(""); const localStore = new Store("store.bin"); @@ -300,15 +301,29 @@ async function refreshDevices() { } async function connectDevice() { - if (!address.value) { + if (!wireless_address.value) { message.error(t("pages.Device.inputWirelessAddress")); return; } store.showLoading(); - message.info(await adbConnect(address.value)); + message.info(await adbConnect(wireless_address.value)); await refreshDevices(); } + +function connectWS() { + if (!ws_address.value) { + message.error(t("pages.Device.inputWsAddress")); + return; + } + + store.showLoading(); + connectExternalControl(ws_address.value, message, store, t); +} + +function closeWS() { + closeExternalControl(); +}