mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-08 19:18:02 +01:00
reload popup on open of safari app popover
This commit is contained in:
parent
42c44c381a
commit
6fe414ffbd
@ -42,10 +42,10 @@ export class SafariApp {
|
|||||||
if (message == null) {
|
if (message == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((message.id == null || message.id === '') && message.command === 'cs_message') {
|
if ((message.id == null || message.id === '') && message.command === 'app_message') {
|
||||||
try {
|
try {
|
||||||
const msg = JSON.parse(message.data);
|
const msg = JSON.parse(message.data);
|
||||||
SafariApp.sendMessageToListeners(msg, 'cs_message', null);
|
SafariApp.sendMessageToListeners(msg, 'app_message', null);
|
||||||
} catch { }
|
} catch { }
|
||||||
} else if (message.id != null && (window as any).bitwardenSafariAppRequests.has(message.id)) {
|
} else if (message.id != null && (window as any).bitwardenSafariAppRequests.has(message.id)) {
|
||||||
const p = (window as any).bitwardenSafariAppRequests.get(message.id);
|
const p = (window as any).bitwardenSafariAppRequests.get(message.id);
|
||||||
|
@ -127,6 +127,8 @@ export class AppComponent implements OnInit {
|
|||||||
// Wait to make sure background has reloaded first.
|
// Wait to make sure background has reloaded first.
|
||||||
window.setTimeout(() => BrowserApi.reloadExtension(window), 2000);
|
window.setTimeout(() => BrowserApi.reloadExtension(window), 2000);
|
||||||
}
|
}
|
||||||
|
} else if (msg.command === 'reloadPopup') {
|
||||||
|
this.router.navigate(['/']);
|
||||||
} else {
|
} else {
|
||||||
msg.webExtSender = sender;
|
msg.webExtSender = sender;
|
||||||
this.broadcasterService.send(msg);
|
this.broadcasterService.send(msg);
|
||||||
|
@ -16,7 +16,7 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
|
|||||||
page.getPropertiesWithCompletionHandler { properties in
|
page.getPropertiesWithCompletionHandler { properties in
|
||||||
// NSLog("The extension received a message (\(messageName)) from a script injected into (\(String(describing: properties?.url))) with userInfo (\(userInfo ?? [:]))")
|
// NSLog("The extension received a message (\(messageName)) from a script injected into (\(String(describing: properties?.url))) with userInfo (\(userInfo ?? [:]))")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
SafariExtensionViewController.shared.replyMessageFromScript(msg: userInfo)
|
SafariExtensionViewController.shared.sendMessage(msg: userInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,5 +35,11 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
|
|||||||
override func popoverViewController() -> SFSafariExtensionViewController {
|
override func popoverViewController() -> SFSafariExtensionViewController {
|
||||||
return SafariExtensionViewController.shared
|
return SafariExtensionViewController.shared
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func popoverWillShow(in window: SFSafariWindow) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
SafariExtensionViewController.shared.sendMessage(msg: ["command": "reloadPopup"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -153,12 +153,12 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
|
|||||||
webView.evaluateJavaScript("window.bitwardenSafariAppMessageReceiver(\(json));", completionHandler: nil)
|
webView.evaluateJavaScript("window.bitwardenSafariAppMessageReceiver(\(json));", completionHandler: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func replyMessageFromScript(msg: [String : Any]?) {
|
func sendMessage(msg: [String : Any]?) {
|
||||||
if(webView == nil) {
|
if(webView == nil) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let newMsg = AppMessage()
|
let newMsg = AppMessage()
|
||||||
newMsg.command = "cs_message"
|
newMsg.command = "app_message"
|
||||||
do {
|
do {
|
||||||
let jsonData = try JSONSerialization.data(withJSONObject: msg as Any, options: [])
|
let jsonData = try JSONSerialization.data(withJSONObject: msg as Any, options: [])
|
||||||
newMsg.data = String(data: jsonData, encoding: .utf8)
|
newMsg.data = String(data: jsonData, encoding: .utf8)
|
||||||
|
Loading…
Reference in New Issue
Block a user