// app.js
import {
  make_new_session_id,
} from './utils.js';

App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    this.globalData.verify_failures = 0;
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // On iOS, the js runtime is reported to be too slow for wasm, use experimental JIT worker.
    // https://developers.weixin.qq.com/community/develop/doc/000cac2319cbd8ecdc7f062eb53400
    this.globalData.get_worker = () => {
      if (!this.globalData.worker) {
        this.globalData.worker = wx.createWorker('worker/index.js', {
          useExperimentalWorker: true,
        });
      }
      return this.globalData.worker;
    }
  },
  onShow(options) {
    if (options.referrerInfo && options.referrerInfo.extraData && options.referrerInfo.extraData.caller_info) {
        var ci = options.referrerInfo.extraData.caller_info;
        this.globalData.caller_info = ci;
    }
  },
  globalData: {
    userInfo: null,
    server_url: 'https://themblem.com',
    session_id: make_new_session_id(),
  }
})
