Repository navigation
fix(desktop): skip auxiliary macOS snapshot windows #22624
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
Open
YoruSamaOG
wants to merge
1
commit into
pingdotgg:main
Choose a base branch
from
YoruSamaOG:fix/macos-snapshot-auxiliary-windows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+223
−24
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| import { assert, beforeEach, it, vi } from "vite-plus/test"; | ||
|
|
||
| const { execFileMock } = vi.hoisted(() => ({ execFileMock: vi.fn() })); | ||
|
|
||
| vi.mock("node:child_process", () => ({ execFile: execFileMock })); | ||
|
|
||
| import { activeWindow } from "./ActiveWindow.ts"; | ||
|
|
||
| beforeEach(() => { | ||
| execFileMock.mockReset(); | ||
| }); | ||
|
|
||
| function stubMacLookup(stdout: string) { | ||
| execFileMock.mockImplementation( | ||
| ( | ||
| _file: string, | ||
| _args: ReadonlyArray<string>, | ||
| _options: unknown, | ||
| callback: (error: Error | null, stdout: string) => void, | ||
| ) => callback(null, stdout), | ||
| ); | ||
| } | ||
|
|
||
| function macLookup( | ||
| windows: ReadonlyArray<{ | ||
| id: number; | ||
| title: string; | ||
| bounds: { x: number; y: number; width: number; height: number }; | ||
| alpha?: number; | ||
| }>, | ||
| ) { | ||
| return JSON.stringify({ | ||
| owner: { | ||
| name: "Editor", | ||
| processId: 123, | ||
| path: "/Applications/Editor.app", | ||
| bundleId: "com.example.editor", | ||
| }, | ||
| windows: windows.map((window) => ({ ...window, alpha: window.alpha ?? 1 })), | ||
| }); | ||
| } | ||
|
|
||
| it("parses the frontmost macOS window from the osascript lookup", async () => { | ||
| stubMacLookup( | ||
| macLookup([ | ||
| { | ||
| id: 42, | ||
| title: "main.ts", | ||
| bounds: { x: 10, y: 20, width: 800, height: 600 }, | ||
| }, | ||
| ]) + "\n", | ||
| ); | ||
|
|
||
| const window = await activeWindow("darwin"); | ||
|
|
||
| assert.deepEqual(window, { | ||
| platform: "macos", | ||
| id: 42, | ||
| title: "main.ts", | ||
| bounds: { x: 10, y: 20, width: 800, height: 600 }, | ||
| owner: { | ||
| name: "Editor", | ||
| processId: 123, | ||
| path: "/Applications/Editor.app", | ||
| bundleId: "com.example.editor", | ||
| }, | ||
| }); | ||
| const [file, args] = execFileMock.mock.calls[0]!; | ||
| assert.strictEqual(file, "/usr/bin/osascript"); | ||
| assert.deepEqual(args.slice(0, 3), ["-l", "JavaScript", "-e"]); | ||
| }); | ||
|
|
||
| it.each([ | ||
| { | ||
| name: "transparent and untitled helpers", | ||
| helpers: [ | ||
| { | ||
| id: 1, | ||
| title: "", | ||
| bounds: { x: -1, y: -44, width: 1_680, height: 44 }, | ||
| alpha: 0, | ||
| }, | ||
| { id: 2, title: "", bounds: { x: 0, y: 0, width: 1_680, height: 68 } }, | ||
| ], | ||
| content: { | ||
| id: 3, | ||
| title: "Document", | ||
| bounds: { x: 0, y: 0, width: 1_680, height: 1_050 }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "Chrome strips stacked above the content window", | ||
| helpers: [ | ||
| { id: 75, title: "", bounds: { x: 0, y: 39, width: 1_800, height: 41 } }, | ||
| { id: 74, title: "", bounds: { x: 0, y: 80, width: 1_800, height: 81 } }, | ||
| { id: 1691, title: "", bounds: { x: 0, y: 39, width: 1_800, height: 158 } }, | ||
| ], | ||
| content: { | ||
| id: 71, | ||
| title: "(10) Video - YouTube", | ||
| bounds: { x: 0, y: 161, width: 1_800, height: 1_008 }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "a smaller front window's strips with a larger background window", | ||
| helpers: [ | ||
| { id: 75, title: "", bounds: { x: 100, y: 139, width: 1_200, height: 41 } }, | ||
| { id: 74, title: "", bounds: { x: 100, y: 180, width: 1_200, height: 81 } }, | ||
| ], | ||
| content: { | ||
| id: 71, | ||
| title: "Video - YouTube", | ||
| bounds: { x: 100, y: 261, width: 1_200, height: 700 }, | ||
| }, | ||
| background: [ | ||
| { id: 80, title: "Other document", bounds: { x: 0, y: 39, width: 1_800, height: 1_130 } }, | ||
| ], | ||
| }, | ||
| ])("selects the content window behind $name", async ({ helpers, content, background = [] }) => { | ||
| stubMacLookup(macLookup([...helpers, content, ...background])); | ||
|
|
||
| const window = await activeWindow("darwin"); | ||
|
|
||
| assert.strictEqual(window?.id, content.id); | ||
| assert.deepEqual(window?.bounds, content.bounds); | ||
| }); | ||
|
|
||
| it.each([ | ||
| { name: "untitled dialog", title: "", bounds: { x: 300, y: 200, width: 400, height: 240 } }, | ||
| { name: "titled palette", title: "Palette", bounds: { x: 0, y: 0, width: 800, height: 50 } }, | ||
| { name: "offset untitled strip", title: "", bounds: { x: 100, y: 100, width: 800, height: 50 } }, | ||
| { name: "tall untitled window", title: "", bounds: { x: 0, y: 0, width: 800, height: 900 } }, | ||
| ])("keeps a frontmost $name ahead of a larger document", async ({ title, bounds }) => { | ||
| stubMacLookup( | ||
| macLookup([ | ||
| { id: 1, title, bounds }, | ||
| { id: 2, title: "Document", bounds: { x: 0, y: 0, width: 800, height: 1_000 } }, | ||
| ]), | ||
| ); | ||
|
|
||
| const window = await activeWindow("darwin"); | ||
|
|
||
| assert.strictEqual(window?.id, 1); | ||
| assert.deepEqual(window?.bounds, bounds); | ||
| }); | ||
|
|
||
| it("keeps an untitled content window ahead of a much taller background window", async () => { | ||
| const bounds = { x: 0, y: 0, width: 800, height: 900 }; | ||
| stubMacLookup( | ||
| macLookup([ | ||
| { id: 1, title: "", bounds }, | ||
| { id: 2, title: "Background document", bounds: { x: 0, y: 0, width: 800, height: 4_000 } }, | ||
| ]), | ||
| ); | ||
|
|
||
| const window = await activeWindow("darwin"); | ||
|
|
||
| assert.strictEqual(window?.id, 1); | ||
| assert.deepEqual(window?.bounds, bounds); | ||
| }); |
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
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '100,160p' apps/desktop/src/snapShot/ActiveWindow.tsRepository: pingdotgg/t3code
Length of output: 2426
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 40696
Require orthogonal positioning before skipping an untitled window.
The predicate matches any later window with the same
x/widthory/height. It does not check the other axis. Therefore, a frontmost untitled800×50window at(0, 600)can be skipped in favor of a later800×1000window at(0, 0). Apply an orthogonal-position check to both strip branches.The existing offset test changes
x, so it does not cover a same-xhorizontal strip at a differenty.🤖 Prompt for AI Agents