diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d97a5c..9d14d0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,13 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ### Changed / 变更 +- “+ 应用”改为先添加空白步骤并聚焦路径输入框,不再强制打开文件对话框。路径区用更明确的提示、占位符和「查找」在前的按钮顺序强调按名称查找;在路径框按 Enter 也会触发查找,但输入过程中不会自动改写路径。保存、试运行和导出仍要求填写有效绝对路径。 - Professional 工作台不再提供“+ 等待”按钮。等待步骤仍可加载、编辑和运行;步骤之间的间隔请使用各步骤的“后续延迟(秒)”。 - 从 Professional 导出的独立启动器在执行命令步骤时会弹出可交互的控制台窗口(`CREATE_NEW_CONSOLE` 并继承标准输入输出),便于查看输出和交互。编辑器内试运行仍将输出捕获到日志面板。短命令结束时控制台可能很快关闭。 ### Fixed / 修复 +- `tools/check_app_paths_smoke.py` 在干净工作树(没有 gitignored 的 `data/app_templates.json`)上也能运行,并继续证明测试不会改写源码树中的数据文件。 +- 导入 `shared.platform.shortcuts` 不再连带加载 `shared.models`,恢复快捷键策略的隔离约定。`shared.basic_policy` 改为在需要时再导入 Plan。 - 当日志抽屉被拖到最小高度时,“运行与输出日志”标题不再与状态文本重叠,“恢复高度”按钮保持完整可见且可点击。最小高度以标题行为准,不再被日志正文的最小高度挤扁。 - 网址若未写 scheme(例如 `www.baidu.com`),会在输入、保存、预检、试运行和导出时统一补上 `https://`。已显式写出的 scheme(包括 http、https 以及其他 scheme)不会被改写。Basic 仍拒绝非 HTTP/HTTPS。 - 修复 Professional“执行命令”多行输入框在获得焦点时出现模糊/双层蓝框的问题(去掉 QTextEdit 原生边框,只保留样式表描边)。 diff --git a/README.md b/README.md index bb4bbc2..0da75d6 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ LaunchFlow 有意保持小而通用的步骤模型。Professional / 当前默认 Command 在后台以无控制台窗口方式运行,界面仍会保留原始诊断信息。若 Windows 返回 `9009`,日志会在保留退出码和 stderr 的同时提示“未找到可执行命令,请检查程序是否安装或是否加入 PATH。”;找不到目标文件或权限不足时也会显示对应的友好说明。原始 `command`、`returncode`、`stdout`、`stderr` 不会被隐藏。 -Application 步骤用于启动外部程序,本身不等待外部程序退出;后续延迟用于给应用留出启动时间。URL 使用系统默认浏览器。Wait 是流程中的显式暂停。若一个步骤失败,日志会明确标识失败位置,方便在编辑器中返回该步骤修正参数。 +Application 步骤用于启动外部程序,本身不等待外部程序退出;后续延迟用于给应用留出启动时间。添加应用步骤后,可以输入程序名(例如 steam)再点击「查找」或在路径框按 Enter,不必先在磁盘里逐层选择;也可以浏览或直接填写绝对路径。查找只会检索本机常用位置,不会扫描整个磁盘。URL 使用系统默认浏览器。Wait 是流程中的显式暂停。若一个步骤失败,日志会明确标识失败位置,方便在编辑器中返回该步骤修正参数。 ## 🗂️ 方案、最近记录与备份 @@ -135,7 +135,7 @@ Application 步骤用于启动外部程序,本身不等待外部程序退出 1. 把 `LaunchFlow.exe` 放入普通用户可写目录并启动。 2. 如授权页出现,复制离线请求码并交给许可管理员签发。 3. 导入收到的 `.lic` 文件,完成本机校验。 -4. 新建方案,依次添加步骤并填写参数。 +4. 新建方案,依次添加步骤并填写参数。添加应用时,可按名称查找、浏览或填写路径。 5. 先试运行,确认日志无未解决错误。 6. 保存方案;需要交付时再执行导出。 diff --git a/README_EN.md b/README_EN.md index 9143643..e57f3ac 100644 --- a/README_EN.md +++ b/README_EN.md @@ -83,7 +83,7 @@ Select Run or press `Ctrl+R` to execute the plan from top to bottom. The log dra Command steps run in the background without opening a console window, but the original diagnostic information is retained. When Windows returns `9009`, LaunchFlow keeps the return code and stderr and also explains that the executable command could not be found and that installation or PATH should be checked. Missing target files and insufficient permission receive similarly direct explanations. The raw `command`, `returncode`, `stdout`, and `stderr` remain available rather than being replaced by the friendly message. -An Application step launches an external process and continues without waiting for that process to exit; its post-launch delay can provide startup time. URL uses the system default browser. Wait is an explicit pause within the plan. When a step fails, the log identifies the failing position so the user can return to that card and correct its settings. +An Application step launches an external process and continues without waiting for that process to exit; its post-launch delay can provide startup time. After you add an Application step, type a program name such as steam and click Find or press Enter in the path field; you do not have to walk the filesystem first. You can still browse or paste an absolute path. Find searches common local locations only and does not scan the whole disk. URL uses the system default browser. Wait is an explicit pause within the plan. When a step fails, the log identifies the failing position so the user can return to that card and correct its settings. ## 🗂️ Plans, Recent Files, and Backups @@ -135,7 +135,7 @@ A normal packaged workflow is: 1. Place `LaunchFlow.exe` in an ordinary user-writable directory and start it. 2. If activation is requested, copy the offline request code and send it to the license administrator. 3. Import the returned `.lic` file to complete local verification. -4. Create a plan, add steps in order, and fill in their parameters. +4. Create a plan, add steps in order, and fill in their parameters. When adding an Application step, you can look it up by name, browse, or type a path. 5. Test-run the plan and resolve any remaining log errors. 6. Save the plan, and export it only when a separate launcher is needed. diff --git a/editor/edition_ui.py b/editor/edition_ui.py index ed29148..c01eb9f 100644 --- a/editor/edition_ui.py +++ b/editor/edition_ui.py @@ -32,8 +32,16 @@ PROFESSIONAL_EMPTY_STEPS_HINT = "请先在左侧点击“+ 应用 / + 网页 / + 命令”来添加步骤。步骤之间的间隔请使用“后续延迟”。" BASIC_EMPTY_STEPS_HINT = "请先在左侧点击“+ 应用 / + 网页”来添加步骤。" -PROFESSIONAL_APP_PATH_PLACEHOLDER = "输入绝对路径,或浏览 / 按名称查找 .exe / .bat / .cmd / .ps1" -BASIC_APP_PATH_PLACEHOLDER = "输入绝对路径,或浏览 / 按名称查找本地 .exe / .lnk" +PROFESSIONAL_APP_PATH_PLACEHOLDER = "输入程序名后点击查找,例如 steam" +BASIC_APP_PATH_PLACEHOLDER = "输入程序名后点击查找,例如 steam" +PROFESSIONAL_APP_PATH_HINT = ( + "输入程序名后点击「查找」,例如 steam。查找只会检索本机常用位置,不会扫描整个磁盘。" + "也可以「浏览」或直接填写绝对路径(.exe / .bat / .cmd / .ps1 / .lnk)。" +) +BASIC_APP_PATH_HINT = ( + "输入程序名后点击「查找」,例如 steam。查找只会检索本机常用位置,不会扫描整个磁盘。" + "也可以「浏览」或直接填写本地 .exe / .lnk 路径。" +) PROFESSIONAL_LOG_HINT = "后台 Command 的标准输出、错误和退出码集中显示在这里。" BASIC_LOG_HINT = "应用和网页步骤的运行结果会显示在这里。" @@ -80,6 +88,10 @@ def application_path_placeholder() -> str: return BASIC_APP_PATH_PLACEHOLDER if is_basic_edition_active() else PROFESSIONAL_APP_PATH_PLACEHOLDER +def application_path_hint() -> str: + return BASIC_APP_PATH_HINT if is_basic_edition_active() else PROFESSIONAL_APP_PATH_HINT + + def application_lookup_suffixes() -> tuple[str, ...]: """Return the path suffixes keyword lookup may store for this edition.""" diff --git a/editor/services/plan_service.py b/editor/services/plan_service.py index 7c85404..12d468f 100644 --- a/editor/services/plan_service.py +++ b/editor/services/plan_service.py @@ -308,6 +308,10 @@ def create_app_step(self, app_name: str, app_path: str) -> AppStep: working_dir="", delay_after=1.0, ) + # A blank path is a legitimate in-editor draft. Completeness is still + # enforced when the plan is saved, trial-run, or exported. + if not str(app_path or "").strip(): + return step enforce_basic_policy_on_ingress(Plan(plan_name="app-step", steps=[step])) return step diff --git a/editor/ui/main_window.py b/editor/ui/main_window.py index 921c672..741f7a7 100644 --- a/editor/ui/main_window.py +++ b/editor/ui/main_window.py @@ -117,6 +117,7 @@ from editor.edition_ui import ( application_file_dialog_filter, application_lookup_suffixes, + application_path_hint, application_path_placeholder, brand_title, empty_steps_hint, @@ -2349,6 +2350,7 @@ def _apply_edition_presentation(self) -> None: self.brand_title_label.setText(brand_title()) self.empty_steps_subtitle.setText(empty_steps_hint()) self.app_path_in.setPlaceholderText(application_path_placeholder()) + self.app_path_hint.setText(application_path_hint()) self.log_hint.setText(log_hint_text()) def _build_menu_bar(self) -> QMenuBar: @@ -2444,20 +2446,30 @@ def _build_property_editors(self) -> None: self.btn_find_app_path = QPushButton("查找") self.btn_browse_app_path.setObjectName("AppPathBrowseButton") self.btn_find_app_path.setObjectName("AppPathFindButton") - self.btn_browse_app_path.setToolTip("打开文件对话框,选择要启动的程序") - self.btn_find_app_path.setToolTip("根据输入的关键词在本机查找程序,例如 steam") + self.btn_browse_app_path.setToolTip("打开文件对话框,选择要启动的程序。如果更熟悉程序名称,请改用查找。") + self.btn_find_app_path.setToolTip("按输入的名称在本机查找程序,例如 steam。不会扫描整个磁盘。也可在路径框中按 Enter。") self.application_lookup = lookup_windows_application path_row = QWidget() path_layout = QHBoxLayout(path_row) path_layout.setContentsMargins(0, 0, 0, 0) path_layout.setSpacing(8) path_layout.addWidget(self.app_path_in, 1) - path_layout.addWidget(self.btn_browse_app_path) path_layout.addWidget(self.btn_find_app_path) + path_layout.addWidget(self.btn_browse_app_path) + self.app_path_hint = self._make_label(application_path_hint(), "panel_hint") + self.app_path_hint.setObjectName("AppPathHint") + self.app_path_hint.setWordWrap(True) + path_column = QWidget() + path_column_layout = QVBoxLayout(path_column) + path_column_layout.setContentsMargins(0, 0, 0, 0) + path_column_layout.setSpacing(6) + path_column_layout.addWidget(path_row) + path_column_layout.addWidget(self.app_path_hint) app_form.addRow("步骤名称", self.app_name_in) - app_form.addRow("程序路径", path_row) + app_form.addRow("程序路径或名称", path_column) self.btn_browse_app_path.clicked.connect(self._on_browse_app_path) self.btn_find_app_path.clicked.connect(self._on_find_app_path) + self.app_path_in.returnPressed.connect(self._on_find_app_path) app_form.addRow("启动参数", self.app_args_in) app_form.addRow("后续延迟(秒)", self.app_delay_in) self.editor_stack.addWidget(self.page_app) @@ -2746,7 +2758,7 @@ def _configure_tooltips(self) -> None: self.btn_delete_step.setToolTip( self._shortcut_tooltip("删除当前选中步骤", self.action_delete_step) ) - self.btn_add_app.setToolTip("添加一个应用启动步骤") + self.btn_add_app.setToolTip("添加一个应用步骤。添加后可按名称查找、浏览或填写路径,不必先在磁盘里逐层选择。") self.btn_add_url.setToolTip("添加一个网页打开步骤") self.btn_add_cmd.setToolTip("添加一个后台命令步骤,输出显示在日志区") self.btn_add_wait.setToolTip("等待步骤仍可加载和运行,请使用各步骤的后续延迟。") @@ -3602,21 +3614,16 @@ def _commit_before_editor_boundary(self, title: str) -> bool: # ---------------- add step ---------------- def _on_add_app_step(self) -> None: - """ - 通过文件选择框添加一个应用步骤。 + """Add a blank Application step so the user can find, browse, or type a path. - 说明: - - Professional 支持 exe / bat / cmd / ps1 / lnk 等常见启动入口; - - Basic 只提供本地 .exe / .lnk 选择; - - 选择成功后会立即将步骤加入当前方案并刷新界面。 + The add button no longer opens a file dialog first. Completeness is + still enforced on save, trial-run, and export. Browse remains available + in the inspector after the draft step is created. """ - file_path = self._choose_application_file(start_dir="") - if not file_path: - return if not self._commit_before_editor_boundary("无法新增步骤"): return - new_step = self.plan_service.create_app_step(Path(file_path).stem, file_path) + new_step = self.plan_service.create_app_step("新应用", "") self.current_plan.steps.append(new_step) self.current_editor_index = None self._refresh_flow_list() @@ -3733,15 +3740,14 @@ def _select_new_step(self, index: int) -> None: self.flow_list.scrollToItem(item) step = self.current_plan.steps[index] - editor = ( - self.app_name_in - if isinstance(step, AppStep) - else self.url_name_in - if isinstance(step, UrlStep) - else self.cmd_name_in - if isinstance(step, CommandStep) - else self.wait_name_in - ) + if isinstance(step, AppStep): + editor = self.app_path_in + elif isinstance(step, UrlStep): + editor = self.url_name_in + elif isinstance(step, CommandStep): + editor = self.cmd_name_in + else: + editor = self.wait_name_in editor.setFocus() editor.selectAll() diff --git a/shared/basic_policy.py b/shared/basic_policy.py index cfc5f10..d86bd85 100644 --- a/shared/basic_policy.py +++ b/shared/basic_policy.py @@ -26,12 +26,13 @@ import re from dataclasses import dataclass from enum import Enum -from typing import Any, Callable, Iterable, Mapping, Protocol, runtime_checkable +from typing import TYPE_CHECKING, Any, Callable, Iterable, Mapping, Protocol, runtime_checkable from urllib.parse import urlparse from shared.url_normalization import normalize_missing_url_scheme -from shared.models import Plan +if TYPE_CHECKING: + from shared.models import Plan BASIC_FIXED_DELAY_SECONDS = 1.0 @@ -191,6 +192,13 @@ class BasicPolicyDependencies: shortcut_resolver: ShortcutResolver | ShortcutResolverCallable | None = None +def _is_plan(value: object) -> bool: + # Import Plan only when a caller actually needs to distinguish a Plan object. + from shared.models import Plan + + return isinstance(value, Plan) + + def validate_basic_plan_document( document: Any, *, @@ -211,7 +219,7 @@ def validate_basic_plan_document( drive_classifier=drive_classifier, shortcut_resolver=shortcut_resolver, ) - if isinstance(document, Plan): + if _is_plan(document): return validate_basic_plan( document, filesystem=deps.filesystem, @@ -236,7 +244,7 @@ def validate_basic_plan( use validate_basic_plan_document() first. """ - if not isinstance(plan, Plan): + if not _is_plan(plan): return BasicPolicyResult( False, ( diff --git a/tools/check_app_paths_smoke.py b/tools/check_app_paths_smoke.py index 365b025..674de87 100644 --- a/tools/check_app_paths_smoke.py +++ b/tools/check_app_paths_smoke.py @@ -41,7 +41,14 @@ def main() -> None: temp_root.mkdir(parents=True) alternate_cwd.mkdir() - protected_source_files = [PROJECT_ROOT / "data" / "app_templates.json", PROJECT_ROOT / "data" / "settings.json"] + tracked_settings = PROJECT_ROOT / "data" / "settings.json" + gitignored_templates = PROJECT_ROOT / "data" / "app_templates.json" + if not tracked_settings.is_file(): + raise AssertionError(f"missing tracked source file: {tracked_settings}") + templates_existed = gitignored_templates.is_file() + protected_source_files = [tracked_settings] + if templates_existed: + protected_source_files.append(gitignored_templates) before_hashes = {path: _sha256(path) for path in protected_source_files} old_override = os.environ.get(APP_DATA_ENV) old_cwd = Path.cwd() @@ -111,6 +118,10 @@ def main() -> None: after_hashes = {path: _sha256(path) for path in protected_source_files} if before_hashes != after_hashes: raise AssertionError("read-only source data changed") + if not templates_existed and gitignored_templates.exists(): + raise AssertionError( + "clean-tree smoke created gitignored data/app_templates.json in the source tree" + ) finally: reset_app_logger_for_tests() sys.executable = old_executable diff --git a/tools/check_application_path_picker_smoke.py b/tools/check_application_path_picker_smoke.py index 757a539..d642df1 100644 --- a/tools/check_application_path_picker_smoke.py +++ b/tools/check_application_path_picker_smoke.py @@ -22,7 +22,9 @@ from PySide6.QtWidgets import QApplication, QFileDialog # noqa: E402 from editor.edition_ui import ( # noqa: E402 + BASIC_APP_PATH_HINT, BASIC_APP_PATH_PLACEHOLDER, + PROFESSIONAL_APP_PATH_HINT, PROFESSIONAL_APP_PATH_PLACEHOLDER, application_file_dialog_filter, application_lookup_suffixes, @@ -89,6 +91,16 @@ def check_shared_controls(window: MainWindow, *, basic: bool) -> None: require(window.app_path_in.isVisible(), "path field should stay visible once an App step is selected") expected = BASIC_APP_PATH_PLACEHOLDER if basic else PROFESSIONAL_APP_PATH_PLACEHOLDER require(window.app_path_in.placeholderText() == expected, "path placeholder drifted") + expected_hint = BASIC_APP_PATH_HINT if basic else PROFESSIONAL_APP_PATH_HINT + require(hasattr(window, "app_path_hint"), "path hint label is missing") + require(window.app_path_hint.isVisible(), "path hint should stay visible once an App step is selected") + require(window.app_path_hint.text() == expected_hint, "path hint drifted") + path_layout = window.btn_find_app_path.parentWidget().layout() + require(path_layout is not None, "path button row is missing") + require( + path_layout.indexOf(window.btn_find_app_path) < path_layout.indexOf(window.btn_browse_app_path), + "Find should appear before Browse in the path row", + ) suffixes = application_lookup_suffixes() require( suffixes == (BASIC_LOOKUP_SUFFIXES if basic else PROFESSIONAL_LOOKUP_SUFFIXES), @@ -215,6 +227,53 @@ def cancel_picker(matches: tuple[ApplicationLookupMatch, ...]): require(window.app_path_in.text() == "demo", "cancelled chooser must not invent a path") +def check_enter_triggers_find(window: MainWindow) -> None: + _select_app_step(window) + found_path = r"C:\Program Files (x86)\Steam\steam.exe" + window.app_path_in.setText("steam") + calls: list[str] = [] + + def unique_lookup(keyword: str, **_kwargs: object) -> ApplicationLookupResult: + calls.append(keyword) + match = ApplicationLookupMatch(found_path, "Steam", SOURCE_APP_PATHS, "App Paths") + return ApplicationLookupResult("steam", STATUS_FOUND, (match,), f"已找到 Steam:{found_path}") + + window.application_lookup = unique_lookup + window.app_path_in.returnPressed.emit() + QApplication.processEvents() + require(calls == ["steam"], "Enter in the path field should run an explicit Find") + require(window.app_path_in.text() == found_path, "Enter Find did not fill the absolute path") + + +def check_add_app_creates_draft(window: MainWindow) -> None: + before = len(window.current_plan.steps) if window.current_plan is not None else 0 + calls: list[object] = [] + old_dialog = QFileDialog.getOpenFileName + + def fake_dialog(*args: object, **kwargs: object) -> tuple[str, str]: + calls.append((args, kwargs)) + return r"C:\ShouldNotOpen\demo.exe", "Applications" + + QFileDialog.getOpenFileName = staticmethod(fake_dialog) # type: ignore[method-assign] + try: + window.btn_add_app.click() + QApplication.processEvents() + finally: + QFileDialog.getOpenFileName = old_dialog # type: ignore[method-assign] + require(calls == [], "adding an Application step must not force the file dialog") + require(window.current_plan is not None, "adding an Application step lost the plan") + require(len(window.current_plan.steps) == before + 1, "adding an Application step did not append a draft") + step = window.current_plan.steps[-1] + require(isinstance(step, AppStep), "draft step was not an Application step") + require(step.path == "", "new Application step should start with a blank path") + require(window.app_path_in.text() == "", "path field should stay empty for a new draft") + require(window.app_path_in.hasFocus(), "new Application step should focus the path field") + require( + window.btn_find_app_path.isVisible() and window.btn_browse_app_path.isVisible(), + "draft inspector lost Find/Browse", + ) + + def main() -> int: app = QApplication.instance() or QApplication([]) previous = set_process_edition_context(EditionContext()) @@ -229,6 +288,8 @@ def main() -> int: check_browse_sets_path(professional) check_find_unique_and_not_found(professional) check_find_ambiguous_picker(professional) + check_enter_triggers_find(professional) + check_add_app_creates_draft(professional) os.environ[APP_DATA_ENV] = str(_temp_data / "basic") basic = _build_window(PROJECT_ROOT, basic=True) @@ -236,10 +297,11 @@ def main() -> int: check_shared_controls(basic, basic=True) _select_app_step(basic, path=r"C:\Games\steam.exe") check_browse_sets_path(basic) + check_add_app_creates_draft(basic) require(professional.btn_find_app_path.isVisible(), "creating a Basic window changed Professional controls") print("application path picker smoke ok") print("editions=professional,basic") - print("cases=placeholder,type,browse,unique-find,not-found,ambiguous,cancel") + print("cases=placeholder,hint,type,browse,unique-find,not-found,ambiguous,cancel,enter-find,add-draft") return 0 finally: for window in windows: diff --git a/tools/check_platform_coupling_baseline.json b/tools/check_platform_coupling_baseline.json index 6600253..754128c 100644 --- a/tools/check_platform_coupling_baseline.json +++ b/tools/check_platform_coupling_baseline.json @@ -1243,7 +1243,7 @@ "allowed_to_remain": true }, { - "fingerprint": "2b6e2a2bbad56426944a", + "fingerprint": "facd86a1fe0ed7d1f641", "path": "editor/edition_ui.py", "rule_id": "WIN-ASSET-001", "area": "artifacts", @@ -1253,7 +1253,7 @@ "allowed_to_remain": true }, { - "fingerprint": "5fa9e5285f3e78718375", + "fingerprint": "5f30d67b50a941d7cacb", "path": "editor/edition_ui.py", "rule_id": "WIN-ASSET-001", "area": "artifacts",