Skip to content
Merged
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
26 changes: 22 additions & 4 deletions aw_watcher_window/macos.swift
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,20 @@ class MainThing {
if CHROME_BROWSERS.contains(applicationName) {
debug("Chrome browser detected, extracting URL and title")

guard let bundleIdentifier = frontmost.bundleIdentifier else {
guard frontmost.bundleIdentifier != nil else {
log("Failed to get bundle identifier from frontmost application, which was recognized to be Chrome")
return
}
let chromeObject: ChromeProtocol = SBApplication.init(bundleIdentifier: bundleIdentifier)!
// Address the running process by PID and bail if it already quit: a
// bundle-identifier target makes ScriptingBridge relaunch a browser that just quit.
guard !frontmost.isTerminated else {
log("Chrome is no longer running, skipping scripting request")
return
}
guard let chromeObject = SBApplication.init(processIdentifier: frontmost.processIdentifier) as? ChromeProtocol else {
log("Failed to create ScriptingBridge proxy for Chrome")
return
}

guard let windows = chromeObject.windows,
let frontWindow = windows().first else {
Expand Down Expand Up @@ -638,11 +647,20 @@ class MainThing {
} else if frontmost.localizedName == "Safari" {
debug("Safari browser detected, extracting URL and title")

guard let bundleIdentifier = frontmost.bundleIdentifier else {
guard frontmost.bundleIdentifier != nil else {
log("Failed to get bundle identifier from frontmost application, which was recognized to be Safari")
return
}
let safariObject: SafariApplication = SBApplication.init(bundleIdentifier: bundleIdentifier)!
// Address the running process by PID and bail if it already quit: a
// bundle-identifier target makes ScriptingBridge relaunch a browser that just quit.
guard !frontmost.isTerminated else {
log("Safari is no longer running, skipping scripting request")
return
}
guard let safariObject = SBApplication.init(processIdentifier: frontmost.processIdentifier) as? SafariApplication else {
log("Failed to create ScriptingBridge proxy for Safari")
return
}

guard let windows = safariObject.windows,
let frontWindow = windows().first else {
Expand Down
Loading