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

show popup, reload extension, and formatting

This commit is contained in:
Kyle Spearrin 2019-08-19 20:45:06 -04:00
parent 2a7e361300
commit 41be76a107

View File

@ -50,15 +50,18 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
} }
func userContentController(_: WKUserContentController, didReceive message: WKScriptMessage) { func userContentController(_: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == "bitwardenApp" { if message.name != "bitwardenApp" {
return
}
let messageBody = message.body as! String let messageBody = message.body as! String
print(messageBody) // print(messageBody)
let m: AppMessage? = jsonDeserialize(json: messageBody) let m: AppMessage? = jsonDeserialize(json: messageBody)
if m == nil { if m == nil {
print("m is nil") // print("m is nil")
} else { return
let command = m?.command ?? "null" }
print(command) let command = m!.command
// print(command)
if command == "storage_get" { if command == "storage_get" {
let obj = UserDefaults.standard.string(forKey: m!.data!) let obj = UserDefaults.standard.string(forKey: m!.data!)
m!.responseData = obj m!.responseData = obj
@ -114,9 +117,8 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
} }
winIndex = winIndex + 1 winIndex = winIndex + 1
} }
if theWin != nil {
var theTab: SFSafariTab? var theTab: SFSafariTab?
theWin!.getAllTabs { tabs in theWin?.getAllTabs { tabs in
var tabIndex = 0 var tabIndex = 0
for tab in tabs { for tab in tabs {
if tabMsg?.tab.index == tabIndex { if tabMsg?.tab.index == tabIndex {
@ -125,24 +127,23 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
} }
tabIndex = tabIndex + 1 tabIndex = tabIndex + 1
} }
if theTab != nil { theTab?.getActivePage { activePage in
theTab!.getActivePage { activePage in
if activePage != nil {
activePage?.dispatchMessageToScript(withName: "bitwarden", userInfo: ["msg": tabMsg!.obj]) activePage?.dispatchMessageToScript(withName: "bitwarden", userInfo: ["msg": tabMsg!.obj])
} }
} }
} }
}
}
}
} else if command == "hidePopover" { } else if command == "hidePopover" {
dismissPopover() dismissPopover()
replyMessage(message: m!) replyMessage(message: m!)
} else if command == "showPopover" { } else if command == "showPopover" {
// TODO SFSafariApplication.getActiveWindow { win in
replyMessage(message: m!) win?.getToolbarItem(completionHandler: { item in
item?.showPopover()
self.replyMessage(message: m!)
})
}
} else if command == "reloadExtension" { } else if command == "reloadExtension" {
// TODO webView?.reload()
replyMessage(message: m!) replyMessage(message: m!)
} else if command == "copyToClipboard" { } else if command == "copyToClipboard" {
let pasteboard = NSPasteboard.general let pasteboard = NSPasteboard.general
@ -155,8 +156,6 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
replyMessage(message: m!) replyMessage(message: m!)
} }
} }
}
}
func replyMessage(message: AppMessage) { func replyMessage(message: AppMessage) {
if webView == nil { if webView == nil {