XuqmGroup-RNSDK/packages/update/src/NativeVersion.ts
XuqmGroup febefc8d69 refactor: SDK monorepo with modular packages + clean init API
- Restructure as yarn workspace with packages/common, im, push, update
- @xuqm/rn-common: built-in URLs (no apiBaseUrl/imWsUrl in init), init({appId, debug})
- @xuqm/rn-im: login(userId) handles token internally, no token in public API
- @xuqm/rn-update: registerPlugin({moduleId,version}) for self-registration,
  checkAppUpdate() auto-detects version via XuqmVersionModule native bridge,
  checkRnUpdate(moduleId) uses registered version (no app-layer arg)
- Add XuqmVersionModule native stubs for Android/iOS
- Keep @xuqm/rn-sdk as convenience meta-package re-exporting all

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 16:16:31 +08:00

41 行
1.1 KiB
TypeScript

import { NativeModules } from 'react-native'
/**
* Native module interface. Provided by XuqmVersionModule (auto-linked).
*
* Android: reads BuildConfig.VERSION_CODE / VERSION_NAME
* iOS: reads CFBundleVersion / CFBundleShortVersionString
*
* If the native module is not linked (e.g. JS-only dev environment),
* falls back to a value set via _devSetAppVersionCode().
*/
interface XuqmVersionModuleInterface {
getVersionCode: () => number
getVersionName: () => string
}
const _native = NativeModules.XuqmVersionModule as XuqmVersionModuleInterface | undefined
let _devVersionCode = 0
let _devVersionName = '0.0.0'
/** Only for dev environments where the native module is not linked. */
export function _devSetAppVersion(versionCode: number, versionName = '0.0.0'): void {
_devVersionCode = versionCode
_devVersionName = versionName
}
export function getAppVersionCode(): number {
try {
if (_native?.getVersionCode) return _native.getVersionCode()
} catch {}
return _devVersionCode
}
export function getAppVersionName(): string {
try {
if (_native?.getVersionName) return _native.getVersionName()
} catch {}
return _devVersionName
}