From c4e66ce587647f68769f111619ef07b939e3249b Mon Sep 17 00:00:00 2001 From: Chad Scharf <3904944+cscharf@users.noreply.github.com> Date: Mon, 21 Sep 2020 12:53:51 -0400 Subject: [PATCH] Potential fix for pinned tab auto-fill in Safari --- .../safari/SafariExtensionHandler.swift | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/safari/safari/SafariExtensionHandler.swift b/src/safari/safari/SafariExtensionHandler.swift index fe37ac4276..3d8711f401 100644 --- a/src/safari/safari/SafariExtensionHandler.swift +++ b/src/safari/safari/SafariExtensionHandler.swift @@ -70,11 +70,26 @@ func makeSenderTabObject(page: SFSafariPage, props: SFSafariPageProperties?, com t.url = props?.url?.absoluteString page.getContainingTab { tab in tab.getContainingWindow(completionHandler: { win in - win?.getActiveTab(completionHandler: { activeTab in + guard let window = win else { + t.active = false; + t.windowId = -100 + SFSafariApplication.getAllWindows(completionHandler: { allWins in + if (allWins.count == 0) { + return + } + allWins[0].getAllTabs { allWinTabs in + t.index = allWinTabs.firstIndex(of: tab) ?? -1 + t.id = "\(t.windowId)_\(t.index)" + complete(t) + } + }) + return + } + window.getActiveTab(completionHandler: { activeTab in t.active = activeTab != nil && tab == activeTab SFSafariApplication.getAllWindows(completionHandler: { allWins in - t.windowId = allWins.firstIndex(of: win!) ?? -100 - win!.getAllTabs { allWinTabs in + t.windowId = allWins.firstIndex(of: window) ?? -100 + window.getAllTabs { allWinTabs in t.index = allWinTabs.firstIndex(of: tab) ?? -1 t.id = "\(t.windowId)_\(t.index)" complete(t)