Skip to content

Add on-window-detected info to debug-windows command resolves #1326#1340

Closed
hieberr wants to merge 2 commits intonikitabobko:mainfrom
hieberr:fp_log-on-window-detected
Closed

Add on-window-detected info to debug-windows command resolves #1326#1340
hieberr wants to merge 2 commits intonikitabobko:mainfrom
hieberr:fp_log-on-window-detected

Conversation

@hieberr
Copy link
Copy Markdown
Contributor

@hieberr hieberr commented Apr 24, 2025

Adds matching on-window-detected debug info to the debug-windows command.

I wasn't sure what info you wanted so I included everything. Also, I'm happy to change formatting if you would like something different.

Example Output:

Typical/simple case

owd-simple

Full case

owd-full
"Aero.on-window-detected" : [
  {
    "commands" : [
      "layout floating",
      "move-node-to-workspace M"
    ],
    "matcher" : "appId=\"com.splice.Splice\", appNameRegexSubstrin=Regex, windowTitleRegexSubstring=Regex, duringAeroSpaceStartup=false"
  }
],

resultParts.append("appId=\"\(appId)\"")
}
if let _ = appNameRegexSubstring {
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.

@hieberr hieberr changed the title Add on-window-detected info to debug-windows command #1326 Add on-window-detected info to debug-windows command resolves #1326 Apr 24, 2025
@nikitabobko
Copy link
Copy Markdown
Owner

lol, I didn't expect that somebody would jump into maintenance tasks, thanks

I've merged your commit with the following minor patch on top:

commit 6bb5aa68af0b28a2a2a7efb2cfd6090038ec0047
Author:     Nikita Bobko <git@bobko.xyz>
AuthorDate: Fri Apr 25 00:30:37 2025 +0200
Commit:     Nikita Bobko <git@bobko.xyz>
CommitDate: Fri Apr 25 00:30:37 2025 +0200

    fixup! Add matching on-window-detected info to debug-windows command

diff --git a/Sources/AppBundle/command/impl/ConfigCommand.swift b/Sources/AppBundle/command/impl/ConfigCommand.swift
index 58ba728c..118a9fbb 100644
--- a/Sources/AppBundle/command/impl/ConfigCommand.swift
+++ b/Sources/AppBundle/command/impl/ConfigCommand.swift
@@ -135,12 +135,18 @@ extension ConfigMapValue {
     }
 }
 
+extension [Command] {
+    var prettyDescription: String {
+        map { $0.args.description }.joined(separator: "; ")
+    }
+}
+
 @MainActor func buildConfigMap() -> ConfigMapValue {
     let mode = config.modes.mapValues { (mode: Mode) -> ConfigMapValue in
         var keyNotationToScript: [String: ConfigMapValue] = [:]
         for binding in mode.bindings.values {
             keyNotationToScript[binding.descriptionWithKeyNotation] =
-                .scalar(.string(binding.commands.map { $0.args.description }.joined(separator: "; ")))
+                .scalar(.string(binding.commands.prettyDescription))
         }
         return .map(["binding": .map(keyNotationToScript)])
     }
diff --git a/Sources/AppBundle/command/impl/DebugWindowsCommand.swift b/Sources/AppBundle/command/impl/DebugWindowsCommand.swift
index 6e42b0cf..d2250de8 100644
--- a/Sources/AppBundle/command/impl/DebugWindowsCommand.swift
+++ b/Sources/AppBundle/command/impl/DebugWindowsCommand.swift
@@ -91,7 +91,7 @@ private func dumpWindowDebugInfo(_ window: Window) async throws -> String {
 
     var matchingCallbacks: [Json] = []
     for callback in config.onWindowDetected where try await callback.matches(window) {
-        matchingCallbacks.append(callback.debugInfo)
+        matchingCallbacks.append(callback.debugJson)
     }
     result["Aero.on-window-detected"] = .array(matchingCallbacks)
 
diff --git a/Sources/AppBundle/config/parseOnWindowDetected.swift b/Sources/AppBundle/config/parseOnWindowDetected.swift
index 421655ab..eccae241 100644
--- a/Sources/AppBundle/config/parseOnWindowDetected.swift
+++ b/Sources/AppBundle/config/parseOnWindowDetected.swift
@@ -10,15 +10,11 @@ struct WindowDetectedCallback: ConvenienceCopyable, Equatable {
         rawRun ?? dieT("ID-46D063B2 should have discarded nil")
     }
 
-    var debugInfo: Json {
+    var debugJson: 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)
+            result["commands"] = .string(commands.prettyDescription)
         }
         return .dict(result)
     }

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

@nikitabobko nikitabobko added the pr-merged Pull Request is merged label Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-merged Pull Request is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants