fix(android): break IPC settings barrel cycle (#827)

Co-authored-by: sim <sim@local>
This commit is contained in:
TRIPandsim authored and GitHub committed 2026-07-15 13:20:57 +08:00
1 parent c645b16851
commit d6ca07a6b2
3 files changed
+31 -1

No files matched your search

@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Icon } from '../../../src/components/Icon';
import { getSettings, setSettings } from '../../../src/lib/ipc';
import { getSettings, setSettings } from '../../../src/lib/ipc/settings';
import type { UserPreferences } from '../../../src/lib/types';
import { Btn, Pill } from '../../../src/pages/_atoms';
import { SettingRow } from '../../../src/pages/settings/shared';
+1
View File
@@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"prebuild": "node scripts/android-ipc-import-boundary.test.mjs",
"build": "tsc && vite build",
"preview": "vite preview",
"tauri": "tauri",
@@ -0,0 +1,29 @@
import { readFile } from 'node:fs/promises';
const panelUrl = new URL(
'../android/frontend/components/AndroidPermissionsPanel.tsx',
import.meta.url,
);
const source = await readFile(panelUrl, 'utf8');
const imports = [...source.matchAll(/import\s+([\s\S]*?)\s+from\s+['"]([^'"]+)['"];?/g)];
function moduleFor(name) {
return imports
.filter(([, bindings]) => new RegExp(`\\b${name}\\b`).test(bindings))
.map(([, , moduleName]) => moduleName);
}
for (const name of ['getSettings', 'setSettings']) {
const modules = moduleFor(name);
if (modules.length !== 1 || modules[0] !== '../../../src/lib/ipc/settings') {
throw new Error(
`${name} must be imported directly from ../../../src/lib/ipc/settings; found ${JSON.stringify(modules)}`,
);
}
}
if (/from\s+['"]\.\.\/\.\.\/\.\.\/src\/lib\/ipc['"]/.test(source)) {
throw new Error('AndroidPermissionsPanel must not import through the IPC barrel');
}
console.log('android-ipc-import-boundary.test.mjs passed');