Skip to content

Commit 5fd0286

Browse files
hieberrnikitabobko
authored andcommitted
Add matching on-window-detected info to debug-windows command
closes #1326 closes #1340
1 parent c7a5910 commit 5fd0286

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

Sources/AppBundle/command/impl/ConfigCommand.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,18 @@ extension ConfigMapValue {
135135
}
136136
}
137137

138+
extension [Command] {
139+
var prettyDescription: String {
140+
map { $0.args.description }.joined(separator: "; ")
141+
}
142+
}
143+
138144
@MainActor func buildConfigMap() -> ConfigMapValue {
139145
let mode = config.modes.mapValues { (mode: Mode) -> ConfigMapValue in
140146
var keyNotationToScript: [String: ConfigMapValue] = [:]
141147
for binding in mode.bindings.values {
142148
keyNotationToScript[binding.descriptionWithKeyNotation] =
143-
.scalar(.string(binding.commands.map { $0.args.description }.joined(separator: "; ")))
149+
.scalar(.string(binding.commands.prettyDescription))
144150
}
145151
return .map(["binding": .map(keyNotationToScript)])
146152
}

Sources/AppBundle/command/impl/DebugWindowsCommand.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ private func dumpWindowDebugInfo(_ window: Window) async throws -> String {
8989
result["Aero.AXApp"] = .dict(try await window.macApp.dumpAppAxInfo())
9090
// todo add app bundle version to debug log
9191

92+
var matchingCallbacks: [Json] = []
93+
for callback in config.onWindowDetected where try await callback.matches(window) {
94+
matchingCallbacks.append(callback.debugJson)
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ struct WindowDetectedCallback: ConvenienceCopyable, Equatable {
1010
rawRun ?? dieT("ID-46D063B2 should have discarded nil")
1111
}
1212

13+
var debugJson: Json {
14+
var result: [String: Json] = [:]
15+
result["matcher"] = matcher.debugJson
16+
if let commands = rawRun {
17+
result["commands"] = .string(commands.prettyDescription)
18+
}
19+
return .dict(result)
20+
}
21+
1322
static func == (lhs: WindowDetectedCallback, rhs: WindowDetectedCallback) -> Bool {
1423
return lhs.matcher == rhs.matcher && lhs.checkFurtherCallbacks == rhs.checkFurtherCallbacks &&
1524
zip(lhs.run, rhs.run).allSatisfy { $0.equals($1) }
@@ -23,6 +32,26 @@ struct WindowDetectedCallbackMatcher: ConvenienceCopyable, Equatable {
2332
var workspace: String?
2433
var duringAeroSpaceStartup: Bool?
2534

35+
var debugJson: Json {
36+
var resultParts: [String] = []
37+
if let appId {
38+
resultParts.append("appId=\"\(appId)\"")
39+
}
40+
if appNameRegexSubstring != nil {
41+
resultParts.append("appNameRegexSubstrin=Regex")
42+
}
43+
if windowTitleRegexSubstring != nil {
44+
resultParts.append("windowTitleRegexSubstring=Regex")
45+
}
46+
if let workspace {
47+
resultParts.append("workspace=\"\(workspace)\"")
48+
}
49+
if let duringAeroSpaceStartup {
50+
resultParts.append("duringAeroSpaceStartup=\(duringAeroSpaceStartup)")
51+
}
52+
return .string(resultParts.joined(separator: ", "))
53+
}
54+
2655
static func == (lhs: WindowDetectedCallbackMatcher, rhs: WindowDetectedCallbackMatcher) -> Bool {
2756
check(
2857
lhs.appNameRegexSubstring == nil &&

0 commit comments

Comments
 (0)