XuqmGroup-RNSDK/packages/update/src/NativeBundle.ts
XuqmGroup 07b08a4f5a feat: T-B01~B04 — XuqmBundleModule + onProgress + JSBridge/厂商文档
T-B01: XuqmBundleModule 原生模块
- Android: XuqmBundleModule.java(文件读写/manifest/路径)
- iOS: XuqmBundleModule.m(对应实现)
- JS: NativeBundle.ts 封装
- 注册到 XuqmUpdatePackage

T-B02: downloadPluginBundle 添加 onProgress
- 使用 ReadableStream 实现下载进度追踪
- checkAndCachePlugin 同步支持 onProgress

T-B03: XWebView JSBridge 标准接口文档
- docs/XWebView-JSBridge.md
- H5→RN 消息协议 / RN→H5 通信
- 下载处理 / Dialog 覆盖 / 标准 Bridge 接口

T-B04: PushSDK Android 厂商集成文档
- docs/PushSDK-厂商集成.md
- 6 厂商配置步骤 / ProGuard 规则 / 调试指南
2026-06-15 02:36:11 +08:00

94 行
2.4 KiB
TypeScript

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

/**
* XuqmBundleModule JS 封装。
*
* 提供 bundle 文件的原生管理能力:
* - 读取/写入/删除 bundle 文件
* - manifest 管理
* - bundle 路径查询
*
* 注意bundle 注入到运行中的 RN hostloadBundle
* 由宿主的 BundleRuntime 负责RN 0.84 不暴露公开 API
*/
import {NativeModules, Platform} from 'react-native'
interface XuqmBundleModuleInterface {
bundleExists(moduleId: string): Promise<boolean>
readBundle(moduleId: string): Promise<string>
writeBundle(moduleId: string, source: string, md5: string): Promise<boolean>
deleteBundle(moduleId: string): Promise<boolean>
getBundlePath(moduleId: string): Promise<string>
getManifest(): Promise<string>
writeManifest(manifestJson: string): Promise<boolean>
}
function getModule(): XuqmBundleModuleInterface {
const mod = NativeModules.XuqmBundleModule
if (!mod) {
throw new Error('[XuqmBundleModule] Native module not available')
}
return mod as XuqmBundleModuleInterface
}
export const NativeBundle = {
/**
* 检查指定 bundle 文件是否存在。
*/
async exists(moduleId: string): Promise<boolean> {
return getModule().bundleExists(moduleId)
},
/**
* 读取 bundle 文件内容JS 源码文本)。
*/
async read(moduleId: string): Promise<string> {
return getModule().readBundle(moduleId)
},
/**
* 将 bundle 源码写入本地文件。
*
* @param moduleId 插件 ID
* @param source JS 源码文本
* @param md5 文件 MD5 校验值
*/
async write(moduleId: string, source: string, md5: string): Promise<void> {
await getModule().writeBundle(moduleId, source, md5)
},
/**
* 删除指定 bundle 文件。
*/
async remove(moduleId: string): Promise<void> {
await getModule().deleteBundle(moduleId)
},
/**
* 获取 bundle 文件的绝对路径。
*/
async getPath(moduleId: string): Promise<string> {
return getModule().getBundlePath(moduleId)
},
/**
* 读取 manifest.json 内容。
*/
async getManifest(): Promise<string> {
return getModule().getManifest()
},
/**
* 写入 manifest.json。
*/
async writeManifest(manifestJson: string): Promise<void> {
await getModule().writeManifest(manifestJson)
},
/**
* 获取 bundle 文件名(平台相关)。
*/
getFileName(moduleId: string): string {
return `${moduleId}.${Platform.OS}.bundle`
},
}