android-midscene-automation 1.1.6 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
1
  # 更新记录
2
+ ## v1.1.7
3
+ - [Appium]修复元素判断临近超时时误报“设备自动化服务无响应”的问题。
4
+ - [Appium]流程编辑器新增直线与曲线切换,默认使用曲线,配置自动保存并同步至主画布和流程总览。
5
+ - [Appium]优化多分支汇合线:汇合点按左右汇入线居中,增大纵向间距,曲线在底部留白处平滑汇入,减少节点遮挡。
6
+
2
7
  ## v1.1.6
3
8
  - [Appium]优化流程画布交互:点击节点自动放大并居中,流程总览支持还原位置,AI 识别节点提示词最多展示三行。
4
9
  - [Appium]统一节点编辑界面:AI 识别、组件定位、节点信息和超时设置使用紧凑分组,优化循环、滑动、缩放等参数布局。
package/README.md CHANGED
@@ -1502,6 +1502,11 @@ Linux: ~/.local/share/android-midscene-automation
1502
1502
 
1503
1503
  # 项目更新记录
1504
1504
 
1505
+ ## v1.1.7
1506
+ - [Appium]修复元素判断临近超时时误报“设备自动化服务无响应”的问题。
1507
+ - [Appium]流程编辑器新增直线与曲线切换,默认使用曲线,配置自动保存并同步至主画布和流程总览。
1508
+ - [Appium]优化多分支汇合线:汇合点按左右汇入线居中,增大纵向间距,曲线在底部留白处平滑汇入,减少节点遮挡。
1509
+
1505
1510
  ## v1.1.6
1506
1511
  - [Appium]优化流程画布交互:点击节点自动放大并居中,流程总览支持还原位置,AI 识别节点提示词最多展示三行。
1507
1512
  - [Appium]统一节点编辑界面:AI 识别、组件定位、节点信息和超时设置使用紧凑分组,优化循环、滑动、缩放等参数布局。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "android-midscene-automation",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/oooooooko/android-midscene-automation.git"
@@ -42,10 +42,12 @@ test('Appium autosave is isolated from manual config, persists and rejects inval
42
42
  const base = `http://127.0.0.1:${address.port}`;
43
43
  const post = (path: string, body: unknown) => fetch(base + path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
44
44
  const initial = await (await fetch(base + '/api/config')).json() as AppConfig;
45
- const appium = { ...initial.appium, flowLineColor: '#AbC', model: { baseUrl: 'https://example.invalid', apiKey: 'test', name: 'new-model' } };
45
+ assert.equal(initial.appium.flowLineStyle, 'curved');
46
+ const appium = { ...initial.appium, flowLineStyle: 'curved', flowLineColor: '#AbC', model: { baseUrl: 'https://example.invalid', apiKey: 'test', name: 'new-model' } };
46
47
  assert.equal((await post('/api/config/appium', { appium, runtime: { androidSdkPath: 'invalid-draft' }, midscene: { model: { name: 'unsaved' } } })).status, 200);
47
48
  let stored = await (await fetch(base + '/api/config')).json() as AppConfig;
48
49
  assert.equal(stored.appium.flowLineColor, '#aabbcc');
50
+ assert.equal(stored.appium.flowLineStyle, 'curved');
49
51
  assert.deepEqual(stored.runtime, initial.runtime);
50
52
  assert.deepEqual(stored.midscene, initial.midscene);
51
53
  const { appium: _appium, ...manual } = structuredClone(initial);
@@ -55,9 +57,11 @@ test('Appium autosave is isolated from manual config, persists and rejects inval
55
57
  assert.deepEqual(stored.appium.model, initial.appium.model, 'automatic saves must not persist untested model drafts');
56
58
  assert.equal(stored.midscene.model.name, initial.midscene.model.name, 'runtime save must not persist an untested model');
57
59
  assert.equal((await post('/api/config/appium', { appium: { ...appium, flowLineColor: 'invalid' } })).status, 400);
60
+ assert.equal((await post('/api/config/appium', { appium: { ...appium, flowLineStyle: 'invalid' } })).status, 400);
58
61
  assert.equal((await post('/api/config/appium', { appium: null })).status, 400);
59
62
  const { loadModelConfigFromDb } = await import('./config-store');
60
63
  assert.equal(loadModelConfigFromDb()?.appium?.flowLineColor, '#aabbcc');
64
+ assert.equal(loadModelConfigFromDb()?.appium?.flowLineStyle, 'curved');
61
65
 
62
66
  for (const key of ['midscene', 'scriptOptimizer', 'appium'] as const) {
63
67
  const before = await (await fetch(base + '/api/config')).json() as AppConfig;
@@ -333,7 +333,7 @@ async function appiumRequest<T>(
333
333
  throw new ReplayStoppedError();
334
334
  }
335
335
  context?.appiumLog(`[Appium] 异常:${method} ${effectivePath}(${errorDetail(error)})`);
336
- if (error instanceof AppiumRequestTimeoutError) throw error;
336
+ if (error instanceof AppiumRequestTimeoutError || error instanceof ConditionTimeoutError) throw error;
337
337
  if (isTimeoutError(error)) {
338
338
  throw new AppiumServiceError(`Appium 请求超时 ${requestUrl},${errorDetail(error)}`);
339
339
  }
@@ -550,6 +550,7 @@ async function findElementWithinDeadline(sessionId: string, step: AppiumRecorded
550
550
  return await findElementBySelector(sessionId, step.selector, parentId);
551
551
  } catch (error) {
552
552
  throwIfReplayStopped(error);
553
+ if (error instanceof ConditionTimeoutError) throw error;
553
554
  lastError = error;
554
555
  // Continue with the fallback chain below.
555
556
  }
@@ -567,6 +568,7 @@ async function findElementWithinDeadline(sessionId: string, step: AppiumRecorded
567
568
  return await findElementBySelector(sessionId, selector);
568
569
  } catch (error) {
569
570
  throwIfReplayStopped(error);
571
+ if (error instanceof ConditionTimeoutError) throw error;
570
572
  lastError = error;
571
573
  }
572
574
  }
@@ -726,6 +728,7 @@ async function waitForElementGone(sessionId: string, step: AppiumRecordedStepRec
726
728
  await findElement(sessionId, step, remaining);
727
729
  } catch (error) {
728
730
  throwIfReplayStopped(error);
731
+ if (error instanceof ConditionTimeoutError) throw error;
729
732
  return;
730
733
  }
731
734
  const pauseMs = Math.min(500, timeoutMs - (Date.now() - startedAt));
@@ -1,5 +1,6 @@
1
1
  import assert from 'node:assert/strict';
2
2
  import { test } from 'node:test';
3
+ import { setTimeout as delay } from 'node:timers/promises';
3
4
  import childProcess from 'node:child_process';
4
5
  import { syncBuiltinESMExports } from 'node:module';
5
6
  import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises';
@@ -186,6 +187,66 @@ test('text matching does not start another Appium query at the node deadline', a
186
187
  }
187
188
  });
188
189
 
190
+ test('missing element completes its last query and follows the timeout branch without reporting a service failure', async () => {
191
+ const root = await mkdtemp(join(tmpdir(), 'text-deadline-'));
192
+ const env = { ...process.env };
193
+ const original = { execFile: childProcess.execFile, fetch: globalThis.fetch };
194
+ let elementQueries = 0;
195
+ try {
196
+ const sdk = join(root, 'sdk');
197
+ await mkdir(join(sdk, 'platform-tools'), { recursive: true });
198
+ await writeFile(join(sdk, 'platform-tools', 'adb'), '');
199
+ Object.assign(process.env, {
200
+ ANDROID_MIDSCENE_DATA_ROOT: root,
201
+ ANDROID_HOME: sdk,
202
+ ANDROID_SDK_ROOT: sdk,
203
+ APPIUM_SERVER_URL: 'http://external.invalid',
204
+ });
205
+ childProcess.execFile = ((_command, _args: string[], _options, callback) => {
206
+ queueMicrotask(() => callback(null, '', ''));
207
+ return {};
208
+ }) as typeof childProcess.execFile;
209
+ syncBuiltinESMExports();
210
+ globalThis.fetch = async (input, init) => {
211
+ const path = new URL(String(input)).pathname;
212
+ if (path === '/session' && init?.method === 'POST') {
213
+ return Response.json({ value: { sessionId: 'deadline-session' } });
214
+ }
215
+ if (path === '/session/deadline-session/element') {
216
+ elementQueries += 1;
217
+ await delay(150, undefined, { signal: init?.signal ?? undefined });
218
+ return Response.json({ value: { error: 'no such element', message: 'not found' } }, { status: 404 });
219
+ }
220
+ return Response.json({ value: null });
221
+ };
222
+ const { replayAppiumScript } = await import('./appium-runner');
223
+ const script: AppiumRecordedScriptRecord = {
224
+ id: 'deadline', name: 'deadline', deviceId: 'fake-device', appPackage: '', appActivity: '', createdAt: '', updatedAt: '',
225
+ steps: [{
226
+ id: 'text', type: 'assertExists', label: '判断低功耗主页', timeoutMs: 100,
227
+ selector: { strategy: 'id', value: 'example:id/batterItem', unique: true },
228
+ timeoutBranch: 'no', flow: { nodeKind: 'condition', noTargetId: 'done' },
229
+ }, { id: 'done', type: 'noop', label: '继续执行' }],
230
+ };
231
+ const result = await replayAppiumScript(script, 'fake-device', undefined, undefined, {
232
+ screenshotReport: false,
233
+ reportSummaryEnabled: false,
234
+ });
235
+ assert.equal(result.success, true, result.output);
236
+ assert.doesNotMatch(result.output, /服务无响应/);
237
+ assert.equal(elementQueries, 1, 'no retry after the node deadline');
238
+ assert.match(result.output, /判断超时,按配置进入右侧分支/);
239
+ } finally {
240
+ childProcess.execFile = original.execFile;
241
+ globalThis.fetch = original.fetch;
242
+ syncBuiltinESMExports();
243
+ for (const key of ['ANDROID_MIDSCENE_DATA_ROOT', 'ANDROID_HOME', 'ANDROID_SDK_ROOT', 'APPIUM_SERVER_URL']) {
244
+ if (env[key] === undefined) delete process.env[key]; else process.env[key] = env[key];
245
+ }
246
+ await rm(root, { recursive: true, force: true });
247
+ }
248
+ });
249
+
189
250
  test('optional tap recovers a blocked UiAutomator2 session and uses the ADB hierarchy', async () => {
190
251
  const root = await mkdtemp(join(tmpdir(), 'optional-recovery-'));
191
252
  const env = { ...process.env };
@@ -0,0 +1,34 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { createServer } from 'node:http';
4
+ import { setTimeout as delay } from 'node:timers/promises';
5
+ import { ConditionTimeoutError } from './condition-timeout';
6
+ import { AppiumRequestTimeoutError, timedAppiumFetch, withElementDeadline } from './request-timeout';
7
+
8
+ test('element deadline does not shorten an in-flight request or its response body', async () => {
9
+ const server = createServer(async (_req, res) => {
10
+ res.writeHead(404, { 'Content-Type': 'application/json' });
11
+ res.flushHeaders();
12
+ await delay(150);
13
+ res.end('{"value":{"error":"no such element"}}');
14
+ });
15
+ await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));
16
+ const url = `http://127.0.0.1:${(server.address() as { port: number }).port}/element`;
17
+ try {
18
+ const result = await withElementDeadline(50, () => timedAppiumFetch(url, {}, 2000));
19
+ assert.equal(result.response.status, 404);
20
+ assert.equal(JSON.parse(result.text).value.error, 'no such element');
21
+ await assert.rejects(withElementDeadline(1, async () => {
22
+ await delay(10);
23
+ return timedAppiumFetch(url, {}, 2000);
24
+ }), ConditionTimeoutError);
25
+ await assert.rejects(withElementDeadline(10, () => timedAppiumFetch(url, {}, 50)), AppiumRequestTimeoutError);
26
+ const controller = new AbortController();
27
+ const request = timedAppiumFetch(url, { signal: controller.signal }, 2000);
28
+ controller.abort(new Error('user stopped'));
29
+ await assert.rejects(request, /user stopped/);
30
+ } finally {
31
+ server.closeAllConnections();
32
+ await new Promise<void>(resolve => server.close(() => resolve()));
33
+ }
34
+ });
@@ -1,4 +1,5 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { ConditionTimeoutError } from './condition-timeout';
2
3
 
3
4
  const deadline = new AsyncLocalStorage<number>();
4
5
  export class AppiumRequestTimeoutError extends Error {}
@@ -14,8 +15,11 @@ export function remainingElementDeadlineMs() {
14
15
 
15
16
  // 响应体也受同一个期限约束,避免收到 HTTP 头后继续无限等待。
16
17
  export async function timedAppiumFetch(url: string, init: RequestInit, timeoutMs: number) {
17
- const remaining = Math.max(1, Math.min(timeoutMs, (deadline.getStore() ?? Infinity) - Date.now()));
18
- const timeout = AbortSignal.timeout(Math.ceil(remaining));
18
+ const elementRemaining = remainingElementDeadlineMs();
19
+ if (elementRemaining <= 0) throw new ConditionTimeoutError('元素定位等待期限已到');
20
+ // 节点期限限制是否继续查找;已发出的请求使用独立通信超时,
21
+ // 避免把最后一次正常查询因剩余预算过短误报为服务无响应。
22
+ const timeout = AbortSignal.timeout(Math.ceil(timeoutMs));
19
23
  const signal = init.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
20
24
  try {
21
25
  const response = await fetch(url, { ...init, signal });
@@ -23,7 +27,7 @@ export async function timedAppiumFetch(url: string, init: RequestInit, timeoutMs
23
27
  return { response, text };
24
28
  } catch (error) {
25
29
  if (timeout.aborted && !init.signal?.aborted) {
26
- throw new AppiumRequestTimeoutError(`设备自动化服务无响应:Appium 请求超过 ${Math.ceil(remaining)}ms,已停止等待(${url})`);
30
+ throw new AppiumRequestTimeoutError(`设备自动化服务无响应:Appium 请求超过 ${Math.ceil(timeoutMs)}ms,已停止等待(${url})`);
27
31
  }
28
32
  throw error;
29
33
  }
package/server/config.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { resolveReportSummary, type ReportSummaryConfig } from '../src/appium-recorder/report-summary';
2
2
  import type { AiPromptPreset } from '../src/appium-recorder/ai-prompt-presets';
3
3
  import fs from 'node:fs';
4
- import { isHexColor, normalizeFlowBackground, normalizeFlowLineColor } from '../src/appium-recorder/flow-appearance';
4
+ import { isHexColor, normalizeFlowBackground, normalizeFlowLineColor, normalizeFlowLineStyle } from '../src/appium-recorder/flow-appearance';
5
5
  import os from 'node:os';
6
6
  import path from 'node:path';
7
7
  import YAML from 'yaml';
@@ -13,7 +13,7 @@ import { resolveAiDeduplication, type AiDeduplicationConfig } from '../src/appiu
13
13
  import type { MidsceneModelProvider } from '../src/config/midscene-model-presets';
14
14
 
15
15
  export type AppConfig = {
16
- appium: { reportSummary?: ReportSummaryConfig; model: AiRecognitionModel; promptOptimizer?: { model: AiRecognitionModel }; aiPromptPresets?: AiPromptPreset[]; aiDeduplication?: AiDeduplicationConfig; flowBackgroundColor?: string; flowLineColor?: string; screenshotReport?: boolean };
16
+ appium: { reportSummary?: ReportSummaryConfig; model: AiRecognitionModel; promptOptimizer?: { model: AiRecognitionModel }; aiPromptPresets?: AiPromptPreset[]; aiDeduplication?: AiDeduplicationConfig; flowBackgroundColor?: string; flowLineColor?: string; flowLineStyle?: 'straight' | 'curved'; screenshotReport?: boolean };
17
17
  runtime: {
18
18
  androidSdkPath: string;
19
19
  reportOutputPath: string;
@@ -100,6 +100,7 @@ function normalizeConfig(config: Partial<AppConfig> | null | undefined): AppConf
100
100
  screenshotReport: config?.appium?.screenshotReport === true,
101
101
  flowBackgroundColor: normalizeFlowBackground(config?.appium?.flowBackgroundColor),
102
102
  flowLineColor: normalizeFlowLineColor(config?.appium?.flowLineColor),
103
+ flowLineStyle: normalizeFlowLineStyle(config?.appium?.flowLineStyle),
103
104
  model: Object.fromEntries(['baseUrl', 'apiKey', 'name'].map((key) => {
104
105
  const value = config?.appium?.model?.[key as keyof AiRecognitionModel];
105
106
  return [key, typeof value === 'string' ? value.trim() : ''];
@@ -234,11 +235,14 @@ export function saveConfig(config: AppConfig) {
234
235
  try { resolveAiDeduplication(config.appium?.aiDeduplication); }
235
236
  catch (error) { throw new ConfigValidationError(error instanceof Error ? error.message : '截图去重配置无效'); }
236
237
  if (config.appium?.flowBackgroundColor !== undefined && !isHexColor(config.appium.flowBackgroundColor)) {
237
- throw new ConfigValidationError('流程背景色必须是有效的十六进制颜色(#RGB 或 #RRGGBB)');
238
+ throw new ConfigValidationError('画布背景色必须是有效的十六进制颜色(#RGB 或 #RRGGBB)');
238
239
  }
239
240
  if (config.appium?.flowLineColor !== undefined && !isHexColor(config.appium.flowLineColor)) {
240
241
  throw new ConfigValidationError('连接线条颜色必须是有效的十六进制颜色(#RGB 或 #RRGGBB)');
241
242
  }
243
+ if (config.appium?.flowLineStyle !== undefined && !['straight', 'curved'].includes(config.appium.flowLineStyle)) {
244
+ throw new ConfigValidationError('连接线条样式必须是直线或曲线');
245
+ }
242
246
  const normalized = normalizeConfig(config);
243
247
  validateRuntimeConfig(normalized);
244
248
  cachedConfig = normalized;
package/src/App.vue CHANGED
@@ -994,6 +994,7 @@ onUnmounted(() => {
994
994
  :report-summary="configForm.appium.reportSummary"
995
995
  :flow-background-color="configForm.appium.flowBackgroundColor"
996
996
  :flow-line-color="configForm.appium.flowLineColor"
997
+ :flow-line-style="configForm.appium.flowLineStyle"
997
998
  :device-actions="deviceActions"
998
999
  :playground-available="playgroundAvailable"
999
1000
  :playground-device-id="playgroundDeviceId"
@@ -1,12 +1,12 @@
1
1
  <script setup lang="ts">
2
- import { computed, h, onMounted, onUnmounted, provide, reactive, shallowRef, watch } from 'vue';
3
- import { flowBackgroundKey, normalizeFlowBackground, flowLineColorKey, normalizeFlowLineColor } from './flow-appearance';
2
+ import { computed, h, nextTick, onMounted, onUnmounted, provide, reactive, shallowRef, useTemplateRef, watch } from 'vue';
3
+ import { flowBackgroundKey, normalizeFlowBackground, flowLineColorKey, normalizeFlowLineColor, flowLineStyleKey, normalizeFlowLineStyle, type FlowLineStyle } from './flow-appearance';
4
4
  import { useCoordinatePicker } from './coordinate-preview';
5
5
  import { DEFAULT_NODE_TIMEOUT_MS } from './node-timeout';
6
6
  import { aiPromptPresetsKey, DEFAULT_AI_PROMPT_PRESETS, type AiPromptPreset } from './ai-prompt-presets';
7
7
  import AiRecognitionPromptInput from './components/AiRecognitionPromptInput.vue';
8
8
  import { ElForm, ElFormItem, ElInputNumber, ElMessage, ElMessageBox, ElOption, ElSelect } from 'element-plus';
9
- import { ArrowDown, Check, CircleClose, CopyDocument, Delete, Document, Download, Edit, Plus, Refresh, Upload, VideoPlay, View, Clock } from '@element-plus/icons-vue';
9
+ import { ArrowDown, Check, CircleClose, CopyDocument, Delete, Document, Download, Edit, FolderOpened, Plus, Refresh, Upload, VideoPlay, View, Clock } from '@element-plus/icons-vue';
10
10
  import RunHistoryDialog from './RunHistoryDialog.vue';
11
11
  import type { AndroidDevice, AppPreset, DeviceAction } from '../types';
12
12
  import DevicePreviewPanel from '../components/device/DevicePreviewPanel.vue';
@@ -112,6 +112,7 @@ const props = defineProps<{
112
112
  reportSummary?: ReportSummaryConfig;
113
113
  flowBackgroundColor?: string;
114
114
  flowLineColor?: string;
115
+ flowLineStyle?: FlowLineStyle;
115
116
  active: boolean;
116
117
  appPresets: AppPreset[];
117
118
  deviceActions: readonly DeviceAction[];
@@ -138,6 +139,7 @@ const props = defineProps<{
138
139
  // provide/inject 随组件关系传递,放大弹窗 teleport 后也能使用同一颜色。
139
140
  provide(flowBackgroundKey, computed(() => normalizeFlowBackground(props.flowBackgroundColor)));
140
141
  provide(flowLineColorKey, computed(() => normalizeFlowLineColor(props.flowLineColor)));
142
+ provide(flowLineStyleKey, computed(() => normalizeFlowLineStyle(props.flowLineStyle)));
141
143
  const availableAiPromptPresets = computed(() => props.aiPromptPresets ?? DEFAULT_AI_PROMPT_PRESETS);
142
144
  const availableReportTemplates = computed(() => [
143
145
  ...REPORT_SUMMARY_PROMPT_PRESETS,
@@ -150,6 +152,7 @@ const tree = shallowRef<AppiumNode | null>(null);
150
152
  const selectedNode = shallowRef<AppiumNode | null>(null);
151
153
  const scripts = shallowRef<AppiumRecordedScript[]>([]);
152
154
  const selectedScriptId = shallowRef('');
155
+ const recordedStepsRef = useTemplateRef('recordedStepsRef');
153
156
  const newScriptDialogVisible = shallowRef(false);
154
157
  const newScriptRevision = shallowRef(0);
155
158
  const storedWorkbenchTab = window.localStorage.getItem(WORKBENCH_TAB_STORAGE_KEY);
@@ -1866,6 +1869,7 @@ function loadScript(script: AppiumRecordedScript) {
1866
1869
  }
1867
1870
  steps.value = normalizeLegacyNestedConditionBranches((script.steps || []).map(normalizeLegacyFlowScope));
1868
1871
  markDraftSaved();
1872
+ void nextTick(() => recordedStepsRef.value?.resetMainFlowPosition());
1869
1873
  }
1870
1874
 
1871
1875
  function loadSelectedScript() {
@@ -2390,6 +2394,7 @@ watch(
2390
2394
 
2391
2395
  <section class="appium-workbench__section appium-workbench__flow">
2392
2396
  <RecordedSteps
2397
+ ref="recordedStepsRef"
2393
2398
  :key="newScriptRevision"
2394
2399
  :ai-recognition-model-configured="aiRecognitionModelConfigured"
2395
2400
  :steps="steps"
@@ -2448,7 +2453,7 @@ watch(
2448
2453
  <el-button size="small" :icon="Clock" aria-label="历史结果对比" @click.stop="historyScript = { id: script.id, name: script.name }" />
2449
2454
  </span></el-tooltip>
2450
2455
  <el-tooltip content="加载" placement="top" :show-after="200"><span class="appium-script-icon">
2451
- <el-button size="small" :icon="Document" aria-label="加载" @click.stop="loadScript(script)" />
2456
+ <el-button size="small" :icon="FolderOpened" aria-label="加载" @click.stop="loadScript(script)" />
2452
2457
  </span></el-tooltip>
2453
2458
  <el-tooltip content="修改脚本名称" placement="top" :show-after="200"><span class="appium-script-icon">
2454
2459
  <el-button
@@ -1,9 +1,11 @@
1
1
  <script setup lang="ts">
2
- import { computed } from 'vue';
3
- import { BaseEdge, type EdgeProps } from '@vue-flow/core';
2
+ import { computed, inject } from 'vue';
3
+ import { BaseEdge, getBezierPath, type EdgeProps } from '@vue-flow/core';
4
+ import { flowLineStyleKey, normalizeFlowLineStyle } from '../flow-appearance';
4
5
  import type { FlowGraphNodeData } from '../flow-graph';
5
6
 
6
7
  const props = defineProps<EdgeProps>();
8
+ const lineStyle = inject(flowLineStyleKey, computed(() => normalizeFlowLineStyle(undefined)));
7
9
 
8
10
  const targetData = computed(() => props.targetNode.data as FlowGraphNodeData | undefined);
9
11
 
@@ -22,6 +24,22 @@ function linePath(points: Point[]) {
22
24
  }
23
25
 
24
26
  const path = computed(() => {
27
+ if (lineStyle.value === 'curved') {
28
+ if (props.data?.merge && props.targetY > props.sourceY) {
29
+ // 先沿分支向下,仅在汇合点上方的留白内弯曲,避免斜穿相邻节点。
30
+ const bendY = Math.max(props.sourceY, props.targetY - 112);
31
+ const controlY = (bendY + props.targetY) / 2;
32
+ return [
33
+ `M ${props.sourceX} ${props.sourceY}`,
34
+ `L ${props.sourceX} ${bendY}`,
35
+ `C ${props.sourceX} ${controlY} ${props.targetX} ${controlY} ${props.targetX} ${props.targetY}`,
36
+ ].join(' ');
37
+ }
38
+ return getBezierPath({
39
+ sourceX: props.sourceX, sourceY: props.sourceY, sourcePosition: props.sourcePosition,
40
+ targetX: props.targetX, targetY: props.targetY, targetPosition: props.targetPosition,
41
+ })[0];
42
+ }
25
43
  const source = { x: props.sourceX, y: props.sourceY };
26
44
  const target = { x: props.targetX, y: props.targetY };
27
45
  const deltaX = target.x - source.x;
@@ -247,6 +247,8 @@ function resetMainFlowPosition() {
247
247
  mainResetViewToken.value += 1;
248
248
  }
249
249
 
250
+ defineExpose({ resetMainFlowPosition });
251
+
250
252
  function resetDialogFlowPosition() {
251
253
  dialogResetViewToken.value += 1;
252
254
  }
@@ -1,7 +1,7 @@
1
1
  import type { InjectionKey, Ref } from 'vue';
2
2
 
3
- export const DEFAULT_FLOW_BACKGROUND = '#f8fafc';
4
- export const FLOW_BACKGROUND_PRESETS = ['#f8fafc', '#d4e8dd', '#d5e6f5', '#e4dcf2', '#f2dedc', '#d5eae9', '#e8e4cc'];
3
+ export const DEFAULT_FLOW_BACKGROUND = '#f1f5f9';
4
+ export const FLOW_BACKGROUND_PRESETS = [DEFAULT_FLOW_BACKGROUND, '#d4e8dd', '#d5e6f5', '#e4dcf2', '#f2dedc', '#d5eae9', '#e8e4cc'];
5
5
  export const flowBackgroundKey: InjectionKey<Readonly<Ref<string>>> = Symbol('flowBackground');
6
6
  export const DEFAULT_FLOW_LINE_COLOR = '#94a3b8';
7
7
  export const FLOW_LINE_COLOR_PRESETS = ['#94a3b8', '#719985', '#4b83c4', '#8b6bb1', '#c78a46', '#7b8794', '#374151'];
@@ -24,3 +24,10 @@ function normalizeFlowColor(value: unknown, fallback: string) {
24
24
  const color = value.trim().toLowerCase();
25
25
  return color.length === 4 ? '#' + [...color.slice(1)].map((char) => char + char).join('') : color;
26
26
  }
27
+
28
+ export type FlowLineStyle = 'straight' | 'curved';
29
+ export const flowLineStyleKey: InjectionKey<Readonly<Ref<FlowLineStyle>>> = Symbol('flowLineStyle');
30
+
31
+ export function normalizeFlowLineStyle(value: unknown): FlowLineStyle {
32
+ return value === 'straight' ? 'straight' : 'curved';
33
+ }
@@ -789,10 +789,10 @@ export function buildFlowGraph(
789
789
  const joinOwner = joins.get(target.id);
790
790
  if (joinOwner && target.id !== joinOwner) {
791
791
  const incoming = links.filter((edge) => edge.target === target.id).map((edge) => nodeById.get(edge.source)!).filter(Boolean);
792
- const owner = nodeById.get(joinOwner);
793
- if (owner && incoming.length) {
794
- target.position.y = Math.round(Math.max(...incoming.map((node) => node.position.y + nodeHeight(node))) + FLOW_STANDARD_LINE_GAP * 2);
795
- setCenterX(target, centerX(owner));
792
+ if (incoming.length) {
793
+ target.position.y = Math.round(Math.max(...incoming.map((node) => node.position.y + nodeHeight(node))) + FLOW_STANDARD_LINE_GAP * 4);
794
+ const incomingCenters = incoming.map(centerX);
795
+ setCenterX(target, (Math.min(...incomingCenters) + Math.max(...incomingCenters)) / 2);
796
796
  }
797
797
  return;
798
798
  }
@@ -68,8 +68,8 @@ defineEmits<{
68
68
  </section>
69
69
 
70
70
  <section class="appium-config-section" aria-labelledby="appium-editor-title">
71
- <header class="appium-section-heading"><div><h2 id="appium-editor-title">流程编辑器</h2><p>调整流程画布和连接线的显示颜色。</p></div></header>
72
- <FlowAppearanceSettings v-model="configForm.appium.flowBackgroundColor" v-model:line-color="configForm.appium.flowLineColor" />
71
+ <header class="appium-section-heading"><div><h2 id="appium-editor-title">流程编辑器</h2><p>调整流程画布颜色、连接线颜色和曲直样式。</p></div></header>
72
+ <FlowAppearanceSettings v-model="configForm.appium.flowBackgroundColor" v-model:line-color="configForm.appium.flowLineColor" v-model:line-style="configForm.appium.flowLineStyle" />
73
73
  </section>
74
74
  </div>
75
75
  </template>
@@ -2,16 +2,16 @@
2
2
  import { computed } from 'vue';
3
3
  import { RefreshLeft } from '@element-plus/icons-vue';
4
4
  import {
5
- DEFAULT_FLOW_BACKGROUND, FLOW_BACKGROUND_PRESETS, normalizeFlowBackground,
5
+ DEFAULT_FLOW_BACKGROUND, FLOW_BACKGROUND_PRESETS, normalizeFlowBackground, normalizeFlowLineStyle, type FlowLineStyle,
6
6
  DEFAULT_FLOW_LINE_COLOR, FLOW_LINE_COLOR_PRESETS, normalizeFlowLineColor, isHexColor,
7
7
  } from '../../appium-recorder/flow-appearance';
8
8
 
9
- const props = defineProps<{ modelValue?: string; lineColor?: string }>();
10
- const emit = defineEmits<{ 'update:modelValue': [color: string]; 'update:lineColor': [color: string] }>();
9
+ const props = defineProps<{ modelValue?: string; lineColor?: string; lineStyle?: FlowLineStyle }>();
10
+ const emit = defineEmits<{ 'update:modelValue': [color: string]; 'update:lineColor': [color: string]; 'update:lineStyle': [style: FlowLineStyle] }>();
11
11
  const panels = computed(() => [
12
- { key: 'background' as const, title: '流程背景色', color: props.modelValue ?? DEFAULT_FLOW_BACKGROUND,
12
+ { key: 'background' as const, title: '画布背景色', color: props.modelValue ?? DEFAULT_FLOW_BACKGROUND,
13
13
  fallback: DEFAULT_FLOW_BACKGROUND, presets: FLOW_BACKGROUND_PRESETS, normalize: normalizeFlowBackground,
14
- inputLabel: '十六进制背景色', pickerLabel: '选择流程背景色', resetLabel: '恢复默认颜色', presetLabel: '选择颜色' },
14
+ inputLabel: '十六进制背景色', pickerLabel: '选择画布背景色', resetLabel: '恢复默认颜色', presetLabel: '选择颜色' },
15
15
  { key: 'line' as const, title: '连接线条颜色', color: props.lineColor ?? DEFAULT_FLOW_LINE_COLOR,
16
16
  fallback: DEFAULT_FLOW_LINE_COLOR, presets: FLOW_LINE_COLOR_PRESETS, normalize: normalizeFlowLineColor,
17
17
  inputLabel: '十六进制线条颜色', pickerLabel: '选择连接线条颜色', resetLabel: '恢复默认线条颜色', presetLabel: '选择线条颜色' },
@@ -29,6 +29,13 @@ function update(key: 'background' | 'line', color: string) {
29
29
  <section v-for="panel in panels" :key="panel.key" class="flow-appearance-section" :aria-label="panel.title">
30
30
  <h3>{{ panel.title }}</h3>
31
31
  <el-form label-position="top">
32
+ <el-form-item v-if="panel.key === 'line'" label="连接线条样式">
33
+ <el-radio-group :model-value="normalizeFlowLineStyle(lineStyle)" aria-label="连接线条样式"
34
+ @update:model-value="emit('update:lineStyle', normalizeFlowLineStyle($event))">
35
+ <el-radio-button value="straight">直线</el-radio-button>
36
+ <el-radio-button value="curved">曲线</el-radio-button>
37
+ </el-radio-group>
38
+ </el-form-item>
32
39
  <el-form-item label="预选颜色">
33
40
  <div class="flow-color-presets">
34
41
  <button v-for="preset in panel.presets" :key="preset" type="button"
@@ -4,7 +4,7 @@ import { resolveReportSummary } from '../appium-recorder/report-summary';
4
4
  import { isAiRecognitionModelConfigured } from '../appium-recorder/ai-recognition';
5
5
  import { resolveAiDeduplication } from '../appium-recorder/ai-deduplication';
6
6
  import { resolveAiPromptPresets } from '../appium-recorder/ai-prompt-presets';
7
- import { normalizeFlowBackground, normalizeFlowLineColor } from '../appium-recorder/flow-appearance';
7
+ import { normalizeFlowBackground, normalizeFlowLineColor, normalizeFlowLineStyle } from '../appium-recorder/flow-appearance';
8
8
  import { selectMidsceneModelProvider, type MidsceneModelProvider } from './midscene-model-presets';
9
9
  import { useAppiumAutoSave } from './use-appium-auto-save';
10
10
  import type { ConfigForm } from '../types';
@@ -76,6 +76,7 @@ export function useModelConfig() {
76
76
  configForm.appium.aiPromptPresets = resolveAiPromptPresets(payload.appium?.aiPromptPresets);
77
77
  configForm.appium.flowBackgroundColor = normalizeFlowBackground(payload.appium?.flowBackgroundColor);
78
78
  configForm.appium.flowLineColor = normalizeFlowLineColor(payload.appium?.flowLineColor);
79
+ configForm.appium.flowLineStyle = normalizeFlowLineStyle(payload.appium?.flowLineStyle);
79
80
  appiumAutoSave.initialize();
80
81
  ready.value = true;
81
82
  aiRecognitionModelConfigured.value = isAiRecognitionModelConfigured(configForm.appium.model);
@@ -131,17 +131,17 @@ function handleTabKeydown(event: KeyboardEvent, index: number) {
131
131
  width: fit-content;
132
132
  max-width: calc(100% - 48px);
133
133
  flex-wrap: wrap;
134
- gap: 4px;
134
+ gap: 2px;
135
135
  margin: 20px 24px 0;
136
136
  padding: 4px;
137
137
  border: 1px solid var(--ui-border);
138
- border-radius: 24px;
138
+ border-radius: var(--ui-radius-pill);
139
139
  background: var(--ui-bg-soft);
140
- box-shadow: var(--ui-shadow-card);
140
+ box-shadow: var(--ui-shadow-inset);
141
141
  }
142
142
  .config-tabs .subnav__item {
143
- min-height: 34px;
144
- padding: 6px 16px;
143
+ min-height: 32px;
144
+ padding: 6px 14px;
145
145
  border: 0;
146
146
  border-radius: var(--ui-radius-pill);
147
147
  font-size: 13px;
@@ -149,7 +149,7 @@ function handleTabKeydown(event: KeyboardEvent, index: number) {
149
149
  .config-tabs .subnav__item--active {
150
150
  background: var(--ui-surface);
151
151
  color: var(--ui-primary);
152
- box-shadow: var(--ui-shadow-card);
152
+ box-shadow: var(--ui-shadow-control);
153
153
  }
154
154
  .config-page > [role="tabpanel"] { padding: 24px; }
155
155
  :deep(.config-module-card > .el-card__header) { padding: 18px 24px; font-size: 16px; font-weight: 600; }
package/src/style.css CHANGED
@@ -2656,7 +2656,7 @@ select {
2656
2656
  overflow: hidden;
2657
2657
  border: 1px solid #e6edf5;
2658
2658
  border-radius: 12px;
2659
- background: var(--flow-background, #f8fafc);
2659
+ background: var(--flow-background, var(--ui-bg-soft));
2660
2660
  }
2661
2661
 
2662
2662
  .appium-flow-canvas--dialog.appium-flow-canvas--vue {
@@ -2669,7 +2669,7 @@ select {
2669
2669
  height: 100%;
2670
2670
  background:
2671
2671
  radial-gradient(circle at 1px 1px, #cbd5e1 1px, transparent 0) 0 0 / 22px 22px,
2672
- var(--flow-background, #f8fafc);
2672
+ var(--flow-background, var(--ui-bg-soft));
2673
2673
  }
2674
2674
 
2675
2675
  .appium-vue-flow .vue-flow__pane {
@@ -4044,11 +4044,11 @@ button:focus-visible { outline: 2px solid var(--ui-primary); outline-offset: -2p
4044
4044
  box-sizing: border-box;
4045
4045
  width: fit-content;
4046
4046
  max-width: 100%;
4047
- padding: 2px;
4048
- border: 1px solid #dbe3ee;
4049
- border-radius: 14px;
4050
- background: linear-gradient(180deg, #fff, #f8fafc);
4051
- box-shadow: inset 0 1px 0 rgb(255 255 255 / 95%), 0 4px 12px -4px rgb(15 23 42 / 20%);
4047
+ padding: 4px;
4048
+ border: 1px solid var(--ui-border);
4049
+ border-radius: var(--ui-radius-pill);
4050
+ background: var(--ui-bg-soft);
4051
+ box-shadow: var(--ui-shadow-inset);
4052
4052
  }
4053
4053
 
4054
4054
  .el-radio-group:has(.el-radio-button) .el-radio-button {
@@ -4062,12 +4062,13 @@ button:focus-visible { outline: 2px solid var(--ui-primary); outline-offset: -2p
4062
4062
  justify-content: center;
4063
4063
  box-sizing: border-box;
4064
4064
  min-height: 32px;
4065
- padding: 6px 12px;
4065
+ padding: 6px 14px;
4066
4066
  border: 0 !important;
4067
- border-radius: 11px !important;
4067
+ border-radius: var(--ui-radius-pill) !important;
4068
4068
  background: transparent;
4069
4069
  box-shadow: none !important;
4070
4070
  color: var(--ui-text-secondary);
4071
+ font-size: 13px;
4071
4072
  font-weight: 500;
4072
4073
  line-height: 1.25;
4073
4074
  white-space: normal;
@@ -4076,19 +4077,19 @@ button:focus-visible { outline: 2px solid var(--ui-primary); outline-offset: -2p
4076
4077
  }
4077
4078
 
4078
4079
  .el-radio-group:has(.el-radio-button) .el-radio-button:not(.is-active):not(.is-disabled) .el-radio-button__inner:hover {
4079
- background: #f1f5f9;
4080
+ background: transparent;
4080
4081
  color: var(--ui-primary);
4081
4082
  }
4082
4083
 
4083
4084
  .el-radio-group:has(.el-radio-button) .el-radio-button.is-active .el-radio-button__inner {
4084
- background: linear-gradient(180deg, #438cf5, #2574e8);
4085
- box-shadow: inset 0 1px 0 rgb(255 255 255 / 30%), 0 4px 12px rgb(37 116 232 / 34%) !important;
4086
- color: #fff;
4085
+ background: var(--ui-surface);
4086
+ box-shadow: var(--ui-shadow-control) !important;
4087
+ color: var(--ui-primary);
4087
4088
  font-weight: 600;
4088
4089
  }
4089
4090
 
4090
4091
  .el-radio-group:has(.el-radio-button) .el-radio-button.is-active:not(.is-disabled) .el-radio-button__inner:active {
4091
- box-shadow: inset 0 2px 5px rgb(15 23 42 / 20%) !important;
4092
+ box-shadow: var(--ui-shadow-inset) !important;
4092
4093
  transform: translateY(1px);
4093
4094
  }
4094
4095
 
@@ -4098,8 +4099,9 @@ button:focus-visible { outline: 2px solid var(--ui-primary); outline-offset: -2p
4098
4099
  }
4099
4100
 
4100
4101
  .el-radio-group:has(.el-radio-button) .el-radio-button.is-active.is-disabled .el-radio-button__inner {
4101
- background: #dbeafe;
4102
- color: #64748b;
4102
+ background: var(--ui-surface);
4103
+ box-shadow: none !important;
4104
+ color: var(--el-disabled-text-color);
4103
4105
  }
4104
4106
 
4105
4107
  .el-radio-group:has(.el-radio-button) .el-radio-button__original-radio:focus-visible + .el-radio-button__inner {
package/src/types.ts CHANGED
@@ -21,7 +21,7 @@ export type GeneratorForm = {
21
21
  };
22
22
 
23
23
  export type ConfigForm = {
24
- appium: { reportSummary?: ReportSummaryConfig; model: AiRecognitionModel; promptOptimizer?: { model: AiRecognitionModel }; aiPromptPresets?: AiPromptPreset[]; aiDeduplication?: AiDeduplicationConfig; flowBackgroundColor?: string; flowLineColor?: string; screenshotReport?: boolean };
24
+ appium: { reportSummary?: ReportSummaryConfig; model: AiRecognitionModel; promptOptimizer?: { model: AiRecognitionModel }; aiPromptPresets?: AiPromptPreset[]; aiDeduplication?: AiDeduplicationConfig; flowBackgroundColor?: string; flowLineColor?: string; flowLineStyle?: 'straight' | 'curved'; screenshotReport?: boolean };
25
25
  runtime: {
26
26
  androidSdkPath: string;
27
27
  reportOutputPath: string;