mcpField
H
hinge

hinge

github.com/artemnovichkov测试与质量4045 次安装1 周前更新
代码仓库

关于 hinge

hinge 是一项命令行技能,用于设置和读取已启动的可折叠 iPhone Simulator 的铰链角度。它还可报告设备姿态和当前显示屏,并截取该显示屏的屏幕图像。

主要功能

  1. 01设置角度和命名折叠状态
  2. 02读取角度、方向和姿态
  3. 03报告当前活动显示屏
  4. 04使用 sweep 动画调整角度
  5. 05截取活动显示屏

适用场景

  1. 01测试不同折叠角度下的布局
  2. 02检查 UI 所在的显示屏
  3. 03折叠后截取屏幕图像
  4. 04在模拟器测试中自动调整铰链

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/artemnovichkov/hinge --skill hinge

安装后在 Claude Code 中输入/hinge确认已加载。

附带文件scripts/hingescripts/hinge_helper.m

详细介绍

hinge

从命令行设置并读取已启动的可折叠 iPhone Simulator 的铰链角度。它会发送与 Xcode Device Hub 中隐藏的铰链滑块相同的 HID 事件(按住 Option)。

从此技能目录的相对路径运行附带的脚本 scripts/hinge。也可以使用 PATH 中的 hinge,但前提是运行 hinge -v 输出的版本与 scripts/hinge -v 相同;较旧的安装版本不支持 screenshot 和 --json。

命令

scripts/hinge 120                # set angle: 0 = closed, 180 = flat
scripts/hinge open               # 180°
scripts/hinge close              # 0°
scripts/hinge half               # 90°
scripts/hinge sweep 180 0 2      # animate from 180° to 0° over 2 seconds
scripts/hinge get                # print current angle, e.g. 130.0
scripts/hinge posture            # angle, orientation, and which integrated display is active
scripts/hinge posture --json     # the same as JSON; also works with get, orientation, screenshot
scripts/hinge screenshot out.png # capture the display that hosts the UI
scripts/hinge rotate left        # rotate 90°, like Device Hub's Controls > Rotate Left; prints the new orientation
scripts/hinge rotate right
scripts/hinge orient landscape-left  # portrait, landscape-left, landscape-right, or portrait-upside-down
scripts/hinge orientation        # print current orientation, e.g. landscape-left
scripts/hinge -d "iPhone Duo" 90 # target a simulator by name or UDID (default: $HINGE_DEVICE, else the only booted iPhone Duo)
scripts/hinge -t 0 90            # set without waiting for the angle to be confirmed

open、close 和 half 也接受 unfolded/flat、closed/folded 和 half-open。

工作流

  1. 确保可折叠模拟器已启动:xcrun simctl list devices booted。如果未指定 -d,hinge 会选择唯一已启动的 iPhone Duo;如果有多个,它会列出这些设备并退出——请传入 -d <udid> 或设置 HINGE_DEVICE,不要猜测。
  2. 设置角度。模拟器报告新角度后,命令即会返回,因此非零退出码意味着折叠未完成——不要通过轮询 get 来检查。
  3. 等待显示屏切换后再截图或读取 UI:角度变化后需要等待 1-2.5 秒。
  4. 折叠后,scripts/hinge posture 会指出 UI 所在的显示屏(active)。解析输出时请使用 --json:activeDisplay 表示该显示屏。
  5. 使用 scripts/hinge screenshot out.png 截图。它会捕获当前活动显示屏,因此仍需遵循第 3 步的等待时间。对于可折叠设备,直接使用 simctl io … screenshot 会失败并返回 Invalid argument,除非指定 --display=LCD(外屏)或 --display=LCD-1(内屏)。

备注

  • 仅支持模拟器,不能用于实体设备。
  • 首次运行时,会使用 Xcode 的 clang 编译一个小型辅助程序,并将其缓存到 ~/.cache/hinge。这需要几秒钟。
  • sweep 会在单个进程中以 60 Hz 运行。要实现流畅动画,请使用它,而不是多次调用 set。它不会确认最终角度。
  • 设置角度不等于切换显示屏。角度会得到确认;显示屏切换则由模拟器决定。0° 和 180° 通常会触发切换,中间角度则取决于铰链移动的路径(缓慢的 sweep 可能会让显示屏保持不变,直到结束),而且有时模拟器会完全停止跟随铰链,但仍报告新角度。请始终使用 posture 检查,不要想当然;停止跟随铰链的模拟器仍会报告正确角度,关机后重新启动即可清除此问题。
  • UI 所在的显示屏由 active 表示,而不是背光状态:折叠后的 Duo 会点亮外屏,并将其标记为 inactiveOn;背光状态最多会比折叠操作延迟 3 秒。
  • 不接受 0-180 之外的角度。没有铰链的模拟器会报错:“this simulator reports no hinge”。
  • orient、orientation 和 rotate 使用设备方向(即 devicectl 中的名称),而不是界面方向:设备处于 landscape-right 时,会显示为 landscape-left 界面。
  • 可折叠设备的方向只遵循 Device Hub 自身的事件;xcrun devicectl device orientation set 虽然会报告成功,但方向会被还原。rotate/orient 会发送 Device Hub 事件,并在忽略该事件的模拟器上回退到 devicectl。
  • 此工具使用了私有且未公开的协议。已在 iOS 27.1 上使用 Xcode 27.1 和 27.2 验证,在其他版本中可能会失效。如果设置角度失败并显示“the hinge angle did not reach ...”,请报告协议可能已更改。

评论

支持 Markdown