1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-07 09:31:31 +01:00

tab query fixes

This commit is contained in:
Kyle Spearrin 2019-08-16 11:46:24 -04:00
parent d90279a596
commit 8bf6609c23
2 changed files with 12 additions and 8 deletions

View File

@ -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) {

View File

@ -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()
tabGroup.notify(queue: .main){
winGroup.leave()
}
}
}
windowIndex = windowIndex + 1
}
winGroup.wait()
winGroup.notify(queue: .main){
complete(newTabs)
}
}
func makeTabObject(tab: SFSafariTab, activeTab: SFSafariTab?, windowIndex: Int, tabIndex: Int, complete: @escaping (Tab) -> Void) {