const transport = require('./transport/ble-core.js')
const themeService = require('./store/theme-store.js')

transport.configureProtocolHelpers(() => require('./protocols/transport-helpers.js'))

function deferStartupWork(task) {
  if (typeof task !== 'function') return

  if (typeof setTimeout === 'function') {
    setTimeout(task, 120)
    return
  }

  task()
}

App({
  onShow() {
    deferStartupWork(() => {
      try {
        themeService.syncWithSystemTheme()
        Promise.resolve(transport.handleAppShow()).catch(() => {})
      } catch (error) {}
    })
  },

  onHide() {
    transport.handleAppHide()
  }
})
