1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-03 13:33:32 +01:00

get proper tab index on makeSenderTabObject

This commit is contained in:
Kyle Spearrin 2019-09-04 11:55:57 -04:00
parent c99403255d
commit b912470e69

View File

@ -13,7 +13,9 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
page.getPropertiesWithCompletionHandler { properties in
DispatchQueue.main.async {
makeSenderTabObject(page: page, props: properties, complete: { senderTab in
self.sendMessage(msg: userInfo, sender: senderTab)
DispatchQueue.main.async {
self.sendMessage(msg: userInfo, sender: senderTab)
}
})
}
}
@ -72,15 +74,8 @@ func makeSenderTabObject(page: SFSafariPage, props: SFSafariPageProperties?, com
t.active = activeTab != nil && tab == activeTab
SFSafariApplication.getAllWindows(completionHandler: { allWins in
t.windowId = allWins.firstIndex(of: win!) ?? -100
let winGroup = DispatchGroup()
for allWin in allWins {
winGroup.enter()
allWin.getAllTabs { allWinTabs in
t.index = allWinTabs.firstIndex(of: tab) ?? -1
winGroup.leave()
}
}
winGroup.notify(queue: .main) {
win!.getAllTabs { allWinTabs in
t.index = allWinTabs.firstIndex(of: tab) ?? -1
t.id = "\(t.windowId)_\(t.index)"
complete(t)
}