mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-02 08:40:08 +01:00
safari app browser utils
This commit is contained in:
parent
bf43a198c7
commit
d91c96ae65
@ -1,4 +1,5 @@
|
|||||||
import { BrowserApi } from '../browser/browserApi';
|
import { BrowserApi } from '../browser/browserApi';
|
||||||
|
import { SafariApp } from '../browser/safariApp';
|
||||||
|
|
||||||
import { DeviceType } from 'jslib/enums/deviceType';
|
import { DeviceType } from 'jslib/enums/deviceType';
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
|||||||
return this.deviceCache;
|
return this.deviceCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((window as any).safariAppExtension === true) {
|
if (this.isSafariExtension()) {
|
||||||
this.deviceCache = DeviceType.SafariExtension;
|
this.deviceCache = DeviceType.SafariExtension;
|
||||||
} else if (navigator.userAgent.indexOf(' Firefox/') !== -1 || navigator.userAgent.indexOf(' Gecko/') !== -1) {
|
} else if (navigator.userAgent.indexOf(' Firefox/') !== -1 || navigator.userAgent.indexOf(' Gecko/') !== -1) {
|
||||||
this.deviceCache = DeviceType.FirefoxExtension;
|
this.deviceCache = DeviceType.FirefoxExtension;
|
||||||
@ -187,7 +188,13 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
|||||||
}
|
}
|
||||||
const clearing = options ? !!options.clearing : false;
|
const clearing = options ? !!options.clearing : false;
|
||||||
const clearMs: number = options && options.clearMs ? options.clearMs : null;
|
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.isSafariExtension()) {
|
||||||
|
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(() => {
|
(win as any).navigator.clipboard.writeText(text).then(() => {
|
||||||
if (!clearing && this.clipboardWriteCallback != null) {
|
if (!clearing && this.clipboardWriteCallback != null) {
|
||||||
this.clipboardWriteCallback(text, clearMs);
|
this.clipboardWriteCallback(text, clearMs);
|
||||||
@ -231,7 +238,9 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
|||||||
doc = options.doc;
|
doc = options.doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isFirefox() && (win as any).navigator.clipboard && (win as any).navigator.clipboard.readText) {
|
if (this.isSafariExtension()) {
|
||||||
|
return await SafariApp.sendMessageToApp('readFromClipboard');
|
||||||
|
} else if (this.isFirefox() && (win as any).navigator.clipboard && (win as any).navigator.clipboard.readText) {
|
||||||
return await (win as any).navigator.clipboard.readText();
|
return await (win as any).navigator.clipboard.readText();
|
||||||
} else if (doc.queryCommandSupported && doc.queryCommandSupported('paste')) {
|
} else if (doc.queryCommandSupported && doc.queryCommandSupported('paste')) {
|
||||||
const textarea = doc.createElement('textarea');
|
const textarea = doc.createElement('textarea');
|
||||||
@ -283,4 +292,8 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isSafariExtension(): boolean {
|
||||||
|
return (window as any).safariAppExtension === true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user