mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-07 09:31:31 +01:00
show popup, reload extension, and formatting
This commit is contained in:
parent
2a7e361300
commit
41be76a107
@ -50,15 +50,18 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
|
||||
}
|
||||
|
||||
func userContentController(_: WKUserContentController, didReceive message: WKScriptMessage) {
|
||||
if message.name == "bitwardenApp" {
|
||||
if message.name != "bitwardenApp" {
|
||||
return
|
||||
}
|
||||
let messageBody = message.body as! String
|
||||
print(messageBody)
|
||||
// print(messageBody)
|
||||
let m: AppMessage? = jsonDeserialize(json: messageBody)
|
||||
if m == nil {
|
||||
print("m is nil")
|
||||
} else {
|
||||
let command = m?.command ?? "null"
|
||||
print(command)
|
||||
// print("m is nil")
|
||||
return
|
||||
}
|
||||
let command = m!.command
|
||||
// print(command)
|
||||
if command == "storage_get" {
|
||||
let obj = UserDefaults.standard.string(forKey: m!.data!)
|
||||
m!.responseData = obj
|
||||
@ -114,9 +117,8 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
|
||||
}
|
||||
winIndex = winIndex + 1
|
||||
}
|
||||
if theWin != nil {
|
||||
var theTab: SFSafariTab?
|
||||
theWin!.getAllTabs { tabs in
|
||||
theWin?.getAllTabs { tabs in
|
||||
var tabIndex = 0
|
||||
for tab in tabs {
|
||||
if tabMsg?.tab.index == tabIndex {
|
||||
@ -125,24 +127,23 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
|
||||
}
|
||||
tabIndex = tabIndex + 1
|
||||
}
|
||||
if theTab != nil {
|
||||
theTab!.getActivePage { activePage in
|
||||
if activePage != nil {
|
||||
theTab?.getActivePage { activePage in
|
||||
activePage?.dispatchMessageToScript(withName: "bitwarden", userInfo: ["msg": tabMsg!.obj])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if command == "hidePopover" {
|
||||
dismissPopover()
|
||||
replyMessage(message: m!)
|
||||
} else if command == "showPopover" {
|
||||
// TODO
|
||||
replyMessage(message: m!)
|
||||
SFSafariApplication.getActiveWindow { win in
|
||||
win?.getToolbarItem(completionHandler: { item in
|
||||
item?.showPopover()
|
||||
self.replyMessage(message: m!)
|
||||
})
|
||||
}
|
||||
} else if command == "reloadExtension" {
|
||||
// TODO
|
||||
webView?.reload()
|
||||
replyMessage(message: m!)
|
||||
} else if command == "copyToClipboard" {
|
||||
let pasteboard = NSPasteboard.general
|
||||
@ -155,8 +156,6 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
|
||||
replyMessage(message: m!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func replyMessage(message: AppMessage) {
|
||||
if webView == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user