From 8bf6609c23ece1bce4f93a1a3617611cc9d3713a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 16 Aug 2019 11:46:24 -0400 Subject: [PATCH] tab query fixes --- src/browser/browserApi.ts | 2 +- .../safari/SafariExtensionViewController.swift | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/browser/browserApi.ts b/src/browser/browserApi.ts index 3d459cfa6e..39b669c38c 100644 --- a/src/browser/browserApi.ts +++ b/src/browser/browserApi.ts @@ -41,7 +41,7 @@ export class BrowserApi { }); } else if (BrowserApi.isSafariApi) { const tabs = await SafariApp.sendMessageToApp('tabs_query', JSON.stringify(options)); - return tabs; + return tabs != null ? JSON.parse(tabs) : null; // TODO /* if (options.currentWindow) { diff --git a/src/safari/app/desktop/safari/SafariExtensionViewController.swift b/src/safari/app/desktop/safari/SafariExtensionViewController.swift index c491ca46bb..b408ae29e9 100644 --- a/src/safari/app/desktop/safari/SafariExtensionViewController.swift +++ b/src/safari/app/desktop/safari/SafariExtensionViewController.swift @@ -90,7 +90,7 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe SFSafariApplication.getActiveWindow { (win) in processWindowsForTabs(wins: [win!], options: options , complete: { (tabs) in - m!.data = jsonSerialize(obj: tabs) + m!.responseData = jsonSerialize(obj: tabs) self.replyMessage(message: m!) }) } @@ -98,7 +98,7 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe SFSafariApplication.getAllWindows { (wins) in processWindowsForTabs(wins: wins, options: options , complete: { (tabs) in - m!.data = jsonSerialize(obj: tabs) + m!.responseData = jsonSerialize(obj: tabs) self.replyMessage(message: m!) }) } @@ -133,7 +133,7 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe } } -func processWindowsForTabs(wins: [SFSafariWindow], options: TabQueryOptions?, complete: ([Tab]) -> Void) { +func processWindowsForTabs(wins: [SFSafariWindow], options: TabQueryOptions?, complete: @escaping ([Tab]) -> Void) { if(wins.count == 0) { complete([]) return @@ -155,6 +155,8 @@ func processWindowsForTabs(wins: [SFSafariWindow], options: TabQueryOptions?, co newTabs.append(t) tabGroup.leave() }) + } else { + tabGroup.leave() } } else { makeTabObject(tab: tab, activeTab: activeTab, windowIndex: windowIndex, tabIndex: tabIndex, complete: { (t) in @@ -164,14 +166,16 @@ func processWindowsForTabs(wins: [SFSafariWindow], options: TabQueryOptions?, co } tabIndex = tabIndex + 1 } - tabGroup.wait() - winGroup.leave() + tabGroup.notify(queue: .main){ + winGroup.leave() + } } } windowIndex = windowIndex + 1 } - winGroup.wait() - complete(newTabs) + winGroup.notify(queue: .main){ + complete(newTabs) + } } func makeTabObject(tab: SFSafariTab, activeTab: SFSafariTab?, windowIndex: Int, tabIndex: Int, complete: @escaping (Tab) -> Void) {