123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
- import dayjs from 'dayjs'
- import { IPostMessage, listenerMessage, postMessage, removeListenerMessage } from '/src/helpers/native-message'
- import runtime, * as RuntimeUtils from '/src/pages/detail/runtime'
- import { permissionPopup } from '/src/subpages/colexiu/popups/permission/permission'
- import SettingState from '/src/pages/detail/setting-state'
- import detailState from '/src/pages/detail/state'
- import { storeKeys } from '/src/constant/store-keys'
- import { soundEffectShow } from '../popups/sound-effect'
- import { evaluatingShow } from '../popups/evaluating'
- import { Toast } from 'vant'
- /** 打开校音或者距离上一次校音超过一天 */
- const soundNeedShow = () => {
- if (runtime.evaluatingStatus) {
- let time: number = -1
- const timeString = localStorage.getItem(storeKeys.lastCheckTime)
- try {
- const date = dayjs(parseFloat(timeString || '0'))
- if (date.isValid()) {
- time = Math.abs(date.diff(dayjs(new Date().valueOf()), 'day'))
- }
- } catch (e) {}
- console.log(SettingState.sett.tuning, time, timeString)
- if (SettingState.sett.tuning || time > 0 || !timeString) {
- soundEffectShow.value = true
- }
- }
- }
- /**
- * 检查耳机连接状态,并且打开耳机连接状态的提示,以及校音
- * @param res IPostMessage
- */
- const setWiredStatus = (res?: IPostMessage) => {
- if (runtime.evaluatingStatus) {
- permissionPopup.active = 'earphone'
- permissionPopup.show = !res?.content.checkIsWired
- soundNeedShow()
- } else {
- permissionPopup.show = false
- }
- }
- /**
- * 开启评测模式后,需要效验 耳机,效音
- */
- export const handleCheckEvaluatStatus = () => {
- // 是否需要效音
- soundNeedShow()
- // 检测耳机状态
- // postMessage({ api: 'isWiredHeadsetOn' }, setWiredStatus)
- postMessage({ api: 'isWiredHeadsetOn' }, (evt) => {
- // console.log('🚀 ~ 耳机状态', evt)
- permissionPopup.active = 'earphone'
- permissionPopup.show = !evt?.content.checkIsWired
- })
- }
- /**
- * 监听评测状态打开
- */
- export const useWiredHeadsetCheck = () => {
- const wiredStatus = ref(false)
- // watch(
- // () => runtime.evaluatingStatus,
- // () => {
- // if (!runtime.evaluatingStatus) return
- // postMessage(
- // {
- // api: 'isWiredHeadsetOn',
- // },
- // setWiredStatus
- // )
- // }
- // )
- // watch(
- // () => permissionPopup.show,
- // () => {
- // soundNeedShow()
- // }
- // )
- /** 监听评测状态,退出评测模式停止播放,清除提示信息 */
- watch([() => runtime.evaluatingStatus], () => {
- // Toast.clear()
- // if (!runtime.evaluatingStatus) {
- // runtime.evaluatingTips = false
- // RuntimeUtils.pause()
- // RuntimeUtils.setCurrentTime(0)
- // }
- if (SettingState.sett.fingering) {
- // RuntimeUtils.event.emit('settingFingeringChange')
- }
- // console.log('settingFingeringChange', 11, runtime.evaluatingStatus)
- })
- /** 监听耳机状态啊 */
- watch(
- [() => runtime.evaluatingStatus, () => permissionPopup.show, () => soundEffectShow.value],
- ([evaluatingStatus, permissionShow, soundEffectShow]) => {
- // wiredStatus.value = evaluatingStatus && !permissionShow && !soundEffectShow
- // if (!runtime.evaluatingStatus) {
- // detailState.evaluatings = {}
- // evaluatingShow.value = false
- // }
- }
- )
- // onMounted(() => {
- // listenerMessage('listenerWiredStatus', setWiredStatus)
- // })
- // onBeforeUnmount(() => {
- // removeListenerMessage('listenerWiredStatus', setWiredStatus)
- // })
- return [wiredStatus]
- }
|