Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

1.2 KB
Raw Blame
// Where this copy of the app came from, which decides who installs its updates:
//   'sideload' the APK from GitHub or opengym.ch: it checks GitHub and installs updates itself
//   'play'     Google Play, which updates it (and does not allow an app to update itself)
//   'appstore' the iPhone app, updated by the App Store
//   'web'      the browser, updated with its server
// Android says which build it is (ChannelPlugin.java, the build flavour). An APK from before the
// plugin existed is a sideloaded one: the Play build never shipped without it.
import { MOBILE } from './mobile.js'

let channelP = null
export function getChannel() {
  return channelP || (channelP = (async () => {
    if (!MOBILE) return 'web'
    const { Capacitor, registerPlugin } = await import('@capacitor/core')
    const platform = Capacitor.getPlatform()
    if (platform === 'ios') return 'appstore'
    if (platform !== 'android') return 'web'
    try {
      const { channel } = await registerPlugin('Channel').get()
      return channel === 'play' ? 'play' : 'sideload'
    } catch {
      return 'sideload'
    }
  })().catch(() => 'web'))
}

// The in-app updater is for the sideloaded APK only.
export async function selfUpdates() {
  return (await getChannel()) === 'sideload'
}