From b912470e6940c6b3341c1218ba7d1f2ffd5f6d6e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 4 Sep 2019 11:55:57 -0400 Subject: [PATCH] get proper tab index on makeSenderTabObject --- src/safari/safari/SafariExtensionHandler.swift | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/safari/safari/SafariExtensionHandler.swift b/src/safari/safari/SafariExtensionHandler.swift index bc6ff2e8af..fe37ac4276 100644 --- a/src/safari/safari/SafariExtensionHandler.swift +++ b/src/safari/safari/SafariExtensionHandler.swift @@ -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) }