diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts index 64fc5f727..1a5cbced0 100644 --- a/app/src/protyle/util/compatibility.ts +++ b/app/src/protyle/util/compatibility.ts @@ -45,12 +45,6 @@ export const readClipboard = async () => { textPlain?: string, files?: File[], } = {textPlain: "", textHTML: ""}; - if (isInAndroid()) { - text.textPlain = window.JSAndroid.readClipboard(); - } else if (isInHarmony()) { - text.textPlain = window.JSHarmony.readClipboard(); - } - try { const clipboardContents = await navigator.clipboard.read(); for (const item of clipboardContents) { @@ -67,9 +61,17 @@ export const readClipboard = async () => { text.files = [new File([blob], "image.png", {type: "image/png", lastModified: Date.now()})]; } } + return text; } catch (e) { + if (isInAndroid()) { + text.textPlain = window.JSAndroid.readClipboard(); + text.textHTML = window.JSAndroid.readHTMLClipboard(); + } else if (isInHarmony()) { + text.textPlain = window.JSHarmony.readClipboard(); + text.textHTML = window.JSHarmony.readHTMLClipboard(); + } + return text; } - return text; }; export const writeText = (text: string) => { diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 9d1b73096..6970314ef 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -191,6 +191,7 @@ interface Window { writeHTMLClipboard(text: string, html: string): void writeImageClipboard(uri: string): void readClipboard(): string + readHTMLClipboard(): string getBlockURL(): string } JSHarmony: { @@ -199,6 +200,7 @@ interface Window { writeClipboard(text: string): void writeHTMLClipboard(text: string, html: string): void readClipboard(): string + readHTMLClipboard(): string returnDesktop(): void }