feat: 驱动按 process.platform 自动选择,非 win32 抛 platform_unsupported

迁移前置项(指南五件小事 #2):
- RpaEngine.driver 改惰性 getter:win32 惰性创建 WindowsDriver,其他平台访问时
  抛 RuntimeError(platform_unsupported),import 不再隐式绑定 Windows
- 错误码 platform_unsupported 登记 RUNTIME_ERROR_CODES
- engine-driver.test.ts 覆盖两条路径
This commit is contained in:
yu committed 2026-11-05 17:56:34 +08:00
1 parent 8414c4f355
commit 51a6178bfc
3 files changed
+41 -2

No files matched your search

+18 -2
View File
@@ -2,6 +2,7 @@ import type { Client } from "basic-ftp";
import type { Workbook as ExcelJSWorkbook } from "exceljs";
import { WindowsDriver } from "../driver/windows/windows-driver";
import type { AutomationDriver } from "../driver/types";
import { RuntimeError } from "./types";
/** 人为拟真操作的开关与随机参数(desktop 能力的进程级设置)。 */
export interface ManualOperationSettings {
@@ -41,8 +42,23 @@ export class RpaEngine {
minMs: 1000,
maxMs: 3000
};
/** 桌面自动化驱动(任务 3.4 注入点,默认 PowerShell 版 WindowsDriver) */
readonly driver: AutomationDriver = new WindowsDriver();
/** 桌面自动化驱动:按系统自动选(迁移指南五件小事 #2)。win32 用 PowerShell 版 WindowsDriver;
* 其他平台尚未实现,访问时抛 platform_unsupported 明确报错(惰性创建,避免 import 即炸) */
private _driver?: AutomationDriver;
get driver(): AutomationDriver {
if (!this._driver) {
if (process.platform === "win32") {
this._driver = new WindowsDriver();
} else {
throw new RuntimeError(
"platform_unsupported",
`该平台暂不支持桌面自动化驱动(当前:${process.platform})`,
{ recommendation: "桌面/键鼠/窗口能力目前仅支持 Windows;macOS/Linux 驱动在迁移指南三端计划中规划" }
);
}
}
return this._driver;
}
}
export function createEngine(): RpaEngine {