Skip to content

Commit d6135c1

Browse files
committed
Add matching on-window-detected info to debug-windows command
1 parent c7a5910 commit d6135c1

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

Sources/AppBundle/command/impl/DebugWindowsCommand.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ private func dumpWindowDebugInfo(_ window: Window) async throws -> String {
8888

8989
result["Aero.AXApp"] = .dict(try await window.macApp.dumpAppAxInfo())
9090
// todo add app bundle version to debug log
91-
91+
92+
var matchingCallbacks: [Json] = []
93+
for callback in config.onWindowDetected where try await callback.matches(window) {
94+
matchingCallbacks.append(callback.debugInfo)
95+
}
96+
result["Aero.on-window-detected"] = .array(matchingCallbacks)
97+
9298
return (JSONEncoder.aeroSpaceDefault.encodeToString(result) ?? "nil").prefixLines(with: "\(window.app.bundleId ?? "nil-bundle-id") ||| ")
9399
}
94100

Sources/AppBundle/config/parseOnWindowDetected.swift

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ struct WindowDetectedCallback: ConvenienceCopyable, Equatable {
1010
rawRun ?? dieT("ID-46D063B2 should have discarded nil")
1111
}
1212

13+
var debugInfo: Json {
14+
var result: [String: Json] = [:]
15+
result ["matcher"] = matcher.debugInfo
16+
if let commands = rawRun {
17+
let commandsJson: [Json] = commands.map { command in
18+
let args = command.args.rawArgs.value.joined(separator: ",")
19+
return .string("\(command.info.kind.rawValue) \(args)")
20+
}
21+
result["commands"] = .array(commandsJson)
22+
}
23+
return .dict(result)
24+
}
25+
1326
static func == (lhs: WindowDetectedCallback, rhs: WindowDetectedCallback) -> Bool {
1427
return lhs.matcher == rhs.matcher && lhs.checkFurtherCallbacks == rhs.checkFurtherCallbacks &&
1528
zip(lhs.run, rhs.run).allSatisfy { $0.equals($1) }
@@ -22,7 +35,27 @@ struct WindowDetectedCallbackMatcher: ConvenienceCopyable, Equatable {
2235
var windowTitleRegexSubstring: Regex<AnyRegexOutput>?
2336
var workspace: String?
2437
var duringAeroSpaceStartup: Bool?
25-
38+
39+
var debugInfo: Json {
40+
var resultParts: [String] = []
41+
if let appId = appId {
42+
resultParts.append("appId=\"\(appId)\"")
43+
}
44+
if let _ = appNameRegexSubstring {
45+
resultParts.append("appNameRegexSubstrin=Regex")
46+
}
47+
if let _ = windowTitleRegexSubstring {
48+
resultParts.append("windowTitleRegexSubstring=Regex")
49+
}
50+
if let workspace = workspace {
51+
resultParts.append("workspace=\"\(workspace)\"")
52+
}
53+
if let duringAeroSpaceStartup = duringAeroSpaceStartup {
54+
resultParts.append("duringAeroSpaceStartup=\(duringAeroSpaceStartup)")
55+
}
56+
return .string(resultParts.joined(separator: ", "))
57+
}
58+
2659
static func == (lhs: WindowDetectedCallbackMatcher, rhs: WindowDetectedCallbackMatcher) -> Bool {
2760
check(
2861
lhs.appNameRegexSubstring == nil &&

0 commit comments

Comments
 (0)