mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
23 lines
782 B
JavaScript
23 lines
782 B
JavaScript
// Obsidian points navigator.clipboard.writeText at electron.clipboard, which already points at this shim.
|
|
// To avoid recursion, use the untouched native prototype methods.
|
|
const proto = typeof Clipboard !== "undefined" ? Clipboard.prototype : null;
|
|
|
|
// Returns a native-backed clipboard facade, or null in insecure (non-localhost http) contexts.
|
|
export function getClipboard() {
|
|
const clip =
|
|
typeof navigator !== "undefined" ? navigator.clipboard : undefined;
|
|
|
|
if (!proto || !clip) {
|
|
console.warn(
|
|
"[shim:clipboard] clipboard API unavailable (insecure context?)",
|
|
);
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
writeText: (text) => proto.writeText.call(clip, text),
|
|
write: (items) => proto.write.call(clip, items),
|
|
read: () => proto.read.call(clip),
|
|
};
|
|
}
|