Potential fix for swift nil unwrap exception

This commit is contained in:
Chad Scharf 2020-05-20 10:01:58 -04:00
parent 9f024828f2
commit e12cce711c
1 changed files with 19 additions and 8 deletions

View File

@ -101,10 +101,19 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
let options: TabQueryOptions? = jsonDeserialize(json: m!.data)
if options?.currentWindow ?? false {
SFSafariApplication.getActiveWindow { win in
if win != nil {
processWindowsForTabs(wins: [win!], options: options, complete: { tabs in
m!.responseData = jsonSerialize(obj: tabs)
self.replyMessage(message: m!)
})
} else {
SFSafariApplication.getAllWindows { wins in
processWindowsForTabs(wins: wins, options: options, complete: { tabs in
m!.responseData = jsonSerialize(obj: tabs)
self.replyMessage(message: m!)
})
}
}
}
} else {
SFSafariApplication.getAllWindows { wins in
@ -145,11 +154,13 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
dismissPopover()
replyMessage(message: m!)
} else if command == "showPopover" {
if popoverOpenCount <= 0 {
SFSafariApplication.getActiveWindow { win in
win?.getToolbarItem(completionHandler: { item in
item?.showPopover()
})
}
}
} else if command == "isPopoverOpen" {
m!.responseData = popoverOpenCount > 0 ? "true" : "false"
replyMessage(message: m!)