mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 16:56:35 +00:00
Fix copy encryption key (#23515)
This commit is contained in:
parent
d0123b2cce
commit
f3705a7e1d
@ -1,4 +1,4 @@
|
|||||||
export const copyToClipboard = async (str) => {
|
export const copyToClipboard = async (str, rootEl?: HTMLElement) => {
|
||||||
if (navigator.clipboard) {
|
if (navigator.clipboard) {
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(str);
|
await navigator.clipboard.writeText(str);
|
||||||
@ -8,10 +8,12 @@ export const copyToClipboard = async (str) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const root = rootEl ?? document.body;
|
||||||
|
|
||||||
const el = document.createElement("textarea");
|
const el = document.createElement("textarea");
|
||||||
el.value = str;
|
el.value = str;
|
||||||
document.body.appendChild(el);
|
root.appendChild(el);
|
||||||
el.select();
|
el.select();
|
||||||
document.execCommand("copy");
|
document.execCommand("copy");
|
||||||
document.body.removeChild(el);
|
root.removeChild(el);
|
||||||
};
|
};
|
||||||
|
@ -396,7 +396,10 @@ class DialogBackupOnboarding extends LitElement implements HassDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _copyKeyToClipboard() {
|
private async _copyKeyToClipboard() {
|
||||||
await copyToClipboard(this._config!.create_backup.password!);
|
await copyToClipboard(
|
||||||
|
this._config!.create_backup.password!,
|
||||||
|
this.renderRoot.querySelector("div")!
|
||||||
|
);
|
||||||
showToast(this, {
|
showToast(this, {
|
||||||
message: this.hass.localize("ui.common.copied_clipboard"),
|
message: this.hass.localize("ui.common.copied_clipboard"),
|
||||||
});
|
});
|
||||||
|
@ -206,7 +206,10 @@ class DialogChangeBackupEncryptionKey extends LitElement implements HassDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _copyKeyToClipboard() {
|
private async _copyKeyToClipboard() {
|
||||||
await copyToClipboard(this._newEncryptionKey);
|
await copyToClipboard(
|
||||||
|
this._newEncryptionKey,
|
||||||
|
this.renderRoot.querySelector("div")!
|
||||||
|
);
|
||||||
showToast(this, {
|
showToast(this, {
|
||||||
message: this.hass.localize("ui.common.copied_clipboard"),
|
message: this.hass.localize("ui.common.copied_clipboard"),
|
||||||
});
|
});
|
||||||
@ -216,7 +219,10 @@ class DialogChangeBackupEncryptionKey extends LitElement implements HassDialog {
|
|||||||
if (!this._params?.currentKey) {
|
if (!this._params?.currentKey) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await copyToClipboard(this._params.currentKey);
|
await copyToClipboard(
|
||||||
|
this._params.currentKey,
|
||||||
|
this.renderRoot.querySelector("div")!
|
||||||
|
);
|
||||||
showToast(this, {
|
showToast(this, {
|
||||||
message: this.hass.localize("ui.common.copied_clipboard"),
|
message: this.hass.localize("ui.common.copied_clipboard"),
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user