update
This commit is contained in:
@@ -37,6 +37,11 @@ export class EcoApplauncherWifimenu extends DeesElement {
|
||||
:host {
|
||||
display: block;
|
||||
position: relative;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
:host([open]) {
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.menu-container {
|
||||
@@ -224,10 +229,16 @@ export class EcoApplauncherWifimenu extends DeesElement {
|
||||
accessor wifiEnabled = true;
|
||||
|
||||
private boundHandleClickOutside = this.handleClickOutside.bind(this);
|
||||
private inactivityTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
private readonly INACTIVITY_TIMEOUT = 60000; // 1 minute
|
||||
|
||||
public render(): TemplateResult {
|
||||
return html`
|
||||
<div class="menu-container">
|
||||
<div class="menu-container"
|
||||
@click=${(e: MouseEvent) => e.stopPropagation()}
|
||||
@mousemove=${this.resetInactivityTimer}
|
||||
@mousedown=${this.resetInactivityTimer}
|
||||
>
|
||||
<div class="menu-header">
|
||||
<span class="menu-title">
|
||||
<dees-icon .icon=${'lucide:wifi'} .iconSize=${18}></dees-icon>
|
||||
@@ -332,11 +343,41 @@ export class EcoApplauncherWifimenu extends DeesElement {
|
||||
|
||||
private handleClickOutside(e: MouseEvent): void {
|
||||
if (this.open && !this.contains(e.target as Node)) {
|
||||
this.open = false;
|
||||
this.dispatchEvent(new CustomEvent('menu-close', {
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
}));
|
||||
this.closeMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private resetInactivityTimer(): void {
|
||||
this.clearInactivityTimer();
|
||||
if (this.open) {
|
||||
this.inactivityTimeout = setTimeout(() => {
|
||||
this.closeMenu();
|
||||
}, this.INACTIVITY_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
private clearInactivityTimer(): void {
|
||||
if (this.inactivityTimeout) {
|
||||
clearTimeout(this.inactivityTimeout);
|
||||
this.inactivityTimeout = null;
|
||||
}
|
||||
}
|
||||
|
||||
private closeMenu(): void {
|
||||
this.open = false;
|
||||
this.dispatchEvent(new CustomEvent('menu-close', {
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
}));
|
||||
}
|
||||
|
||||
protected updated(changedProperties: Map<string, unknown>): void {
|
||||
if (changedProperties.has('open')) {
|
||||
if (this.open) {
|
||||
this.resetInactivityTimer();
|
||||
} else {
|
||||
this.clearInactivityTimer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,5 +392,6 @@ export class EcoApplauncherWifimenu extends DeesElement {
|
||||
async disconnectedCallback(): Promise<void> {
|
||||
await super.disconnectedCallback();
|
||||
document.removeEventListener('click', this.boundHandleClickOutside);
|
||||
this.clearInactivityTimer();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user