Target the Suno browser for field filling

This commit is contained in:
diyaa
2026-09-14 22:35:12 +02:00
parent 3fced12bef
commit 52978a375d
@@ -14,7 +14,7 @@ struct MacOSSunoAccessibilityFieldFiller: SunoFieldFilling {
try? await Task.sleep(for: .seconds(2)) try? await Task.sleep(for: .seconds(2))
guard let application = NSWorkspace.shared.frontmostApplication else { guard let application = sunoBrowserApplication() else {
return .copyRequired(for: SunoHandoffField.allCases, reason: "The Suno browser window was not found.") return .copyRequired(for: SunoHandoffField.allCases, reason: "The Suno browser window was not found.")
} }
@@ -78,6 +78,16 @@ struct MacOSSunoAccessibilityFieldFiller: SunoFieldFilling {
descendants(of: AXUIElementCreateApplication(processIdentifier)) descendants(of: AXUIElementCreateApplication(processIdentifier))
} }
private func sunoBrowserApplication() -> NSRunningApplication? {
guard let applicationURL = NSWorkspace.shared.urlForApplication(toOpen: SunoHandoffDestination.createPageURL),
let bundleIdentifier = Bundle(url: applicationURL)?.bundleIdentifier else {
return NSWorkspace.shared.frontmostApplication
}
return NSRunningApplication.runningApplications(withBundleIdentifier: bundleIdentifier).first
?? NSWorkspace.shared.frontmostApplication
}
private func descendants(of root: AXUIElement) -> [AXUIElement] { private func descendants(of root: AXUIElement) -> [AXUIElement] {
var elements: [AXUIElement] = [] var elements: [AXUIElement] = []
var pending = [root] var pending = [root]
@@ -99,7 +109,7 @@ struct MacOSSunoAccessibilityFieldFiller: SunoFieldFilling {
} }
private func labels(for element: AXUIElement) -> [String] { private func labels(for element: AXUIElement) -> [String] {
[kAXTitleAttribute, kAXDescriptionAttribute, kAXHelpAttribute, kAXIdentifierAttribute] [kAXTitleAttribute, kAXDescriptionAttribute, kAXHelpAttribute, kAXIdentifierAttribute, kAXPlaceholderValueAttribute]
.compactMap { attribute($0, from: element) as? String } .compactMap { attribute($0, from: element) as? String }
} }