feat: 初始化完整应用框架

- 切换到 expo-router 文件路由,删除 App.tsx
- 新增 5 个 Expo 原生插件:ppocr (OCR), accessibility (账单抓取),
  notification-listener, screenshot-monitor, sms-receiver
- 实现核心领域逻辑:billPipeline (账单流水), dedup (去重),
  transferRecognizer (转账识别), ruleEngine + categories (双轨制分类),
  budgets, creditCards, recurring, sync, ocrProcessor
- 增强 ledger.ts:支持 balance assertion, option, pad/note 指令,
  posting 级 metadata, cost/price 解析
- 新增完整 UI:tabs (首页/报表/设置), 交易详情, 预算, 日历热力图,
  分类管理, 信用卡, 定期交易, 规则管理
- 实现 Zustand 状态管理:ledgerStore, importStore, settingsStore,
  metadataStore, automationStore + 持久化
- 新增 AI 功能:chatAssistant, monthlySummary, voiceInput
- 实现多端同步:gitSync, webdavSync, icloudSync
- 新增主题系统 (tokens/presets) 和 i18n (zh/en)
- 添加 30+ 单元测试覆盖核心逻辑
This commit is contained in:
fengmengqi
2026-07-15 10:01:31 +08:00
parent 167adfca62
commit f6437b83fe
171 changed files with 34937 additions and 1229 deletions
+188
View File
@@ -0,0 +1,188 @@
/**
* 无障碍服务 Config Pluginplan.md「3.6 无障碍服务」+「决策 4」)。
*
* 在 expo prebuild 时注册 Android 无障碍服务(manifest service + xml 配置)。
* 参考 AutoAccounting 的 SelectToSpeakService 伪装机制(侧载保留,plan.md 决策 3)。
*
* 注意:withAndroidManifest 的 modResults 结构是 { manifest: { ... } }
* 操作 application 必须通过 modResults.manifest.application。
*/
const { withAndroidManifest, withDangerousMod, withMainApplication } = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');
const PACKAGE = 'com.beancount.mobile.accessibility';
/** 递归复制目录。 */
function copyDir(src, dest) {
if (!fs.existsSync(src)) return;
fs.mkdirSync(dest, { recursive: true });
for (const entry of fs.readdirSync(src)) {
const s = path.join(src, entry);
const d = path.join(dest, entry);
if (fs.statSync(s).isDirectory()) copyDir(s, d);
else fs.copyFileSync(s, d);
}
}
function withAccessibilityService(config) {
// 1. 复制 Kotlin 源码 + res/xml 资源到原生工程
config = withDangerousMod(config, [
'android',
async (modConfig) => {
const projectRoot = modConfig.modRequest.platformProjectRoot;
// Kotlin 源码(只复制 .kt 文件,不含 res/ 子目录)
const ktDest = path.join(projectRoot, 'app/src/main/java/com/beancount/mobile/accessibility');
fs.mkdirSync(ktDest, { recursive: true });
const androidDir = path.join(__dirname, 'android');
for (const f of fs.readdirSync(androidDir)) {
if (f.endsWith('.kt')) {
fs.copyFileSync(path.join(androidDir, f), path.join(ktDest, f));
}
}
// res/xml 资源
const resSrc = path.join(__dirname, 'android/res');
if (fs.existsSync(resSrc)) {
copyDir(resSrc, path.join(projectRoot, 'app/src/main/res'));
}
// 确保有 accessibility_service_description 字符串资源
const stringsXmlPath = path.join(projectRoot, 'app/src/main/res/values/strings.xml');
if (fs.existsSync(stringsXmlPath)) {
let content = fs.readFileSync(stringsXmlPath, 'utf8');
if (!content.includes('accessibility_service_description')) {
content = content.replace(
/<\/resources>/,
' <string name="accessibility_service_description">自动识别支付账单页面,辅助快速记账</string>\n</resources>',
);
fs.writeFileSync(stringsXmlPath, content, 'utf8');
}
}
return modConfig;
},
]);
// 2. 注入 ReactContextHolder 赋值 + 注册 AccessibilityBridgePackage 到 MainApplication
config = withMainApplication(config, (modConfig) => {
let content = modConfig.modResults.contents;
// 2a. 注入 importReactContextHolder + AccessibilityBridgePackage
if (!content.includes(`import ${PACKAGE}.ReactContextHolder`)) {
content = content.replace(
/^(package\s+[\w.]+;?\s*)$/m,
`$1\nimport ${PACKAGE}.ReactContextHolder\nimport ${PACKAGE}.AccessibilityBridgePackage`,
);
} else if (!content.includes(`import ${PACKAGE}.AccessibilityBridgePackage`)) {
content = content.replace(
`import ${PACKAGE}.ReactContextHolder`,
`import ${PACKAGE}.ReactContextHolder\nimport ${PACKAGE}.AccessibilityBridgePackage`,
);
}
// 2b. 在 onCreate 方法中注入 ReactContextHolder.context = this
if (!content.includes('ReactContextHolder.context')) {
// 尝试在 super.onCreate() 后注入
if (/super\.onCreate\(\)/.test(content)) {
content = content.replace(
/(super\.onCreate\(\))/,
`$1\n // 由 Config Plugin 注入:让原生服务能访问 RN 上下文\n ReactContextHolder.context = this`,
);
} else if (/onCreate/.test(content)) {
// 有 onCreate 但没有 super.onCreate()(不太可能)
content = content.replace(
/(onCreate[^{]*\{)/,
`$1\n ReactContextHolder.context = this`,
);
} else {
// 没有 onCreate — 在类体内注入一个
content = content.replace(
/(class\s+MainApplication\s*[^{]*\{)/,
`$1\n override fun onCreate() {\n super.onCreate()\n ReactContextHolder.context = this\n }`,
);
}
}
// 2c. 在 getPackages() 的 .apply {} 块里注入 add(AccessibilityBridgePackage())
if (!content.includes('add(AccessibilityBridgePackage())')) {
if (/PackageList\(this\)\.packages\.apply\s*\{/.test(content)) {
content = content.replace(
/(PackageList\(this\)\.packages\.apply\s*\{)/,
`$1\n add(AccessibilityBridgePackage())`,
);
} else if (/PackageList\(this\)\.packages\b/.test(content)) {
content = content.replace(
/PackageList\(this\)\.packages\b/,
`PackageList(this).packages.apply { add(AccessibilityBridgePackage()) }`,
);
}
}
modConfig.modResults.contents = content;
return modConfig;
});
// 3. 注册服务到 AndroidManifest
config = withAndroidManifest(config, (modConfig) => {
const manifest = modConfig.modResults.manifest;
// 1. 添加无障碍服务声明
const serviceNode = {
$: {
'android:name': 'com.beancount.mobile.accessibility.BillingAccessibilityService',
'android:permission': 'android.permission.BIND_ACCESSIBILITY_SERVICE',
'android:label': '账单识别',
'android:exported': 'false',
},
'intent-filter': [{
action: [{ $: { 'android:name': 'android.accessibilityservice.AccessibilityService' } }],
}],
'meta-data': [{
$: {
'android:name': 'android.accessibilityservice',
'android:resource': '@xml/accessibility_service_config',
},
}],
};
// 2. 确保 application[0] 存在
if (!Array.isArray(manifest.application) || manifest.application.length === 0) {
manifest.application = [{ $: {} }];
}
const app = manifest.application[0];
if (!app.service) {
app.service = [];
}
const exists = app.service.some(
s => s.$['android:name'] === 'com.beancount.mobile.accessibility.BillingAccessibilityService'
);
if (!exists) {
app.service.push(serviceNode);
}
// 3. 添加 OcrTileService 声明(快速设置磁贴,plan.md「3.11」)
const tileServiceNode = {
$: {
'android:name': 'com.beancount.mobile.accessibility.OcrTileService',
'android:label': 'OCR 记账',
'android:icon': '@android:drawable/ic_menu_camera',
'android:permission': 'android.permission.BIND_QUICK_SETTINGS_TILE',
'android:exported': 'true',
},
'intent-filter': [{
action: [{ $: { 'android:name': 'android.service.quicksettings.action.QS_TILE' } }],
}],
};
const tileExists = app.service.some(
s => s.$['android:name'] === 'com.beancount.mobile.accessibility.OcrTileService'
);
if (!tileExists) {
app.service.push(tileServiceNode);
}
return modConfig;
});
return config;
}
module.exports = withAccessibilityService;
+6
View File
@@ -0,0 +1,6 @@
{
"name": "beancount-mobile-plugin-accessibility",
"version": "0.1.0",
"private": true,
"main": "app.plugin.js"
}
@@ -0,0 +1,69 @@
/**
* 通知监听 Config Pluginplan.md「4.1 通知监听服务」+「决策 4」)。
*
* 在 expo prebuild 时注册 Android NotificationListenerServicemanifest service + 权限)。
*
* 注意:withAndroidManifest 的 modResults 结构是 { manifest: { ... } }
* 操作 application 必须通过 modResults.manifest.application。
*/
const { withAndroidManifest, withDangerousMod } = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');
function withNotificationListener(config) {
// 1. 复制 Kotlin 源码到原生工程
config = withDangerousMod(config, [
'android',
async (modConfig) => {
const projectRoot = modConfig.modRequest.platformProjectRoot;
const dest = path.join(projectRoot, 'app/src/main/java/com/beancount/mobile/notification');
fs.mkdirSync(dest, { recursive: true });
const srcDir = path.join(__dirname, 'android');
for (const f of fs.readdirSync(srcDir)) {
if (f.endsWith('.kt')) {
fs.copyFileSync(path.join(srcDir, f), path.join(dest, f));
}
}
return modConfig;
},
]);
// 2. 注册服务到 AndroidManifest
config = withAndroidManifest(config, (modConfig) => {
const manifest = modConfig.modResults.manifest;
// 1. 添加通知监听服务
const serviceNode = {
$: {
'android:name': 'com.beancount.mobile.notification.BillingNotificationListenerService',
'android:permission': 'android.permission.BIND_NOTIFICATION_LISTENER_SERVICE',
'android:exported': 'false',
},
'intent-filter': [{
action: [{ $: { 'android:name': 'android.service.notification.NotificationListenerService' } }],
}],
};
// 2. 确保 application[0] 存在
if (!Array.isArray(manifest.application) || manifest.application.length === 0) {
manifest.application = [{ $: {} }];
}
const app = manifest.application[0];
if (!app.service) {
app.service = [];
}
const exists = app.service.some(
s => s.$['android:name'] === 'com.beancount.mobile.notification.BillingNotificationListenerService'
);
if (!exists) {
app.service.push(serviceNode);
}
return modConfig;
});
return config;
}
module.exports = withNotificationListener;
@@ -0,0 +1,6 @@
{
"name": "beancount-mobile-plugin-notification-listener",
"version": "0.1.0",
"private": true,
"main": "app.plugin.js"
}
+78
View File
@@ -0,0 +1,78 @@
# PP-OCRv5 (ONNX Runtime) Config Plugin
本插件在 `expo prebuild` 时注入 PP-OCRv5 本地 OCR 原生模块(plan.md 决策 4)。
引擎选用 **ONNX Runtime**(跨平台、微软官方、Windows 友好),替代原 NCNN 方案。
## 文件结构
```
plugins/ppocr/
├── app.plugin.js # Config Plugin 入口(prebuild 时执行)
├── android/ # Kotlin 原生实现(prebuild 时复制进原生工程)
│ ├── OcrModule.kt # React Native BridgeONNX Runtime 推理 + det/rec 前后处理
│ └── OcrPackage.kt # RN Package 注册(注入到 MainApplication.getPackages
└── assets/ # ONNX 模型 + 字典(需自行下载放置)
├── ppocrv5_det.onnx # 文本检测模型
├── ppocrv5_rec.onnx # 文本识别模型
└── ppocr_keys_v1.txt # CJK 字典(CTC 解码用)
```
## 模型获取(一键下载)
社区已转好的 ONNX 版本(来自官方 Paddle 权重,无质量损失):
```bash
# 在项目根目录执行
mkdir -p plugins/ppocr/assets
cd plugins/ppocr/assets
# det 模型(4.8 MB
curl -L -o ppocrv5_det.onnx https://huggingface.co/ilaylow/PP_OCRv5_mobile_onnx/resolve/main/ppocrv5_det.onnx
# rec 模型(16.6 MB
curl -L -o ppocrv5_rec.onnx https://huggingface.co/ilaylow/PP_OCRv5_mobile_onnx/resolve/main/ppocrv5_rec.onnx
# CJK 字典(26 KBPaddleOCR 标准字典)
curl -L -o ppocr_keys_v1.txt https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.6/ppocr/utils/ppocr_keys_v1.txt
```
或用 HuggingFace CLI(首次下载原生模型再转 ONNX 的方式,参见历史 git log)。
> 来源说明:[ilaylow/PP_OCRv5_mobile_onnx](https://huggingface.co/ilaylow/PP_OCRv5_mobile_onnx) 是社区维护的 PP-OCRv5 mobile ONNX 镜像,基于官方 [PaddlePaddle/PP-OCRv5_mobile_det](https://huggingface.co/PaddlePaddle/PP-OCRv5_mobile_det) 与 [_rec](https://huggingface.co/PaddlePaddle/PP-OCRv5_mobile_rec) 转换而来。
## 性能配置(参考 AutoAccounting OcrProcessor.kt
| 优化项 | 配置 |
|--------|------|
| 引擎 | ONNX Runtime Android 1.20.1 |
| 执行器 | CPU(兼容性最稳,部分设备 GPU 会崩溃) |
| 线程 | intraOp=2 / interOp=2 |
| det 图像 | 最大边 960px,短边压缩 720px |
| rec 图像 | 固定高度 48px |
| ABI | arm64-v8a(主流设备) |
## 使用
`app.json` 注册插件:
```json
{
"plugins": ["./plugins/ppocr"]
}
```
JS 层通过 `src/services/ocrBridge.ts``NativeOcrBridge` 调用,桥接到 `NativeModules.PpOcr`
- `recognizeText(base64)` → 返回纯文本(多行用 `\n` 连接)
- `recognizeTextBlocks(base64)` → 返回带坐标的文本块数组 `[{text, x, y, width, height, confidence}]`
- `isReady()` → 模型是否加载完成
## 当前状态
- `app.plugin.js`:✅ Config Plugin 逻辑(prebuild 注入 Kotlin + 模型 + gradle 依赖 + MainApplication 注册)
- `android/OcrModule.kt`:✅ ONNX Runtime 推理(det DB 后处理 + rec CTC 解码)
- `android/OcrPackage.kt`:✅ RN Package 注册
- `assets/`:需自行下载放置(见上「模型获取」),版权/体积原因不入仓库
真机构建步骤:放置模型文件 → `npx expo prebuild --platform android``npx expo run:android`
+120
View File
@@ -0,0 +1,120 @@
/**
* PP-OCRv5 (ONNX Runtime) Config Pluginplan.md「决策 4 Expo Config Plugin 方案」+「3.4 Layer 2」)。
*
* 本插件在 expo prebuild 时:
* 1. 复制 Kotlin 源码(OcrModule.kt + OcrPackage.kt)到 android/app/src/main/java/...
* 2. 复制 ONNX 模型与字典到 android/app/src/main/assets
* 3. 注册 OcrPackage 到 MainApplicationgetPackages
* 4. 添加 onnxruntime-android 依赖(app/build.gradle
*
* 引擎:ONNX Runtime(跨平台、微软官方、Windows 友好),替代 NCNN 路线。
* 注意:SDK 54 的 @expo/config-plugins 暴露的是 withMainApplication / withAppBuildGradle
* (没有 withAndroidMainApplication / withAndroidGradle)。文件复制用 withDangerousMod。
*
* 模型文件放 plugins/ppocr/assets/,版权/体积原因不入仓库,需自行下载(见 README.md)。
*/
const {
withMainApplication,
withAppBuildGradle,
withDangerousMod,
} = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');
const PACKAGE = 'com.beancount.mobile.ppocr';
/** 递归复制目录,prebuild 阶段执行一次。 */
function copyDir(src, dest) {
if (!fs.existsSync(src)) return;
fs.mkdirSync(dest, { recursive: true });
for (const entry of fs.readdirSync(src)) {
const s = path.join(src, entry);
const d = path.join(dest, entry);
if (fs.statSync(s).isDirectory()) copyDir(s, d);
else fs.copyFileSync(s, d);
}
}
function withPpOcr(config) {
// 1+2. 复制 Kotlin 源码与 ONNX 模型/字典到原生工程
config = withDangerousMod(config, [
'android',
async (modConfig) => {
// platformProjectRoot 在 modRequest 里(项目根的 android/ 子目录)
const projectRoot = modConfig.modRequest.platformProjectRoot;
// Kotlin 源码(OcrModule.kt + OcrPackage.kt
copyDir(
path.join(__dirname, 'android'),
path.join(projectRoot, 'app/src/main/java/com/beancount/mobile/ppocr'),
);
// ONNX 模型 + 字典(若已下载)
const assetsSrc = path.join(__dirname, 'assets');
if (fs.existsSync(assetsSrc)) {
copyDir(
assetsSrc,
path.join(projectRoot, 'app/src/main/assets'),
);
}
return modConfig;
},
]);
// 3. 注册 OcrPackage 到 MainApplication
config = withMainApplication(config, (modConfig) => {
let content = modConfig.modResults.contents;
// 3a. 注入 import(在 package 声明行后插入)
if (!content.includes(`import ${PACKAGE}.OcrPackage`)) {
content = content.replace(
/^(package\s+[\w.]+;?\s*)$/m,
`$1\nimport ${PACKAGE}.OcrPackage`,
);
}
// 3b. 在 getPackages() 的 .apply {} 块里注入 add(OcrPackage())
if (!content.includes('add(OcrPackage())')) {
if (/PackageList\(this\)\.packages\.apply\s*\{/.test(content)) {
// 新架构 KotlinSDK 54 默认):模板已有空 .apply {} 块,在块开头注入
content = content.replace(
/(PackageList\(this\)\.packages\.apply\s*\{)/,
`$1\n // PP-OCRv5 ONNX 原生模块(由 Config Plugin 注入)\n add(OcrPackage())`,
);
} else if (/PackageList\(this\)\.packages\b/.test(content)) {
// 新架构变体:.packages 后没有 .apply,包一层
content = content.replace(
/PackageList\(this\)\.packages\b/,
`PackageList(this).packages.apply { add(OcrPackage()) }`,
);
} else if (/\breturn\s+packages\s*;/.test(content)) {
// 老架构 Java:在 return packages; 前插入
content = content.replace(
/(\breturn\s+packages\s*;)/,
`packages.add(new OcrPackage());\n $1`,
);
}
}
modConfig.modResults.contents = content;
return modConfig;
});
// 4. 配置 app/build.gradle 依赖(ONNX Runtime Android
config = withAppBuildGradle(config, (modConfig) => {
let gradle = modConfig.modResults.contents;
if (!gradle.includes('onnxruntime')) {
// 在 dependencies { ... } 块末尾追加
gradle = gradle.replace(
/dependencies\s*{([\s\S]*?)^\s*}/m,
(m, inner) =>
`dependencies {${inner}\n // PP-OCRv5 ONNX Runtime(由 Config Plugin 注入)\n implementation 'com.microsoft.onnxruntime:onnxruntime-android:1.20.0'\n}`,
);
}
modConfig.modResults.contents = gradle;
return modConfig;
});
return config;
}
module.exports = withPpOcr;
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
{
"name": "beancount-mobile-plugin-ppocr",
"version": "0.1.0",
"private": true,
"main": "app.plugin.js"
}
+88
View File
@@ -0,0 +1,88 @@
/**
* 截图监听 Config Pluginplan.md「3.13 截图自动记账通道」+「决策 4」)。
*
* Android: ContentObserver 监听 MediaStore Screenshots(需 READ_MEDIA_IMAGES 权限)
* iOS: AppIntent 自动记账(通过 expo 配置,原生 Swift 实现)
*
* 注意:withAndroidManifest 的 modResults 结构是 { manifest: { ... } }
* 操作权限必须通过 modResults.manifest['uses-permission']。
*/
const { withAndroidManifest, withDangerousMod, withMainApplication } = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');
const PACKAGE = 'com.beancount.mobile.screenshot';
function withScreenshotMonitor(config) {
// 1. 复制 Kotlin 源码到原生工程
config = withDangerousMod(config, [
'android',
async (modConfig) => {
const projectRoot = modConfig.modRequest.platformProjectRoot;
const dest = path.join(projectRoot, 'app/src/main/java/com/beancount/mobile/screenshot');
fs.mkdirSync(dest, { recursive: true });
const srcDir = path.join(__dirname, 'android');
for (const f of fs.readdirSync(srcDir)) {
if (f.endsWith('.kt')) {
fs.copyFileSync(path.join(srcDir, f), path.join(dest, f));
}
}
return modConfig;
},
]);
// 2. 注册 ScreenshotPackage 到 MainApplication(复制 ppocr 模式)
config = withMainApplication(config, (modConfig) => {
let content = modConfig.modResults.contents;
// 2a. 注入 import
if (!content.includes(`import ${PACKAGE}.ScreenshotPackage`)) {
content = content.replace(
/^(package\s+[\w.]+;?\s*)$/m,
`$1\nimport ${PACKAGE}.ScreenshotPackage`,
);
}
// 2b. 在 getPackages() 的 .apply {} 块里注入 add(ScreenshotPackage())
if (!content.includes('add(ScreenshotPackage())')) {
if (/PackageList\(this\)\.packages\.apply\s*\{/.test(content)) {
content = content.replace(
/(PackageList\(this\)\.packages\.apply\s*\{)/,
`$1\n add(ScreenshotPackage())`,
);
} else if (/PackageList\(this\)\.packages\b/.test(content)) {
content = content.replace(
/PackageList\(this\)\.packages\b/,
`PackageList(this).packages.apply { add(ScreenshotPackage()) }`,
);
}
}
modConfig.modResults.contents = content;
return modConfig;
});
// 3. 添加 READ_MEDIA_IMAGES 权限(Android 13+
config = withAndroidManifest(config, (modConfig) => {
const manifest = modConfig.modResults.manifest;
if (!manifest['uses-permission']) {
manifest['uses-permission'] = [];
}
const perms = [
'android.permission.READ_MEDIA_IMAGES',
'android.permission.READ_EXTERNAL_STORAGE',
];
for (const perm of perms) {
const exists = manifest['uses-permission'].some(p => p.$['android:name'] === perm);
if (!exists) {
manifest['uses-permission'].push({ $: { 'android:name': perm } });
}
}
return modConfig;
});
return config;
}
module.exports = withScreenshotMonitor;
+6
View File
@@ -0,0 +1,6 @@
{
"name": "beancount-mobile-plugin-screenshot-monitor",
"version": "0.1.0",
"private": true,
"main": "app.plugin.js"
}
+80
View File
@@ -0,0 +1,80 @@
/**
* 短信监听 Config Pluginplan.md「4.2 短信监听服务」+「决策 4」)。
*
* 在 expo prebuild 时注册 Android SmsReceivermanifest receiver + RECEIVE_SMS 权限)。
*
* 注意:withAndroidManifest 的 modResults 结构是 { manifest: { ... } }
* 操作权限/application 必须通过 modResults.manifest,不是 modResults 本身。
*/
const { withAndroidManifest, withDangerousMod } = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');
function withSmsReceiver(config) {
// 1. 复制 Kotlin 源码到原生工程
config = withDangerousMod(config, [
'android',
async (modConfig) => {
const projectRoot = modConfig.modRequest.platformProjectRoot;
const dest = path.join(projectRoot, 'app/src/main/java/com/beancount/mobile/sms');
fs.mkdirSync(dest, { recursive: true });
const srcDir = path.join(__dirname, 'android');
for (const f of fs.readdirSync(srcDir)) {
if (f.endsWith('.kt')) {
fs.copyFileSync(path.join(srcDir, f), path.join(dest, f));
}
}
return modConfig;
},
]);
// 2. 注册 receiver + 权限到 AndroidManifest
config = withAndroidManifest(config, (modConfig) => {
const manifest = modConfig.modResults.manifest;
// 1. 添加 RECEIVE_SMS 权限
if (!manifest['uses-permission']) {
manifest['uses-permission'] = [];
}
const perms = ['android.permission.RECEIVE_SMS'];
for (const perm of perms) {
const exists = manifest['uses-permission'].some(p => p.$['android:name'] === perm);
if (!exists) {
manifest['uses-permission'].push({ $: { 'android:name': perm } });
}
}
// 2. 添加短信 Receiver
const receiverNode = {
$: {
'android:name': 'com.beancount.mobile.sms.BillingSmsReceiver',
'android:exported': 'true',
},
'intent-filter': [{
action: [{ $: { 'android:name': 'android.provider.Telephony.SMS_RECEIVED' } }],
}],
};
// 确保 application[0] 存在
if (!Array.isArray(manifest.application) || manifest.application.length === 0) {
manifest.application = [{ $: {} }];
}
const app = manifest.application[0];
if (!app.receiver) {
app.receiver = [];
}
const exists = app.receiver.some(
r => r.$['android:name'] === 'com.beancount.mobile.sms.BillingSmsReceiver'
);
if (!exists) {
app.receiver.push(receiverNode);
}
return modConfig;
});
return config;
}
module.exports = withSmsReceiver;
+6
View File
@@ -0,0 +1,6 @@
{
"name": "beancount-mobile-plugin-sms-receiver",
"version": "0.1.0",
"private": true,
"main": "app.plugin.js"
}