Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Sources/AppBundle/command/impl/DebugWindowsCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ private func dumpWindowDebugInfo(_ window: Window) async throws -> String {

result["Aero.AXApp"] = .dict(try await window.macApp.dumpAppAxInfo())
// todo add app bundle version to debug log


var matchingCallbacks: [Json] = []
for callback in config.onWindowDetected where try await callback.matches(window) {
matchingCallbacks.append(callback.debugInfo)
}
result["Aero.on-window-detected"] = .array(matchingCallbacks)

return (JSONEncoder.aeroSpaceDefault.encodeToString(result) ?? "nil").prefixLines(with: "\(window.app.bundleId ?? "nil-bundle-id") ||| ")
}

Expand Down
33 changes: 33 additions & 0 deletions Sources/AppBundle/config/parseOnWindowDetected.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ struct WindowDetectedCallback: ConvenienceCopyable, Equatable {
rawRun ?? dieT("ID-46D063B2 should have discarded nil")
}

var debugInfo: Json {
var result: [String: Json] = [:]
result["matcher"] = matcher.debugInfo
if let commands = rawRun {
let commandsJson: [Json] = commands.map { command in
let args = command.args.rawArgs.value.joined(separator: ",")
return .string("\(command.info.kind.rawValue) \(args)")
}
result["commands"] = .array(commandsJson)
}
return .dict(result)
}

static func == (lhs: WindowDetectedCallback, rhs: WindowDetectedCallback) -> Bool {
return lhs.matcher == rhs.matcher && lhs.checkFurtherCallbacks == rhs.checkFurtherCallbacks &&
zip(lhs.run, rhs.run).allSatisfy { $0.equals($1) }
Expand All @@ -23,6 +36,26 @@ struct WindowDetectedCallbackMatcher: ConvenienceCopyable, Equatable {
var workspace: String?
var duringAeroSpaceStartup: Bool?

var debugInfo: Json {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet another maintenance task: it's probably worth converting this struct to enum

var resultParts: [String] = []
if let appId = appId {
resultParts.append("appId=\"\(appId)\"")
}
if appNameRegexSubstring != nil {
resultParts.append("appNameRegexSubstrin=Regex")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no way to get the actual regex string from the Regex. So, I just hardcode "Regex" in here and for windowTitleRegexSubstring. It's maybe enough just to know that there was a regex that matched. If we want to actually have the regex string we could save it when parsing the config.

}
if windowTitleRegexSubstring != nil {
resultParts.append("windowTitleRegexSubstring=Regex")
}
if let workspace = workspace {
resultParts.append("workspace=\"\(workspace)\"")
}
if let duringAeroSpaceStartup = duringAeroSpaceStartup {
resultParts.append("duringAeroSpaceStartup=\(duringAeroSpaceStartup)")
}
return .string(resultParts.joined(separator: ", "))
}

static func == (lhs: WindowDetectedCallbackMatcher, rhs: WindowDetectedCallbackMatcher) -> Bool {
check(
lhs.appNameRegexSubstring == nil &&
Expand Down
Loading