fix: mask area error

This commit is contained in:
AkiChase 2025-03-11 17:35:33 +08:00
parent 22b106bcbe
commit 098205c613
3 changed files with 29 additions and 25 deletions

View File

@ -20,6 +20,7 @@ const { t } = useI18n();
const store = useGlobalStore(); const store = useGlobalStore();
const router = useRouter(); const router = useRouter();
const message = useMessage(); const message = useMessage();
let initFlag = false;
const curPageActive = ref(false); const curPageActive = ref(false);
@ -34,7 +35,7 @@ onBeforeRouteLeave(() => {
onActivated(async () => { onActivated(async () => {
curPageActive.value = true; curPageActive.value = true;
cleanAfterimage(); if (initFlag) cleanAfterimage();
if (store.controledDevice) { if (store.controledDevice) {
if ( if (
@ -53,7 +54,7 @@ onActivated(async () => {
}); });
onMounted(() => { onMounted(() => {
secondaryInit(); secondaryInit().then(() => (initFlag = true));
}); });
onUnmounted(() => { onUnmounted(() => {

View File

@ -96,14 +96,19 @@ export async function initMaskArea() {
}>("maskArea")) ?? { posX: 100, posY: 100, sizeW: 800, sizeH: 600 }; }>("maskArea")) ?? { posX: 100, posY: 100, sizeW: 800, sizeH: 600 };
// mask area validation // mask area validation
const appWindow = getCurrentWindow();
let { posX, posY, sizeW, sizeH } = maskArea;
const mt = 30; const mt = 30;
const ml = 70; const ml = 70;
const appWindow = getCurrentWindow();
let [winX, winY, winW, winH] = [
maskArea.posX - ml,
maskArea.posY - mt,
maskArea.sizeW + ml,
maskArea.sizeH + mt,
];
// min size // min size
if (sizeW < 120) sizeW = 120; if (winW < 200) winW = 200;
if (sizeH < 120) sizeH = 120; if (winH < 200) winH = 200;
let monitor = await currentMonitor(); let monitor = await currentMonitor();
if (monitor === null) monitor = await primaryMonitor(); if (monitor === null) monitor = await primaryMonitor();
@ -113,8 +118,8 @@ export async function initMaskArea() {
const monitorPos = monitor.position.toLogical(monitor.scaleFactor); const monitorPos = monitor.position.toLogical(monitor.scaleFactor);
// max size // max size
if (sizeW > monitorSize.width - ml) sizeW = monitorSize.width - ml; if (winW > monitorSize.width - ml) winW = monitorSize.width;
if (sizeH > monitorSize.height - mt) sizeH = monitorSize.height - mt; if (winH > monitorSize.height - mt) winH = monitorSize.height;
const tlPos = { x: monitorPos.x, y: monitorPos.y }; const tlPos = { x: monitorPos.x, y: monitorPos.y };
const brPos = { const brPos = {
@ -124,28 +129,28 @@ export async function initMaskArea() {
// min pos (bottom right corner) // min pos (bottom right corner)
// move to top left corner // move to top left corner
if (posX + sizeW < tlPos.x) posX = tlPos.x + ml; if (winX + winW < tlPos.x) winX = tlPos.x;
if (posY + sizeH < tlPos.y) posY = tlPos.y + mt; if (winY + winH < tlPos.y) winY = tlPos.y;
if (brPos !== null) { if (brPos !== null) {
// max pos (top left corner) // max pos (top left corner)
// move to bottom right corner // move to bottom right corner
if (posX > brPos.x) posX = brPos.x - sizeW; if (winX > brPos.x) winX = brPos.x - winW;
if (posY > brPos.y) posY = brPos.y - sizeH; if (winY > brPos.y) winY = brPos.y - winH;
} }
} }
[sizeW, sizeH] = [sizeW, sizeH].map((v) => Math.round(v)); [winW, winH] = [winW, winH].map((v) => Math.round(v));
[posX, posY] = [posX, posY].map((v) => Math.round(v)); [winX, winY] = [winX, winY].map((v) => Math.round(v));
appWindow.setSize(new LogicalSize(sizeW + ml, sizeH + mt)); appWindow.setSize(new LogicalSize(winW, winH));
appWindow.setPosition(new LogicalPosition(posX - 70, posY - 30)); appWindow.setPosition(new LogicalPosition(winX, winY));
NonReactiveStore.setLocal("maskArea", { NonReactiveStore.local.maskArea = {
posX, posX: winX + ml,
posY, posY: winY + mt,
sizeW, sizeW: winW - ml,
sizeH, sizeH: winH - mt,
}); };
} }
// init keyMappingConfigList from local store // init keyMappingConfigList from local store

View File

@ -34,7 +34,5 @@ export async function cleanAfterimage() {
const oldSize = (await appWindow.innerSize()).toLogical(scale); const oldSize = (await appWindow.innerSize()).toLogical(scale);
const newSize = new LogicalSize(oldSize.width, oldSize.height + 1); const newSize = new LogicalSize(oldSize.width, oldSize.height + 1);
await appWindow.setSize(newSize); await appWindow.setSize(newSize);
setTimeout(() => { await appWindow.setSize(oldSize);
appWindow.setSize(oldSize);
}, 150);
} }