2024-04-13 09:53:41 +08:00
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { onActivated, ref } from "vue";
|
|
|
|
|
import { NDialog } from "naive-ui";
|
|
|
|
|
import { useGlobalStore } from "../store/global";
|
2024-04-14 17:15:39 +08:00
|
|
|
|
import { onBeforeRouteLeave, useRouter } from "vue-router";
|
2024-04-16 22:38:07 +08:00
|
|
|
|
import {
|
2024-04-18 11:03:19 +08:00
|
|
|
|
applyShortcuts,
|
|
|
|
|
clearShortcuts,
|
2024-04-16 22:38:07 +08:00
|
|
|
|
listenToKeyEvent,
|
|
|
|
|
unlistenToKeyEvent,
|
|
|
|
|
updateScreenSizeAndMaskArea,
|
|
|
|
|
} from "../hotkey";
|
|
|
|
|
import { getCurrent } from "@tauri-apps/api/window";
|
2024-04-13 09:53:41 +08:00
|
|
|
|
|
|
|
|
|
const maskRef = ref<HTMLElement | null>(null);
|
|
|
|
|
|
|
|
|
|
const store = useGlobalStore();
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
2024-04-14 17:15:39 +08:00
|
|
|
|
onBeforeRouteLeave(() => {
|
2024-04-18 11:03:19 +08:00
|
|
|
|
if (maskRef.value && store.controledDevice) {
|
|
|
|
|
unlistenToKeyEvent();
|
|
|
|
|
clearShortcuts();
|
2024-04-14 17:15:39 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-13 09:53:41 +08:00
|
|
|
|
onActivated(async () => {
|
2024-04-18 11:03:19 +08:00
|
|
|
|
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]
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-19 18:32:42 +08:00
|
|
|
|
applyShortcuts(maskRef.value, store.curKeyMappingConfig);
|
2024-04-18 11:03:19 +08:00
|
|
|
|
listenToKeyEvent();
|
2024-04-13 09:53:41 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function toStartServer() {
|
|
|
|
|
router.replace({ name: "device" });
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 11:01:42 +08:00
|
|
|
|
// TODO 3. 根据配置渲染按钮
|
2024-04-19 18:32:42 +08:00
|
|
|
|
// 配置文件读取到store中,不要每次都io读取
|
2024-04-13 09:53:41 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div v-show="!store.controledDevice" class="notice">
|
|
|
|
|
<div class="content">
|
|
|
|
|
<NDialog
|
|
|
|
|
:closable="false"
|
|
|
|
|
title="未找到受控设备"
|
|
|
|
|
content="请启动服务端并控制任意设备"
|
|
|
|
|
positive-text="去启动"
|
|
|
|
|
type="warning"
|
|
|
|
|
@positive-click="toStartServer"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
v-show="store.controledDevice"
|
2024-04-14 17:15:39 +08:00
|
|
|
|
@contextmenu.prevent
|
2024-04-13 09:53:41 +08:00
|
|
|
|
class="mask"
|
|
|
|
|
ref="maskRef"
|
|
|
|
|
></div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.mask {
|
2024-04-16 22:50:21 +08:00
|
|
|
|
background-color: transparent;
|
2024-04-13 09:53:41 +08:00
|
|
|
|
overflow: hidden;
|
2024-04-14 17:15:39 +08:00
|
|
|
|
cursor: pointer;
|
2024-04-13 09:53:41 +08:00
|
|
|
|
}
|
|
|
|
|
.notice {
|
2024-04-16 22:50:21 +08:00
|
|
|
|
background-color: rgba(0, 0, 0, 0.5);
|
2024-04-13 09:53:41 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
|
|
.content {
|
|
|
|
|
width: 80%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|