import { loadBackendAuthTokens, loadBackendBaseUrl } from './utils/backendAuth'

// app.ts
App<IAppOption>({
  globalData: {
    telemetryPlayerProfile: null,
    backendBaseUrl: null,
    backendAuthTokens: null,
    pendingResultSnapshot: null,
    pendingResultLaunchEnvelope: null,
    pendingHeartRateAutoConnect: null,
  },
  onLaunch() {
    this.globalData.backendBaseUrl = loadBackendBaseUrl()
    this.globalData.backendAuthTokens = loadBackendAuthTokens()

    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: () => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      },
    })
  },
})
