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