mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-15 20:12:59 -07:00
fix(macos): validate PID and socket before reporting window as minimized
- Move PID extraction and app PID match before minimized check in windowStateFromAccessibilityAPI - Add test asserting correct validation order in get-mpv-window-macos.swift - Include new test in test:fast suite
This commit is contained in:
@@ -174,22 +174,26 @@ private func windowStateFromAccessibilityAPI() -> WindowLookupResult? {
|
||||
}
|
||||
|
||||
for window in windows {
|
||||
var minimizedRef: CFTypeRef?
|
||||
let minimizedStatus = AXUIElementCopyAttributeValue(window, kAXMinimizedAttribute as CFString, &minimizedRef)
|
||||
if minimizedStatus == .success, let minimized = minimizedRef as? Bool, minimized {
|
||||
foundMinimizedTargetWindow = true
|
||||
continue
|
||||
}
|
||||
|
||||
var windowPid: pid_t = 0
|
||||
if AXUIElementGetPid(window, &windowPid) != .success {
|
||||
continue
|
||||
}
|
||||
|
||||
if windowPid != app.processIdentifier {
|
||||
continue
|
||||
}
|
||||
|
||||
if !windowHasTargetSocket(windowPid) {
|
||||
continue
|
||||
}
|
||||
|
||||
var minimizedRef: CFTypeRef?
|
||||
let minimizedStatus = AXUIElementCopyAttributeValue(window, kAXMinimizedAttribute as CFString, &minimizedRef)
|
||||
if minimizedStatus == .success, let minimized = minimizedRef as? Bool, minimized {
|
||||
foundMinimizedTargetWindow = true
|
||||
continue
|
||||
}
|
||||
|
||||
if let geometry = geometryFromAXWindow(window) {
|
||||
return .visible(
|
||||
WindowState(
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import test from 'node:test';
|
||||
|
||||
const source = readFileSync('scripts/get-mpv-window-macos.swift', 'utf8');
|
||||
|
||||
test('minimized Accessibility windows are validated by PID and socket before reporting minimized', () => {
|
||||
const minimizedAssignmentIndex = source.indexOf('foundMinimizedTargetWindow = true');
|
||||
assert.notEqual(minimizedAssignmentIndex, -1);
|
||||
|
||||
const loopStartIndex = source.lastIndexOf('for window in windows', minimizedAssignmentIndex);
|
||||
assert.notEqual(loopStartIndex, -1);
|
||||
|
||||
const pidExtractionIndex = source.indexOf(
|
||||
'AXUIElementGetPid(window, &windowPid)',
|
||||
loopStartIndex,
|
||||
);
|
||||
const appPidMatchIndex = source.indexOf('windowPid != app.processIdentifier', loopStartIndex);
|
||||
const socketCheckIndex = source.indexOf('if !windowHasTargetSocket(windowPid)', loopStartIndex);
|
||||
|
||||
assert.ok(
|
||||
pidExtractionIndex > loopStartIndex && pidExtractionIndex < minimizedAssignmentIndex,
|
||||
'window PID must be extracted before accepting a minimized window',
|
||||
);
|
||||
assert.ok(
|
||||
appPidMatchIndex > pidExtractionIndex && appPidMatchIndex < minimizedAssignmentIndex,
|
||||
'window PID must match the owning app before accepting a minimized window',
|
||||
);
|
||||
assert.ok(
|
||||
socketCheckIndex > appPidMatchIndex && socketCheckIndex < minimizedAssignmentIndex,
|
||||
'target socket must be validated before accepting a minimized window',
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user