Target the Suno browser for field filling
This commit is contained in:
@@ -14,7 +14,7 @@ struct MacOSSunoAccessibilityFieldFiller: SunoFieldFilling {
|
||||
|
||||
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.")
|
||||
}
|
||||
|
||||
@@ -78,6 +78,16 @@ struct MacOSSunoAccessibilityFieldFiller: SunoFieldFilling {
|
||||
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] {
|
||||
var elements: [AXUIElement] = []
|
||||
var pending = [root]
|
||||
@@ -99,7 +109,7 @@ struct MacOSSunoAccessibilityFieldFiller: SunoFieldFilling {
|
||||
}
|
||||
|
||||
private func labels(for element: AXUIElement) -> [String] {
|
||||
[kAXTitleAttribute, kAXDescriptionAttribute, kAXHelpAttribute, kAXIdentifierAttribute]
|
||||
[kAXTitleAttribute, kAXDescriptionAttribute, kAXHelpAttribute, kAXIdentifierAttribute, kAXPlaceholderValueAttribute]
|
||||
.compactMap { attribute($0, from: element) as? String }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user