From 6317699f6c8d4234600dfba47f7d0e5f1f8cf7f5 Mon Sep 17 00:00:00 2001 From: Megghy Date: Wed, 21 Feb 2024 12:35:24 +0800 Subject: [PATCH] add obs checker --- .husky/pre-commit | 6 ------ package.json | 1 + src/components/RegisterAndLogin.vue | 5 ++--- src/components/SongPlayer.vue | 3 +-- src/views/obs/LiveLotteryOBS.vue | 11 +++++++++++ src/views/obs/MusicRequestOBS.vue | 13 ++++++++++++- src/views/obs/QuestionDisplayOBS.vue | 20 ++++++++++++++++++-- src/views/obs/QueueOBS.vue | 12 ++++++++++++ src/views/obs/SongRequestOBS.vue | 12 ++++++++++++ yarn.lock | 8 ++++++++ 10 files changed, 77 insertions(+), 14 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index c645905..b5dc6a8 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,9 +1,3 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -# 自动修复 ESLint 检测到的问题 -npx eslint --fix 'src/**/*.{js,jsx,ts,tsx}' || true - # 使用 Prettier 格式化代码 npx prettier --write 'src/**/*.{js,jsx,ts,tsx,json,css,md}' diff --git a/package.json b/package.json index 79aef92..2af4f47 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "devDependencies": { "@eslint/eslintrc": "^3.0.1", "@types/eslint": "^8.56.2", + "@types/obs-studio": "^2.17.2", "@types/uuid": "^9.0.8", "@typescript-eslint/parser": "^7.0.1", "@vicons/ionicons5": "^0.12.0", diff --git a/src/components/RegisterAndLogin.vue b/src/components/RegisterAndLogin.vue index 2804329..694d413 100644 --- a/src/components/RegisterAndLogin.vue +++ b/src/components/RegisterAndLogin.vue @@ -20,7 +20,6 @@ interface LoginModel { const message = useMessage() -const isRegister = ref(false) const isLoading = ref(false) const registerModel = ref({} as RegisterModel) @@ -148,7 +147,7 @@ function onLoginButtonClick() { message.error(data.message) } }) - .catch((err) => { + .catch(() => { message.error('登陆失败') }) .finally(() => { @@ -166,7 +165,7 @@ async function onForgetPassword() { message.error(data.message) } }) - .catch((err) => { + .catch(() => { message.error('发生错误') }) .finally(() => { diff --git a/src/components/SongPlayer.vue b/src/components/SongPlayer.vue index d85cfcd..bf0edb8 100644 --- a/src/components/SongPlayer.vue +++ b/src/components/SongPlayer.vue @@ -3,14 +3,13 @@ import { SongFrom, SongsInfo } from '@/api/api-models' import { QueryGetAPI } from '@/api/query' import { SONG_API_URL } from '@/data/constants' import { NEmpty } from 'naive-ui' -import { computed, ref, toRef, watch } from 'vue' +import { computed, ref, watch } from 'vue' import APlayer from 'vue3-aplayer' const props = defineProps<{ song: SongsInfo | undefined isLrcLoading?: string }>() -const currentSong = toRef(props, 'song') const emits = defineEmits(['update:isLrcLoading']) const aplayerMusic = ref({ diff --git a/src/views/obs/LiveLotteryOBS.vue b/src/views/obs/LiveLotteryOBS.vue index 910eefe..b8af679 100644 --- a/src/views/obs/LiveLotteryOBS.vue +++ b/src/views/obs/LiveLotteryOBS.vue @@ -44,14 +44,25 @@ async function getUsers() { } as UpdateLiveLotteryUsersModel } +const visiable = ref(true) +const active = ref(true) let timer: any onMounted(() => { timer = setInterval(async () => { + if (!visiable.value || !active.value) return const r = await getUsers() if (r) { result.value = r } }, 2000) + //@ts-expect-error 这里获取不了 + window.obsstudio.onVisibilityChange = function (visibility: boolean) { + visiable.value = visibility + } + //@ts-expect-error 这里获取不了 + window.obsstudio.onActiveChange = function (a: boolean) { + active.value = a + } }) onUnmounted(() => { clearInterval(timer) diff --git a/src/views/obs/MusicRequestOBS.vue b/src/views/obs/MusicRequestOBS.vue index 17e967c..ccd992f 100644 --- a/src/views/obs/MusicRequestOBS.vue +++ b/src/views/obs/MusicRequestOBS.vue @@ -55,16 +55,27 @@ const isMoreThanContainer = computed(() => { return originSongs.value.waiting.length * itemHeight > height.value }) async function update() { + if (!visiable.value || !active.value) return const r = await get() if (r) { originSongs.value = r } } - +const visiable = ref(true) +const active = ref(true) let timer: any onMounted(() => { update() timer = setInterval(update, 2000) + + //@ts-expect-error 这里获取不了 + window.obsstudio.onVisibilityChange = function (visibility: boolean) { + visiable.value = visibility + } + //@ts-expect-error 这里获取不了 + window.obsstudio.onActiveChange = function (a: boolean) { + active.value = a + } }) onUnmounted(() => { clearInterval(timer) diff --git a/src/views/obs/QuestionDisplayOBS.vue b/src/views/obs/QuestionDisplayOBS.vue index c7ac3fd..cb2f085 100644 --- a/src/views/obs/QuestionDisplayOBS.vue +++ b/src/views/obs/QuestionDisplayOBS.vue @@ -3,7 +3,7 @@ import { QAInfo, Setting_QuestionDisplay } from '@/api/api-models' import { QueryGetAPI } from '@/api/query' import { QUESTION_API_URL } from '@/data/constants' import { useRouteQuery } from '@vueuse/router' -import { onMounted, ref } from 'vue' +import { onMounted, onUnmounted, ref } from 'vue' import QuestionDisplayCard from '../manage/QuestionDisplayCard.vue' const hash = ref('') @@ -44,10 +44,26 @@ async function getQuestionAndSetting() { } } +const visiable = ref(true) +const active = ref(true) +let timer: any onMounted(() => { - setInterval(() => { + timer = setInterval(() => { + if (!visiable.value || !active.value) return checkIfChanged() }, 1000) + + //@ts-expect-error 这里获取不了 + window.obsstudio.onVisibilityChange = function (visibility: boolean) { + visiable.value = visibility + } + //@ts-expect-error 这里获取不了 + window.obsstudio.onActiveChange = function (a: boolean) { + active.value = a + } +}) +onUnmounted(() => { + clearInterval(timer) }) diff --git a/src/views/obs/QueueOBS.vue b/src/views/obs/QueueOBS.vue index b894dc5..22f1872 100644 --- a/src/views/obs/QueueOBS.vue +++ b/src/views/obs/QueueOBS.vue @@ -97,6 +97,7 @@ const allowGuardTypes = computed(() => { return types }) async function update() { + if (!visiable.value || !active.value) return const r = await get() if (r) { queue.value = r.queue.sort((a, b) => { @@ -106,10 +107,21 @@ async function update() { } } +const visiable = ref(true) +const active = ref(true) let timer: any onMounted(() => { update() timer = setInterval(update, 2000) + + //@ts-expect-error 这里获取不了 + window.obsstudio.onVisibilityChange = function (visibility: boolean) { + visiable.value = visibility + } + //@ts-expect-error 这里获取不了 + window.obsstudio.onActiveChange = function (a: boolean) { + active.value = a + } }) onUnmounted(() => { clearInterval(timer) diff --git a/src/views/obs/SongRequestOBS.vue b/src/views/obs/SongRequestOBS.vue index 411778a..d02b6bc 100644 --- a/src/views/obs/SongRequestOBS.vue +++ b/src/views/obs/SongRequestOBS.vue @@ -76,6 +76,7 @@ const allowGuardTypes = computed(() => { return types }) async function update() { + if (!visiable.value || !active.value) return const r = await get() if (r) { originSongs.value = r.songs.sort((a, b) => { @@ -85,10 +86,21 @@ async function update() { } } +const visiable = ref(true) +const active = ref(true) let timer: any onMounted(() => { update() timer = setInterval(update, 2000) + + //@ts-expect-error 这里获取不了 + window.obsstudio.onVisibilityChange = function (visibility: boolean) { + visiable.value = visibility + } + //@ts-expect-error 这里获取不了 + window.obsstudio.onActiveChange = function (a: boolean) { + active.value = a + } }) onUnmounted(() => { clearInterval(timer) diff --git a/yarn.lock b/yarn.lock index 51d1dd6..0e8406d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1018,6 +1018,13 @@ __metadata: languageName: node linkType: hard +"@types/obs-studio@npm:^2.17.2": + version: 2.17.2 + resolution: "@types/obs-studio@npm:2.17.2" + checksum: 1c7a288532cbee075900882e845ef8b8038d096d77adc6daae13749d9e7f1d8699a87248406e834d70d264868f605c4dc09535fa2738334905d7aed2bfc4083e + languageName: node + linkType: hard + "@types/semver@npm:^7.5.0": version: 7.5.6 resolution: "@types/semver@npm:7.5.6" @@ -5327,6 +5334,7 @@ __metadata: "@eslint/eslintrc": "npm:^3.0.1" "@types/eslint": "npm:^8.56.2" "@types/node": "npm:^20.11.19" + "@types/obs-studio": "npm:^2.17.2" "@types/uuid": "npm:^9.0.8" "@typescript-eslint/eslint-plugin": "npm:^7.0.1" "@typescript-eslint/parser": "npm:^7.0.1"