feat(Device): sync clipboard from device

This commit is contained in:
AkiChase 2024-05-26 21:05:56 +08:00
parent e845a2355f
commit 928e5ff5d9
3 changed files with 14 additions and 10 deletions

View File

@ -60,6 +60,8 @@ let deviceWaitForMetadataTask: ((deviceName: string) => void) | null = null;
let deviceWaitForScreenSizeTask: ((w: number, h: number) => void) | null = null; let deviceWaitForScreenSizeTask: ((w: number, h: number) => void) | null = null;
let unlisten: UnlistenFn | undefined; let unlisten: UnlistenFn | undefined;
let lastClipboard = "";
onMounted(async () => { onMounted(async () => {
unlisten = await listen("device-reply", (event) => { unlisten = await listen("device-reply", (event) => {
try { try {
@ -69,7 +71,17 @@ onMounted(async () => {
deviceWaitForMetadataTask?.(payload.deviceName); deviceWaitForMetadataTask?.(payload.deviceName);
break; break;
case "ClipboardChanged": 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; break;
case "ClipboardSetAck": case "ClipboardSetAck":
console.log("ClipboardSetAck", payload.sequence); console.log("ClipboardSetAck", payload.sequence);
@ -222,7 +234,7 @@ function onMenuClickoutside() {
async function deviceControl() { async function deviceControl() {
let curClientInfo = await getCurClientInfo(); let curClientInfo = await getCurClientInfo();
if (curClientInfo) { if (curClientInfo) {
message.warning(t("pages.Device.alreadyControled")); message.error(t("pages.Device.alreadyControled"));
store.controledDevice = { store.controledDevice = {
scid: curClientInfo.scid, scid: curClientInfo.scid,
deviceName: curClientInfo.device_name, deviceName: curClientInfo.device_name,
@ -236,12 +248,6 @@ async function deviceControl() {
port.value = 27183; port.value = 27183;
} }
if (store.controledDevice) {
message.error(t("pages.Device.deviceControl.closeCurDevice"));
store.hideLoading();
return;
}
message.info(t("pages.Device.deviceControl.controlInfo")); message.info(t("pages.Device.deviceControl.controlInfo"));
const device = devices.value[rowIndex]; const device = devices.value[rowIndex];

View File

@ -14,7 +14,6 @@
"screen": "Get screen size" "screen": "Get screen size"
}, },
"deviceControl": { "deviceControl": {
"closeCurDevice": "Please close the current control device first",
"controlInfo": "The control service is starting. Please keep the device screen on.", "controlInfo": "The control service is starting. Please keep the device screen on.",
"connectTimeout": "Device connection timeout" "connectTimeout": "Device connection timeout"
}, },

View File

@ -13,7 +13,6 @@
"screen": "获取屏幕尺寸" "screen": "获取屏幕尺寸"
}, },
"deviceControl": { "deviceControl": {
"closeCurDevice": "请先关闭当前控制设备",
"controlInfo": "正在启动控制服务,请保持设备亮屏", "controlInfo": "正在启动控制服务,请保持设备亮屏",
"connectTimeout": "设备连接超时" "connectTimeout": "设备连接超时"
}, },