From 928e5ff5d9ab9b89943d8353cb9ba6636e5b25a7 Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Sun, 26 May 2024 21:05:56 +0800 Subject: [PATCH] feat(Device): sync clipboard from device --- src/components/Device.vue | 22 ++++++++++++++-------- src/i18n/en-US.json | 1 - src/i18n/zh-CN.json | 1 - 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/components/Device.vue b/src/components/Device.vue index a134d32..d591761 100644 --- a/src/components/Device.vue +++ b/src/components/Device.vue @@ -60,6 +60,8 @@ let deviceWaitForMetadataTask: ((deviceName: string) => void) | null = null; let deviceWaitForScreenSizeTask: ((w: number, h: number) => void) | null = null; let unlisten: UnlistenFn | undefined; +let lastClipboard = ""; + onMounted(async () => { unlisten = await listen("device-reply", (event) => { try { @@ -69,7 +71,17 @@ onMounted(async () => { deviceWaitForMetadataTask?.(payload.deviceName); break; case "ClipboardChanged": - console.log("ClipboardChanged", payload.clipboard); + if (payload.clipboard === lastClipboard) break; + lastClipboard = payload.clipboard; + navigator.clipboard + .writeText(payload.clipboard) + .then(() => { + message.info("Device clipboard synced"); + }) + .catch((e) => { + console.error(e); + message.error("Device clipboard sync failed"); + }); break; case "ClipboardSetAck": console.log("ClipboardSetAck", payload.sequence); @@ -222,7 +234,7 @@ function onMenuClickoutside() { async function deviceControl() { let curClientInfo = await getCurClientInfo(); if (curClientInfo) { - message.warning(t("pages.Device.alreadyControled")); + message.error(t("pages.Device.alreadyControled")); store.controledDevice = { scid: curClientInfo.scid, deviceName: curClientInfo.device_name, @@ -236,12 +248,6 @@ async function deviceControl() { port.value = 27183; } - if (store.controledDevice) { - message.error(t("pages.Device.deviceControl.closeCurDevice")); - store.hideLoading(); - return; - } - message.info(t("pages.Device.deviceControl.controlInfo")); const device = devices.value[rowIndex]; diff --git a/src/i18n/en-US.json b/src/i18n/en-US.json index 86c0c72..c92404a 100644 --- a/src/i18n/en-US.json +++ b/src/i18n/en-US.json @@ -14,7 +14,6 @@ "screen": "Get screen size" }, "deviceControl": { - "closeCurDevice": "Please close the current control device first", "controlInfo": "The control service is starting. Please keep the device screen on.", "connectTimeout": "Device connection timeout" }, diff --git a/src/i18n/zh-CN.json b/src/i18n/zh-CN.json index 86e2040..3f0d700 100644 --- a/src/i18n/zh-CN.json +++ b/src/i18n/zh-CN.json @@ -13,7 +13,6 @@ "screen": "获取屏幕尺寸" }, "deviceControl": { - "closeCurDevice": "请先关闭当前控制设备", "controlInfo": "正在启动控制服务,请保持设备亮屏", "connectTimeout": "设备连接超时" },