Skip to content

[Feature] 停止等待时间的默认值与上下限由 Core 公开,桌面端不再三次探测推导 #1830

Closed

Description

@xiaoyumuxi

Problem to solve / 要解决的问题

Core 的“停止程序时的等待时间”只给出解析结果,不公开它的默认值和上下限。Viva 桌面端的设置页要显示和校验这一项,只能反推。

  • Core 位置:rust/lithe-core/src/process/lifecycle.rs。常量 GRACEFUL_STOP_SECONDS: (u32, u32) = (1, 60);TerminationSettings::default() 的 graceful_stop_seconds: 5;resolve 用 .clamp(minimum, maximum) 算出 graceful_stop_milliseconds。processLifecycle.resolve 的结果只有这一个解析值,没有默认值,也没有上下限。
  • 桌面端位置:desktop/internal/workbench/process_exit.go 的 stopTimeRule(Epic(0.7.0): 基于 Viva 框架的跨平台方案的迁移(#1794) #1799,feature/1794-viva-workbench-shell)。它按 quit 上下文、以空记录调用 processLifecycle.resolve 三次,gracefulStopSeconds 依次为不填、0、math.MaxUint32,把三个结果当作默认值、下限和上限。这三个值交给 desktop/internal/settingswindow/process_termination_view.go 的 stopTimeCard:控制 −/+ 按钮的可用状态,并把输入值限制在范围内。
  • 判定依据:Core 的契约和 processLifecycle 的方法里,都找不到返回这三个值的入口。旧 macOS 客户端 ProcessTerminationSettingsView.swift 把 1–60 直接写在 Swift 里。

代价:

  • 每次打开窗口要多做三次进程内调用。
  • 推导依赖“越界会被限制到边界”这一实现细节。Core 若改为拒绝越界值或改动范围,桌面端的推导会悄悄出错。
  • 换 UI 壳子时还得再写一遍同样的推导。

Proposed solution / 建议方案

  1. Core 公开这项规则,二选一:在 processLifecycle.resolve 的结果里增加 gracefulStopRule: {defaultSeconds, minSeconds, maxSeconds};或者新增一个只读方法,例如 processLifecycle.settingsRule。规则来自 GRACEFUL_STOP_SECONDS 和 TerminationSettings::default(),与 resolve 共用同一份常量,并配上测试。
  2. 契约 README 和 fixture(shared/fixtures/process-lifecycle/)写明字段含义和单位。
  3. 桌面端 stopTimeRule 改读这个字段,删掉三次探测;TestStopTimeFollowsCoreAndTheSetting 改为断言读到的就是 Core 给出的规则。然后升级 PINNED_CORE_REVISION。

风险:涉及 Core 契约变化,桌面端要同步升级固定的 Core 版本;旧版 Core 没有这个字段时,桌面端要保留“规则未知时停用控件”的现有行为。

Target platform / 目标平台

Cross-platform / 跨平台

Area / 模块

Settings / 设置

Priority / 优先级

P2 / 后续考虑:目前不着急,可安排到后续版本

Alternatives considered / 已考虑的替代方案

  • 把 1–60 和 5 写在 Go 里:这是在复制 Core 的规则,两边改动不同步时设置页会显示错误的范围,不采用。
  • 保持三次探测:能用,但依赖越界会被限制到边界这一行为,没有契约保证。

Additional context / 补充信息

发现于 #1799 第二十一轮接入“停止程序”的等待时间设置时。在 Windows 上,停止程序会立即结束进程(buildprocess.StopsGracefully=false),设置页不显示这一项,所以目前只有 macOS 用到这项规则。相关文件:desktop/internal/workbench/process_exit.go、desktop/internal/settingswindow/controller.go(StopTime)、rust/lithe-core/src/process/lifecycle.rs(Core 仓库 Lithe-IDEA/Lithe-core-rust)。

Checklist / 提交前检查

  • I searched existing issues for duplicates. / 我已搜索现有 Issue,确认没有重复建议。

Activity

  1. added
    enhancement
    P2
    area:settings
    refactor
    on Nov 11, 2026
  2. added
    review: high
    on Nov 11, 2026
  3. added 3 commits that reference this issue on Nov 11, 2026
  4. xiaoyumuxi commented on Nov 14, 2026

    @xiaoyumuxi
    CollaboratorAuthor

    已完成:规则由 Lithe-IDEA/Lithe-core-rust#31 在 Core 中实现(2026-11-14 squash 合入 main,合并提交 62b8a08),桌面端由 #1889 改用这些 Core 命令并删除 Go 中的同名规则,已合入 preview。Core 固定版本改到 62b8a08 的收尾在 #1891。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:settingsenhancementplatform:cross-platformrefactorreview: high

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions