Skip to content

fix: 建立前端统一运行环境判断层并修复宽屏触控设备进入会话误弹软键盘 - #1829

Merged
qqqqqf-q merged 1 commit into
mainfrom
fix/memoh-339-unified-runtime-env
Nov 22, 2026
Merged

qqqqqf-q merged 1 commit into
mainfrom
fix/memoh-339-unified-runtime-env

Conversation

@qqqqqf-q

Copy link
Copy Markdown
Member

Author

  • Human
  • Agent

Type

  • bug
  • feat
  • test

Summary

问题

  1. 原 composables/useIsMobile.ts 仅查询视口宽度 width < 768px(紧凑单栏布局断点),但函数名使用了移动设备含义。
  2. store/workspace-tabs.ts 中的 focusChatInputAfterEntry 与 composer-model-menu.vue 复用了 isMobile 判断是否跳过自动聚焦或点选后收起子菜单。在视口宽度 >= 768px 的触控主导设备(iPad、Android 平板、横屏现代 iPhone、开启桌面版网站的手机)上,isMobile 为 false,用户点击会话项切换会话时,微任务链在点击手势有效期内调用 textarea.focus(),触发 WebKit 每次弹出虚拟软键盘。
  3. 前端运行环境判断分散在多处:message-item.vue 单独调用 useMediaQuery 判断触控指针;平台识别在 keyboard-bindings.ts、pages/runtimes/command.ts、useMacTrafficReserve.ts 中存在三套实现;prefers-reduced-motion 在 Web 与 Desktop 共 12 处直接调用 window.matchMedia;6 处布局与页面各自调用 inject(DesktopShellKey, false)。

修改内容

  1. 建立四层正交运行环境判断入口:
    • 新增 apps/web/src/lib/runtime-env.ts(同步原语,导出 @memohai/web/lib/runtime-env 供 Desktop 渲染层复用):集中定义标准媒体查询常量、操作系统族识别 detectOsFamily(区分 android、ios、mac、windows、linux、unknown)与同步减动效读取 prefersReducedMotion。
    • 新增 apps/web/src/composables/useEnvironment.ts(响应式组合层):按四个正交维度拆分提供 useCompactShell(布局空间 < 768px)、useCoarsePointer / useTouchPointer / useCanHover / useInputModality(主输入与 any-* 共存输入矩阵及 canAutoFocusInput)、useDesktopShell(宿主容器)与 useReducedMotion(减动效偏好)。
  2. 收拢全站调用点并删除 composables/useIsMobile.ts:
    • 壳层布局切换(workspace-tabs 单栈约束、master-detail-sidebar-layout、settings-section、bots/detail、composer-continue-on)改用 useCompactShell。
    • 进入会话自动聚焦(workspace-tabs focusChatInputAfterEntry)与模型选择器子菜单聚焦/收起(composer-model-menu、model-options)改用 useCoarsePointer。
    • 消息长按(message-item)、平台识别(keyboard-bindings、runtimes/command、useMacTrafficReserve)、宿主壳读取与全部 12 处 prefers-reduced-motion 调用点(含 apps/desktop/src/renderer/src/connect/ConnectServer.vue)统一迁入新入口。
  3. 机械检查与前端规范同步:
    • 在 eslint.config.mjs 新增 no-restricted-syntax 规则,禁止 apps/web/src 与 apps/desktop/src/renderer 业务代码直接调用 useMediaQuery、matchMedia 或读取 navigator.platform / userAgent / maxTouchPoints。
    • 更新 .agents/skills/memoh-frontend-rules(SKILL.md、references/rules.md、references/review.md、references/architecture.md、references/upkeep.md)及目录行号。

行为、外观与默认值变更清单(D2)

  1. 宽屏粗指针设备(width >= 768px 且 pointer: coarse,含 iPad、平板及横屏手机):保持双栏多面板布局不变;打开/切换会话与新建会话不再自动聚焦对话输入框;展开模型子菜单不再自动聚焦搜索输入框(改为聚焦滚动容器),且点选模型或推理强度后自动收起当前子菜单。用户主动点击输入框或外接实体键盘直接按键(经 useUnfocusedComposerInput)仍正常输入。
  2. 窄窗口精细指针设备(width < 768px 且非 pointer: coarse,如拉窄窗口的桌面浏览器):切换为紧凑单栏布局,进入会话时继续自动聚焦输入框。
  3. 减动效动态响应:send-morph-icon.vue 与 dot-matrix-bg.vue 改为响应式订阅 useReducedMotion(),运行期切换系统减动效设置立即生效。
  4. Cloud 同步兼容说明:workspaceTabs.isMobile store 属性名保持不变以避免 Cloud 侧调用冲突;同步至 felinics/Memoh-Cloud 时需将 Cloud 专属页面(如 pages/saas/*.vue、components/feedback/feedback-dialog.vue)中的直接 navigator.platform / useMediaQuery 调用同步迁入统一入口以满足新增 ESLint 规则。

Related Issues

Validation

自动化检查

  • pnpm exec eslint apps/ packages/ eslint.config.mjs:0 errors(含新增环境原语拦截规则)。
  • node scripts/check-ui-contract.mjs 与 node scripts/check-settings-rows.mjs:通过。
  • pnpm --filter @memohai/web typecheck 与 pnpm --filter @memohai/desktop typecheck:通过。
  • pnpm test(Vitest 全量前端测试):312 个测试文件全部通过(2913 passed, 1 skipped),含新增的 runtime-env.test.ts、useEnvironment.test.ts 及 workspace-tabs.test.ts 宽屏触控平板与窄窗口桌面回归测试。
  • 未执行:Go 后端测试(本次未改动后端代码,交由 CI 校验)。

Agent 本地运行与真实界面验证(非人工 QA)

  • 环境:本分支 Vite 前端(http://127.0.0.1:8084)代理连接本地 memoh-dev 后端(http://localhost:18080),使用 ego-browser(Chromium)实测并截图:
    1. 桌面精细指针(1280x800,pointer: fine):双栏工作台正常渲染,点击历史会话后 document.activeElement 自动落入 TEXTAREA,输入框呈现聚焦边线。
    2. 宽屏粗指针平板模拟(1024x768,pointer: coarse,width >= 768px):保持双栏工作台布局,点击新建会话与切换历史会话后 document.activeElement 未落入 TEXTAREA(输入框保持静息边线,不触发软键盘);主动点击输入框后正常聚焦 TEXTAREA。
    3. 窄屏手机模拟(390x844,pointer: coarse,width < 768px):切换为紧凑单栏移动端外壳,进入会话不自动聚焦 TEXTAREA。
  • 未覆盖范围:本次通过 Chromium 设备与指针模拟验证,尚未在物理 iPad / iPhone 真机 Chrome 上执行人工验证。

Screenshots / Recordings

1. 桌面精细指针(1280x800):双栏布局 + 切换会话自动聚焦输入框

桌面精细指针下切换会话自动聚焦输入框

2. 宽屏粗指针平板(1024x768,pointer: coarse):保持双栏布局 + 切换会话不自动聚焦输入框

宽屏粗指针平板下切换会话保持双栏且不自动聚焦输入框

3. 窄屏粗指针手机(390x844):紧凑单栏外壳 + 不自动聚焦输入框

窄屏粗指针手机下使用紧凑单栏外壳且不自动聚焦输入框

Human QA

  • Human QA passed

@github-actions github-actions Bot added bug Fixes a bug or unexpected behavior change:desktop Changes the Electron desktop app or shared desktop configuration labels Nov 22, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T09:27:39.188892Z a1b8e14 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added change:web Changes web frontend or shared frontend packages size:M PR size uses the larger of added or deleted lines, excluding generated files labels Nov 22, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1b8e14821

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +274 to +275
focusSearch: (opts?: { avoidKeyboard?: boolean }) =>
((opts?.avoidKeyboard ? null : searchInput.value) ?? scrollEl.value)?.focus({ preventScroll: true }),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve listbox keyboard handling when bypassing search focus

On a coarse-pointer tablet with a hardware keyboard and at least 20 models, opening the composer’s model submenu now focuses the scroll viewport instead of the search input. However, ModelOptions only attaches the viewport’s onKeydown handler when showSearch is false, while composer-model-menu.vue stops these key events from propagating. Consequently, Arrow keys no longer update the active model and Enter cannot select it from the initial focus position. Keep the listbox keyboard handler available on the viewport when avoidKeyboard redirects focus there, so avoiding the software keyboard does not break hardware-keyboard navigation.

Useful? React with 👍 / 👎.

@qqqqqf-q
qqqqqf-q force-pushed the fix/memoh-339-unified-runtime-env branch from a1b8e14 to 0261838 Compare November 22, 2026 10:14
@qqqqqf-q
qqqqqf-q merged commit 6d57d18 into main Nov 22, 2026
13 checks passed
@qqqqqf-q
qqqqqf-q deleted the fix/memoh-339-unified-runtime-env branch November 22, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes a bug or unexpected behavior change:desktop Changes the Electron desktop app or shared desktop configuration change:web Changes web frontend or shared frontend packages size:M PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant