Vanessa 2025-02-28 12:27:26 +08:00
parent d26b46478a
commit 5753de5b13
2 changed files with 11 additions and 7 deletions

View file

@ -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) => {

View file

@ -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
}