1
0
mirror of https://github.com/bitwarden/browser synced 2024-12-24 17:11:55 +01:00

Fix copying TOTP not working in Safari (#1598)

This commit is contained in:
Oscar Hinton 2021-02-04 23:34:10 +01:00 committed by GitHub
parent 3e79dd245b
commit e5764ee16e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -21,6 +21,13 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
let pasteboard = NSPasteboard.general
response.userInfo = [ SFExtensionMessageKey: pasteboard.pasteboardItems?.first?.string(forType: .string) as Any ]
break
case "copyToClipboard":
guard let msg = message?["data"] as? String else {
return
}
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(msg, forType: .string)
case "showPopover":
SFSafariApplication.getActiveWindow { win in
win?.getToolbarItem(completionHandler: { item in

View File

@ -190,7 +190,14 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
}
const clearing = options ? !!options.clearing : false;
const clearMs: number = options && options.clearMs ? options.clearMs : null;
if (this.isFirefox() && (win as any).navigator.clipboard && (win as any).navigator.clipboard.writeText) {
if (this.isSafari()) {
SafariApp.sendMessageToApp('copyToClipboard', text).then(() => {
if (!clearing && this.clipboardWriteCallback != null) {
this.clipboardWriteCallback(text, clearMs);
}
});
} else if (this.isFirefox() && (win as any).navigator.clipboard && (win as any).navigator.clipboard.writeText) {
(win as any).navigator.clipboard.writeText(text).then(() => {
if (!clearing && this.clipboardWriteCallback != null) {
this.clipboardWriteCallback(text, clearMs);