bug(Mask): fix migration error

This commit is contained in:
AkiChase 2024-04-14 17:15:39 +08:00
parent a894af700d
commit 9d495423f7
6 changed files with 46 additions and 36 deletions

View File

@ -2,7 +2,7 @@
name = "scrcpy-mask" name = "scrcpy-mask"
version = "0.0.0" version = "0.0.0"
description = "A Tauri App" description = "A Tauri App"
authors = ["you"] authors = ["AkiChase"]
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -173,7 +173,6 @@ async fn recv_front_msg(
&mut write_half, &mut write_half,
) )
.await; .await;
println!("控制信息发送完成!");
continue; continue;
} else { } else {
// 处理Scrcpy Mask命令 // 处理Scrcpy Mask命令

View File

@ -1,7 +1,7 @@
{ {
"productName": "scrcpy-mask", "productName": "scrcpy-mask",
"version": "0.0.0", "version": "0.0.0",
"identifier": "com.tauri.dev", "identifier": "com.akichase.mask",
"build": { "build": {
"beforeDevCommand": "pnpm dev", "beforeDevCommand": "pnpm dev",
"devUrl": "http://localhost:1420", "devUrl": "http://localhost:1420",

View File

@ -15,6 +15,7 @@ import {
pushServerFile, pushServerFile,
forwardServerPort, forwardServerPort,
startScrcpyServer, startScrcpyServer,
getScreenSize,
} from "../invoke"; } from "../invoke";
import { import {
NH4, NH4,
@ -43,9 +44,7 @@ const store = useGlobalStore();
const port = ref(27183); const port = ref(27183);
//#region listener //#region listener
const deviceWaitForMetadataTask: (( const deviceWaitForMetadataTask: ((deviceName: string) => void)[] = [];
deviceName: string
) => void)[] = [];
let unlisten: UnlistenFn | undefined; let unlisten: UnlistenFn | undefined;
onMounted(async () => { onMounted(async () => {
@ -175,6 +174,8 @@ async function onMenuSelect(key: string) {
"00000000" + Math.floor(Math.random() * 100000).toString(16) "00000000" + Math.floor(Math.random() * 100000).toString(16)
).slice(-8); ).slice(-8);
let screenSize = await getScreenSize(device.id);
await pushServerFile(device.id); await pushServerFile(device.id);
await forwardServerPort(device.id, scid, port.value); await forwardServerPort(device.id, scid, port.value);
await startScrcpyServer(device.id, scid, `127.0.0.1:${port.value}`); await startScrcpyServer(device.id, scid, `127.0.0.1:${port.value}`);
@ -185,7 +186,8 @@ async function onMenuSelect(key: string) {
scid, scid,
deviceName, deviceName,
device, device,
} screenSize,
};
nextTick(() => { nextTick(() => {
store.hideLoading(); store.hideLoading();
}); });
@ -200,6 +202,13 @@ async function refreshDevices() {
devices.value = await adbDevices(); devices.value = await adbDevices();
store.hideLoading(); store.hideLoading();
} }
const screenSizeInfo = computed(() => {
if (store.controledDevice) {
return `${store.controledDevice.screenSize[0]} x ${store.controledDevice.screenSize[1]}`;
}
return "";
});
</script> </script>
<template> <template>
@ -221,7 +230,11 @@ async function refreshDevices() {
v-if="!store.controledDevice" v-if="!store.controledDevice"
/> />
<div class="controled-device" v-if="store.controledDevice"> <div class="controled-device" v-if="store.controledDevice">
<div>{{ store.controledDevice.deviceName }} ({{ store.controledDevice.device.id }})</div> <div>
{{ store.controledDevice.deviceName }} ({{
store.controledDevice.device.id
}})
</div>
<div class="device-op"> <div class="device-op">
<NTooltip trigger="hover"> <NTooltip trigger="hover">
<template #trigger> <template #trigger>
@ -231,16 +244,11 @@ async function refreshDevices() {
</template> </template>
</NButton> </NButton>
</template> </template>
scid: {{ store.controledDevice.scid }} scid: {{ store.controledDevice.scid }} <br />status:
<br />status: {{ store.controledDevice.device.status }} {{ store.controledDevice.device.status }} <br />screen:
{{ screenSizeInfo }}
</NTooltip> </NTooltip>
<NButton quaternary circle type="error" @click="shutdownSC()">
<NButton
quaternary
circle
type="error"
@click="shutdownSC()"
>
<template #icon> <template #icon>
<NIcon><CloseCircle /></NIcon> <NIcon><CloseCircle /></NIcon>
</template> </template>

View File

@ -15,7 +15,7 @@ async function maximizeOrRestore() {
<template> <template>
<div data-tauri-drag-region class="header"> <div data-tauri-drag-region class="header">
<NButtonGroup> <NButtonGroup>
<NButton quaternary :focusable="false" @click="appWindow.minimize()"> <NButton quaternary :focusable="false" @click="getCurrent().minimize()">
<template #icon> <template #icon>
<NIcon><Subtract16Regular /></NIcon> <NIcon><Subtract16Regular /></NIcon>
</template> </template>

View File

@ -2,10 +2,12 @@
import { onActivated, ref } from "vue"; import { onActivated, ref } from "vue";
import { NDialog } from "naive-ui"; import { NDialog } from "naive-ui";
import { useGlobalStore } from "../store/global"; import { useGlobalStore } from "../store/global";
import { useRouter } from "vue-router"; import { onBeforeRouteLeave, useRouter } from "vue-router";
import { getCurrent } from "@tauri-apps/api/window"; import {
import { initShortcuts } from "../hotkey"; initShortcuts,
import { getScreenSize } from "../invoke"; listenToKeyEvent,
unlistenToKeyEvent,
} from "../hotkey";
const maskRef = ref<HTMLElement | null>(null); const maskRef = ref<HTMLElement | null>(null);
@ -14,20 +16,26 @@ const router = useRouter();
let isShortcutInited = false; let isShortcutInited = false;
onBeforeRouteLeave(() => {
if (isShortcutInited) {
if (maskRef.value) {
unlistenToKeyEvent();
}
}
});
onActivated(async () => { onActivated(async () => {
if (isShortcutInited) { if (isShortcutInited) {
maskRef.value?.focus(); if (maskRef.value) {
listenToKeyEvent();
}
return; return;
} }
if (store.controledDevice) { if (store.controledDevice) {
let screenSize = await getScreenSize(store.controledDevice.device.id);
if (maskRef.value) { if (maskRef.value) {
const appWindow = getCurrent(); initShortcuts(store.controledDevice.screenSize, maskRef.value);
let posFactor = await appWindow.scaleFactor(); listenToKeyEvent();
initShortcuts(maskRef.value, posFactor, screenSize);
isShortcutInited = true; isShortcutInited = true;
maskRef.value.focus();
console.log("热键已载入");
} }
} }
}); });
@ -36,7 +44,6 @@ function toStartServer() {
router.replace({ name: "device" }); router.replace({ name: "device" });
} }
// TODO
// TODO // TODO
// TODO // TODO
</script> </script>
@ -56,7 +63,7 @@ function toStartServer() {
</div> </div>
<div <div
v-show="store.controledDevice" v-show="store.controledDevice"
tabindex="-1" @contextmenu.prevent
class="mask" class="mask"
ref="maskRef" ref="maskRef"
></div> ></div>
@ -66,11 +73,7 @@ function toStartServer() {
.mask { .mask {
background-color: rgba(255, 255, 255, 0.2); background-color: rgba(255, 255, 255, 0.2);
overflow: hidden; overflow: hidden;
cursor: pointer;
&:focus {
outline: none;
box-shadow: 0 0 5px var(--primary-color);
}
} }
.notice { .notice {
background-color: rgba(255, 255, 255, 0.2); background-color: rgba(255, 255, 255, 0.2);