@oh-expo/expo-task-manager
v55.0.16-harmony.0
Published
expo-task-manager 的 HarmonyOS 适配包(ExpoModule 原生模块 + TaskManager 任务执行协议,expo-modules-core 体系)
Maintainers
Readme
@oh-expo/expo-task-manager
让
expo-task-manager(后台任务管理)在 HarmonyOS / OpenHarmony 上运行的适配包。
通过 expo-modules-core 体系提供 ExpoTaskManagerModule 原生模块(模块名 ExpoTaskManager)+
TaskManager.executeTask 事件(原生任务执行协议),接口收口自
[email protected] 权威 d.ts。
支持基线
| 项 | 值 |
| --- | --- |
| 适配目标 | [email protected] |
| 运行时底座 | @expo-harmony/[email protected](本地 HAR) |
| 鸿蒙 SDK | API 26(SDK 26.0.0 锚定,@kit.AbilityKit + @kit.ArkData preferences + @kit.ArkTS util) |
| 权限 | 无 |
实现面
- 7 方法:
isAvailableAsync/notifyTaskFinishedAsync/isTaskRegisteredAsync/getTaskOptionsAsync/getRegisteredTasksAsync/unregisterTaskAsync/unregisterAllTasksAsync+EVENT_NAME常量; - 任务注册表:preferences 持久化 + 注册代次(registrationGeneration)、损坏自愈 (corrupted 记录修复 + 诊断日志);
- 待执行请求队列:queued/executing/finishing/expiring 四相位状态机 + claim 令牌 + owner 主从选择(前台优先)+ 退避重试(1s→60s 指数抖动)+ 持久化恢复;
ExpoTaskManagerBackgroundQueue/ExpoTaskManagerWorkMetadata:WorkScheduler 持久化边界(enqueue/expireRequest + owner 元数据协议),供后台任务消费方使用;- 诚实分级:任务执行走
TaskManager.executeTask事件(JS 侧 TaskManager 订阅); 相位/参数严格校验(ERR_TASK_MANAGER_*)。
快速开始
安装 npm 包(peer 依赖
expo-task-manager原包与 expo-modules-core 自动安装):npm install @oh-expo/expo-task-manager拷贝 HAR 到宿主并声明 ohpm 依赖:
cp node_modules/@oh-expo/expo-task-manager/local-hars/expo_task_manager.har harmony/local-hars/// harmony/oh-package.json5 { "dependencies": { "@oh-expo/expo-task-manager": "file:local-hars/expo_task_manager.har" } }JS 侧使用(对外契约由原包提供):
import * as TaskManager from 'expo-task-manager';
构建与校验
pnpm har:prepare # hvigorw assembleHar → local-hars/expo_task_manager.har
pnpm har:prepack # 发布前校验(必需文件 / scope / -harmony.N 版本 / HAR 产物)状态与来源
- ⚠️ 实现已落盘并经 assembleHar / 宿主接入编译验证(真机功能验证 ⏳);
- 接口契约锚定
[email protected]权威 d.ts,规格见主仓docs/adaptations/expo-task-manager.md与acceptance/ledger.md(S4 前置门口径)。
