收口H5桌面壳命令入口
共享HostBridge契约导出唯一Tauri命令名 H5原生壳Transport改用共享Tauri命令常量 桌面壳配置检查对齐H5与Rust命令入口 宿主壳方案文档补充Tauri命令入口门禁 共享决策日志记录H5 Tauri命令边界
This commit is contained in:
@@ -25,6 +25,11 @@ const sharedContractPath = new URL(
|
||||
import.meta.url,
|
||||
);
|
||||
const sharedContractSource = fs.readFileSync(sharedContractPath, 'utf8');
|
||||
const nativeAppHostBridgePath = new URL(
|
||||
'../../../src/services/host-bridge/nativeAppHostBridge.ts',
|
||||
import.meta.url,
|
||||
);
|
||||
const nativeAppHostBridgeSource = fs.readFileSync(nativeAppHostBridgePath, 'utf8');
|
||||
const mainPath = new URL('../src-tauri/src/main.rs', import.meta.url);
|
||||
const main = fs.readFileSync(mainPath, 'utf8');
|
||||
const productionSourceRoots = [
|
||||
@@ -375,6 +380,17 @@ function extractRustStringArrayConst(source, constName) {
|
||||
return [...match[1].matchAll(/"([^"]+)"/g)].map((entry) => entry[1]);
|
||||
}
|
||||
|
||||
function extractTsStringConst(source, constName) {
|
||||
const match = source.match(
|
||||
new RegExp(`export const ${constName}\\s*=\\s*'([^']+)';`),
|
||||
);
|
||||
if (!match) {
|
||||
throw new Error(`unable to read TypeScript const ${constName}`);
|
||||
}
|
||||
|
||||
return match[1];
|
||||
}
|
||||
|
||||
function extractDesktopCapabilities(source) {
|
||||
const match = source.match(/fn capabilities\(\)[^{]*\{[\s\S]*?vec!\[([\s\S]*?)\]\s*\}/);
|
||||
if (!match) {
|
||||
@@ -446,6 +462,12 @@ function extractTauriInvokeCommands(source) {
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function extractNativeAppTauriInvokeCommands(source) {
|
||||
return [...source.matchAll(/\btauriInvoke[\s\S]*?\(\s*([^,\n]+?)\s*,/g)]
|
||||
.map((match) => match[1].trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function assertGeneratedPermissions(commandNames) {
|
||||
if (!fs.existsSync(generatedPermissionDir)) {
|
||||
return;
|
||||
@@ -726,7 +748,11 @@ const allowedPermissions = [
|
||||
'core:default',
|
||||
'allow-host-bridge-request',
|
||||
];
|
||||
const allowedTauriCommands = ['host_bridge_request'];
|
||||
const sharedTauriCommand = extractTsStringConst(
|
||||
sharedContractSource,
|
||||
'HOST_BRIDGE_TAURI_COMMAND',
|
||||
);
|
||||
const allowedTauriCommands = [sharedTauriCommand];
|
||||
const requiredMainSnippets = [
|
||||
'tauri_plugin_single_instance::init',
|
||||
'resolve_desktop_single_instance_action',
|
||||
@@ -821,6 +847,20 @@ const requiredMainSnippets = [
|
||||
'replay_state.complete(slot, response)',
|
||||
];
|
||||
|
||||
assertSameList(
|
||||
allowedTauriCommands,
|
||||
['host_bridge_request'],
|
||||
'shared Tauri HostBridge command',
|
||||
);
|
||||
assertSameList(
|
||||
extractNativeAppTauriInvokeCommands(nativeAppHostBridgeSource),
|
||||
['HOST_BRIDGE_TAURI_COMMAND'],
|
||||
'H5 native app Tauri invoke command source',
|
||||
);
|
||||
if (nativeAppHostBridgeSource.includes("'host_bridge_request'")) {
|
||||
throw new Error('H5 native app HostBridge must use HOST_BRIDGE_TAURI_COMMAND');
|
||||
}
|
||||
|
||||
assertSameList(
|
||||
capability.windows ?? [],
|
||||
['main'],
|
||||
|
||||
Reference in New Issue
Block a user