Skip to content

Commit

Permalink
Fix issues with generating my link (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Jul 14, 2022
1 parent dadfd5d commit b906670
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/panels/hacs-repository-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,37 @@ export class HacsRepositoryPanel extends LitElement {

@state() private _error?: string;

protected async firstUpdated(changedProperties: PropertyValues): Promise<void> {
super.firstUpdated(changedProperties);
document.body.addEventListener("keydown", (ev: KeyboardEvent) => {
if (ev.ctrlKey || ev.shiftKey || ev.metaKey || ev.altKey) {
// Ignore if modifier keys are pressed
public connectedCallback() {
super.connectedCallback();
document.body.addEventListener("keydown", this._generateMyLink);
}

public disconnectedCallback() {
super.disconnectedCallback();
document.body.removeEventListener("keydown", this._generateMyLink);
}

private _generateMyLink = (ev: KeyboardEvent) => {
if (ev.ctrlKey || ev.shiftKey || ev.metaKey || ev.altKey) {
// Ignore if modifier keys are pressed
return;
}
if (ev.key === "m" && mainWindow.location.pathname.startsWith("/hacs/repository/")) {
if (!this._repository) {
return;
}
if (["m"].includes(ev.key)) {
const myParams = new URLSearchParams({
redirect: "hacs_repository",
owner: this._repository!.full_name.split("/")[0],
repository: this._repository!.full_name.split("/")[0],
category: this._repository!.category,
});
window.open(`https://my.home-assistant.io/create-link/?${myParams.toString()}`, "_blank");
}
});
const myParams = new URLSearchParams({
redirect: "hacs_repository",
owner: this._repository!.full_name.split("/")[0],
repository: this._repository!.full_name.split("/")[1],
category: this._repository!.category,
});
window.open(`https://my.home-assistant.io/create-link/?${myParams.toString()}`, "_blank");
}
};

protected async firstUpdated(changedProperties: PropertyValues): Promise<void> {
super.firstUpdated(changedProperties);

const params = extractSearchParamsObject();
if (Object.entries(params).length) {
Expand Down

0 comments on commit b906670

Please sign in to comment.