mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-02-23 07:22:17 +08:00
bug(hotkey): apply and clear shortcuts when nav
This commit is contained in:
parent
fde4f7ef56
commit
6eb2589f48
@ -4,7 +4,8 @@ import { NDialog } from "naive-ui";
|
|||||||
import { useGlobalStore } from "../store/global";
|
import { useGlobalStore } from "../store/global";
|
||||||
import { onBeforeRouteLeave, useRouter } from "vue-router";
|
import { onBeforeRouteLeave, useRouter } from "vue-router";
|
||||||
import {
|
import {
|
||||||
initShortcuts,
|
applyShortcuts,
|
||||||
|
clearShortcuts,
|
||||||
listenToKeyEvent,
|
listenToKeyEvent,
|
||||||
unlistenToKeyEvent,
|
unlistenToKeyEvent,
|
||||||
updateScreenSizeAndMaskArea,
|
updateScreenSizeAndMaskArea,
|
||||||
@ -16,39 +17,29 @@ const maskRef = ref<HTMLElement | null>(null);
|
|||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
let isShortcutInited = false;
|
|
||||||
|
|
||||||
onBeforeRouteLeave(() => {
|
onBeforeRouteLeave(() => {
|
||||||
if (isShortcutInited) {
|
if (maskRef.value && store.controledDevice) {
|
||||||
if (maskRef.value) {
|
unlistenToKeyEvent();
|
||||||
unlistenToKeyEvent();
|
clearShortcuts();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onActivated(async () => {
|
onActivated(async () => {
|
||||||
if (isShortcutInited) {
|
// TODO 每次进入都要重新应用快捷键,因为设定的屏幕尺寸可能都变了,但是闭包内提前换算的坐标的不会随之改变,只能重新添加,后续需要和配置文件结合(配置文件读取到store中,不要每次都io读取)
|
||||||
if (maskRef.value) {
|
if (maskRef.value && store.controledDevice) {
|
||||||
listenToKeyEvent();
|
const mt = 30;
|
||||||
}
|
const ml = 70;
|
||||||
return;
|
const appWindow = getCurrent();
|
||||||
}
|
const size = (await appWindow.outerSize()).toLogical(
|
||||||
if (store.controledDevice) {
|
await appWindow.scaleFactor()
|
||||||
if (maskRef.value) {
|
);
|
||||||
const mt = 30;
|
updateScreenSizeAndMaskArea(
|
||||||
const ml = 70;
|
[store.screenSizeW, store.screenSizeH],
|
||||||
const appWindow = getCurrent();
|
[size.width - ml, size.height - mt]
|
||||||
const size = (await appWindow.outerSize()).toLogical(
|
);
|
||||||
await appWindow.scaleFactor()
|
|
||||||
);
|
applyShortcuts(maskRef.value);
|
||||||
updateScreenSizeAndMaskArea(
|
listenToKeyEvent();
|
||||||
[store.screenSizeW, store.screenSizeH],
|
|
||||||
[size.width - ml, size.height - mt]
|
|
||||||
);
|
|
||||||
initShortcuts(maskRef.value);
|
|
||||||
listenToKeyEvent();
|
|
||||||
isShortcutInited = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -857,6 +857,14 @@ export function unlistenToKeyEvent() {
|
|||||||
loopFlag = false;
|
loopFlag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function clearShortcuts() {
|
||||||
|
downKeyMap.clear();
|
||||||
|
downKeyCBMap.clear();
|
||||||
|
loopDownKeyCBMap.clear();
|
||||||
|
upKeyCBMap.clear();
|
||||||
|
cancelAbleKeyList.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
export function updateScreenSizeAndMaskArea(
|
export function updateScreenSizeAndMaskArea(
|
||||||
screenSize: [number, number],
|
screenSize: [number, number],
|
||||||
maskArea: [number, number]
|
maskArea: [number, number]
|
||||||
@ -867,10 +875,12 @@ export function updateScreenSizeAndMaskArea(
|
|||||||
maskSizeH = maskArea[1];
|
maskSizeH = maskArea[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initShortcuts(element: HTMLElement) {
|
export function applyShortcuts(element: HTMLElement) {
|
||||||
element.addEventListener("mousedown", handleMouseDown);
|
element.addEventListener("mousedown", handleMouseDown);
|
||||||
element.addEventListener("mousemove", handleMouseMove);
|
element.addEventListener("mousemove", handleMouseMove);
|
||||||
element.addEventListener("mouseup", handleMouseUp);
|
element.addEventListener("mouseup", handleMouseUp);
|
||||||
|
// TODO 使用setCursorGrab相关来限制移出,而不是使用下面的方法
|
||||||
|
// TODO 任何down的时候都要限制移出
|
||||||
element.addEventListener("mouseout", handleMouseUp); // mouse out of the element as mouse up
|
element.addEventListener("mouseout", handleMouseUp); // mouse out of the element as mouse up
|
||||||
|
|
||||||
// 读取按键配置文件时获取
|
// 读取按键配置文件时获取
|
||||||
|
Loading…
Reference in New Issue
Block a user