67 lines
2.7 KiB
JavaScript
67 lines
2.7 KiB
JavaScript
const assert = require('node:assert/strict')
|
|
const fs = require('node:fs')
|
|
const vm = require('node:vm')
|
|
|
|
const source = fs.readFileSync(process.argv[2], 'utf8')
|
|
const display = { origin: { x: 0, y: 0 }, size: { width: 2336, height: 1320 } }
|
|
const desktop = { X: 0, Y: 0, Width: 2336, Height: 1320 }
|
|
const appWindow = {
|
|
kCGWindowOwnerPID: 42,
|
|
kCGWindowNumber: 7,
|
|
kCGWindowLayer: 0,
|
|
kCGWindowAlpha: 1,
|
|
kCGWindowBounds: { X: 129, Y: 220, Width: 877, Height: 499 },
|
|
}
|
|
const dockBackdrop = {
|
|
kCGWindowOwnerPID: 43,
|
|
kCGWindowLayer: 20,
|
|
kCGWindowAlpha: 1,
|
|
kCGWindowBounds: desktop,
|
|
}
|
|
|
|
function report({ screens = '1', above = [], bundleId = 'com.apple.dock' } = {}) {
|
|
const frontmostApplication = {
|
|
isNil: () => false,
|
|
activationPolicy: '0',
|
|
processIdentifier: 42,
|
|
localizedName: { isNil: () => false, js: 'Terminal' },
|
|
}
|
|
const native = {
|
|
NSScreen: { screens: { count: screens } },
|
|
NSWorkspace: { sharedWorkspace: { frontmostApplication } },
|
|
NSApplicationActivationPolicyRegular: 0,
|
|
NSRunningApplication: {
|
|
runningApplicationWithProcessIdentifier: () => ({
|
|
isNil: () => false,
|
|
bundleIdentifier: { isNil: () => false, js: bundleId },
|
|
}),
|
|
},
|
|
kCGDockWindowLevelKey: 7,
|
|
CGWindowLevelForKey: () => 20,
|
|
CGMainDisplayID: () => 1,
|
|
CGDisplayBounds: () => display,
|
|
CGWindowListCopyWindowInfo: () => [...above, appWindow],
|
|
CFRelease: () => assert.fail('release of a JXA-managed reference'),
|
|
}
|
|
const bridge = {
|
|
import() {},
|
|
castRefToObject: value => value,
|
|
deepUnwrap: value => value,
|
|
}
|
|
return JSON.parse(vm.runInNewContext(source + '\nJSON.stringify(activeWindow())', { $: native, ObjC: bridge }))
|
|
}
|
|
|
|
const expected = {
|
|
id: 7, app_name: 'Terminal', x: 129, y: 220, width: 877, height: 499,
|
|
display_width: 2336, display_height: 1320,
|
|
}
|
|
assert.deepEqual(report({ above: [dockBackdrop] }), expected, 'Tahoe Dock backdrop leaves the window visible')
|
|
assert.deepEqual(report({ screens: 1 }), expected, 'numeric screen counts remain supported')
|
|
assert.equal(report({ screens: '2' }), null, 'multiple displays remain unsupported')
|
|
assert.equal(report({ above: [dockBackdrop], bundleId: 'com.example.overlay' }), null,
|
|
'other owners cannot cover the target at the Dock level')
|
|
assert.equal(report({ above: [{ ...dockBackdrop, kCGWindowBounds: appWindow.kCGWindowBounds }] }), null,
|
|
'overlapping Dock windows with their own bounds still block capture')
|
|
assert.equal(report({ above: [{ ...dockBackdrop, kCGWindowLayer: 0 }] }), null,
|
|
'a full-size window at another level still blocks capture')
|