Repository navigation
fix(hid): route toolbar Home through SpringBoardLauncher #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
35f2f0f
fix(hid): route toolbar Home through SpringBoardLauncher
EvanBacon 2e1fb42
fix(hid): gate home-indicator flick to Face ID portrait
EvanBacon c77c0db
fix(hid): do not flick Home until orientation is known
EvanBacon dd823d6
fix(hid): confirm portrait from the first 0x07 on a fresh session
EvanBacon c175c83
fix(hid): cancel a timed-out Home and retry chrome lookup
EvanBacon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { | ||
| createHostRpcHandler, | ||
| DEFAULT_PRESS_HOME_TIMEOUT_MS, | ||
| type RunResult, | ||
| } from "../host-rpc"; | ||
|
|
||
| const UDID = "11111111-2222-3333-4444-555555555555"; | ||
|
|
||
| function handler(opts: { | ||
| known?: boolean; | ||
| pressHome?: (udid: string, signal?: AbortSignal) => Promise<boolean>; | ||
| pressHomeTimeoutMs?: number; | ||
| } = {}) { | ||
| const calls: Array<[string, string[]]> = []; | ||
| const events: string[] = []; | ||
| const rpc = createHostRpcHandler({ | ||
| serveSimBin: "serve-sim", | ||
| isKnownDevice: async () => opts.known ?? true, | ||
| pressHome: opts.pressHome, | ||
| pressHomeTimeoutMs: opts.pressHomeTimeoutMs, | ||
| onCommandResult: (command) => events.push(command), | ||
| run: async (file, args): Promise<RunResult> => { | ||
| calls.push([file, args]); | ||
| return { stdout: args.includes("launch") ? "com.apple.springboard: 1\n" : "", stderr: "", exitCode: 0 }; | ||
| }, | ||
| }); | ||
| return { rpc, calls, events }; | ||
| } | ||
|
|
||
| describe("home", () => { | ||
| test("uses the native pressHome path and does not shell out to simctl", async () => { | ||
| const pressed: string[] = []; | ||
| const { rpc, calls, events } = handler({ | ||
| pressHome: async (udid) => { | ||
| pressed.push(udid); | ||
| return true; | ||
| }, | ||
| }); | ||
| expect(await rpc({ method: "home", params: { udid: UDID } })).toEqual({ | ||
| stdout: "", | ||
| stderr: "", | ||
| exitCode: 0, | ||
| }); | ||
| expect(pressed).toEqual([UDID]); | ||
| expect(calls).toEqual([]); | ||
| expect(events).toEqual([`serve-sim button home -d ${UDID}`]); | ||
| }); | ||
|
|
||
| test("falls back to simctl launch when pressHome returns false", async () => { | ||
| const { rpc, calls } = handler({ pressHome: async () => false }); | ||
| expect(await rpc({ method: "home", params: { udid: UDID } })).toMatchObject({ exitCode: 0 }); | ||
| expect(calls).toEqual([["xcrun", ["simctl", "launch", UDID, "com.apple.springboard"]]]); | ||
| }); | ||
|
|
||
| test("falls back to simctl launch when pressHome throws", async () => { | ||
| const { rpc, calls } = handler({ | ||
| pressHome: async () => { | ||
| throw new Error("no session"); | ||
| }, | ||
| }); | ||
| expect(await rpc({ method: "home", params: { udid: UDID } })).toMatchObject({ exitCode: 0 }); | ||
| expect(calls).toEqual([["xcrun", ["simctl", "launch", UDID, "com.apple.springboard"]]]); | ||
| }); | ||
|
|
||
| test("falls back to simctl launch when pressHome exceeds the timeout", async () => { | ||
| const { rpc, calls } = handler({ | ||
| pressHomeTimeoutMs: 30, | ||
| pressHome: () => new Promise<boolean>(() => {}), | ||
| }); | ||
| const t0 = performance.now(); | ||
| expect(await rpc({ method: "home", params: { udid: UDID } })).toMatchObject({ exitCode: 0 }); | ||
| expect(performance.now() - t0).toBeLessThan(400); | ||
| expect(calls).toEqual([["xcrun", ["simctl", "launch", UDID, "com.apple.springboard"]]]); | ||
| }); | ||
|
|
||
| test("aborts a timed-out pressHome so a late native press cannot still fire", async () => { | ||
| let seen: AbortSignal | undefined; | ||
| const { rpc, calls } = handler({ | ||
| pressHomeTimeoutMs: 30, | ||
| pressHome: (_udid: string, signal?: AbortSignal) => { | ||
| seen = signal; | ||
| return new Promise<boolean>(() => {}); | ||
| }, | ||
| }); | ||
| expect(await rpc({ method: "home", params: { udid: UDID } })).toMatchObject({ exitCode: 0 }); | ||
| expect(seen?.aborted).toBe(true); | ||
| expect(calls).toEqual([["xcrun", ["simctl", "launch", UDID, "com.apple.springboard"]]]); | ||
| }); | ||
|
|
||
| test("without pressHome, launches SpringBoard via simctl (legacy path)", async () => { | ||
| const { rpc, calls } = handler(); | ||
| expect(await rpc({ method: "home", params: { udid: UDID } })).toMatchObject({ exitCode: 0 }); | ||
| expect(calls).toEqual([["xcrun", ["simctl", "launch", UDID, "com.apple.springboard"]]]); | ||
| }); | ||
|
|
||
| test("watch home still uses the Simulator.app menu, not pressHome or simctl", async () => { | ||
| let pressed = 0; | ||
| const { rpc, calls } = handler({ | ||
| pressHome: async () => { | ||
| pressed += 1; | ||
| return true; | ||
| }, | ||
| }); | ||
| const result = await rpc({ method: "home", params: { udid: UDID, watch: true } }); | ||
| expect(result.exitCode).toBe(0); | ||
| expect(calls[0]?.[0]).toBe("osascript"); | ||
| expect(calls[0]?.[1].join(" ")).toContain('menu item "Home"'); | ||
| expect(pressed).toBe(0); | ||
| }); | ||
|
|
||
| test("rejects a device that isn't booted", async () => { | ||
| const { rpc, calls } = handler({ known: false, pressHome: async () => true }); | ||
| await expect(rpc({ method: "home", params: { udid: UDID } })).rejects.toThrow( | ||
| "unknown or not booted device", | ||
| ); | ||
| expect(calls).toEqual([]); | ||
| }); | ||
|
|
||
| test("DEFAULT_PRESS_HOME_TIMEOUT_MS is a short bound, not the 10s/30s launcher waits", () => { | ||
| expect(DEFAULT_PRESS_HOME_TIMEOUT_MS).toBe(2_000); | ||
| expect(DEFAULT_PRESS_HOME_TIMEOUT_MS).toBeLessThan(10_000); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Propagate the SpringBoard launch outcome.
If both launch attempts fail, this method still returns
true. The new consumer inpackages/serve-sim/src/host-rpc.tsLine 293 treats that value as success and returnsexitCode: 0.For example, a device shutdown after
requireDevicecan make the launch fail while the toolbar receives success. Return the launch outcome throughSpringBoardLauncher,launchSpringBoard, and this method. Do not report success merely because the attempt finished.