import { authorize, getMenuButtonBoundingClientRect, getSetting } from "@tarojs/taro";
import { ref } from "vue";

export function useAppInitInfo() {
  const rect = getMenuButtonBoundingClientRect();
  const topDistance = ref(rect.height + rect.top + 10);

  const checkCamearSetting = () => {
    return getSetting().then(res => {
      if(res.authSetting["scope.camera"]) {
        return true
      } else {        
        return new Promise((resolve) => {
          authorize({
            scope: 'scope.camera',
            success: () => resolve(true),
            fail: () => resolve(false)
          })
        })
      }
    })
  }

  return {
    rect,
    topDistance,
    checkCamearSetting
  }
}