Skip to content

feat(settings): ask before leaving Fusion settings with unsaved edits - #1700

Merged
jiangzhuqing000 merged 9 commits into
mainfrom
pr/dev-jiangzhuqing000
Nov 26, 2026
Merged

jiangzhuqing000 merged 9 commits into
mainfrom
pr/dev-jiangzhuqing000

Conversation

@jiangzhuqing000

Copy link
Copy Markdown
Collaborator

问题

Fusion 设置页的保存按钮原本是参与者列表之后的一个小号次要按钮,位于长列表末尾:要滚到底才看得到,看起来像脚注而不是「让改动生效」的那一步。而离开这个页面(切到其它设置页、点搜索结果、点遮罩、按 Esc、在配对机器页点「返回」)会把草稿直接丢掉,没有任何提示——用户很容易以为自己已经保存了,实际还是旧配置。

改动

离开前询问。 新增 desktop/src/features/settings/unsavedGuard.tsx:由拥有导航的那一层(设置对话框、配对机器设置页)托管守卫,带草稿的页面把「我在编辑什么 / 现在脏不脏 / 怎么保存」注册进来;离开时若有未保存改动,弹出「还有未保存的修改」,三选一:继续编辑 · 放弃修改 · 保存并离开(保存失败会留在原页并显示错误)。所有退出路径都经过它:设置页切换、搜索跳转、遮罩、Esc、远端页的返回。没有改动时直接走,不会打扰。

保存动作变明显。 按钮移到底部常驻栏(sticky,在内容之上),左侧用 aria-live 说明草稿状态:无改动「修改后需点击保存才会生效。」/ 有改动「有未保存的修改」/ 刚保存「已保存」;右侧是 primary 实心按钮,不再随列表滚出视野。

persist() 改为返回 Promise<boolean>,供守卫判断「保存并离开」是否真的成功。

验证

  • 真实 UI(headless Chrome + demo 数据)跑完整流程:干净时按钮禁用、改动后栏显示「有未保存的修改」且按钮可点、切页弹出提示、继续编辑保留草稿、保存并离开后落到目标页;配对机器页同样验证。
  • tsc --noEmit 干净;eslint src/features/settings src/features/remote-peer 零告警;相关区域 vitest 通过(新增 12 个用例:保存栏 2、页面守卫 5、设置对话框接线 4、远端返回 1)。

Windows accepts `/` in most path APIs, but `explorer` does not: handed
`/select,"C:/Users/me/pic.png"` it opens Documents (or Desktop) instead — the
same wrong-folder symptom as a path that no longer exists, from a file that is
right where the link says it is. That spelling is not exotic: it is how a model
writes the link for a file it just saved the POSIX way, so "show in folder" on
a perfectly present file revealed nowhere near it.

Verified against the real file both ways: the backslash spelling selects the
file, the forward-slash spelling lands on Documents. `select_argument` and the
missing-file folder fallback now build their target from the native spelling;
elsewhere `/` is the separator and nothing changes.
The system file picker answers with the provider's URI rather than a path
(`content://` on Android), and the whole upload then reads through that
provider. A provider may serve only a stream — no size, no random access —
and the transfer reads one chunk at a time through a seekable handle, so it
finds nothing left to send and stops with a stalled attachment. Images never
met this: the photo picker and the converter both hand back files the app
owns, which is why only documents failed.

A picked document is now copied into the app's cache while the reader is
still in the picker, and the message carries the copy. When the copy comes
back empty (a size-driven copy of a stream reports success having written
nothing) the whole document is read instead — the one read every provider
supports — and the copy's size, not the provider's claim, becomes the
message's size, so an announced size the bytes disagree with can no longer
arrive at the desktop as an incomplete upload.

The copy also moves the point of failure: a document nobody can read is
refused before the waiting message's "+" cancels that message for a re-send,
so the reader loses neither the file nor the message, and says which of the
two it was.
The Fusion page keeps a draft and applies it only through its save action, but
every way out of it — another settings tab, a search result, the backdrop,
Escape, "back" on a paired machine — dropped the draft without a word. A user
who believed the change had already been applied kept the old configuration.

`unsavedGuard.tsx` gives the surface that owns navigation a guard: a page with a
draft registers what it holds, and leaving asks first (keep editing / discard /
save and leave). The settings dialog and the paired-machine settings page route
their exits through it and hand its API to the Fusion page.

The save action is now a bar pinned to the bottom of the page that says where
the draft stands ("unsaved changes", "saved", "changes apply only after you
save"), and is a primary button rather than the small secondary one that sat
under the participant list and read as a footnote.
@jiangzhuqing000
jiangzhuqing000 enabled auto-merge (squash) November 26, 2026 07:14
@jiangzhuqing000
jiangzhuqing000 merged commit b8e414d into main Nov 26, 2026
10 checks passed
@jiangzhuqing000
jiangzhuqing000 deleted the pr/dev-jiangzhuqing000 branch November 26, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant