Skip to content

Commit

Permalink
Fix double triggering
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmayer-dev committed Apr 29, 2024
1 parent cad510a commit 64219b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}"
(down)="onMouseDown($event)"
(up)="onMouseUp($event)"
(mouseleave)="onMouseUp($event)"
(mouseleave)="onMouseLeave($event)"
class="button-widget-wrapper">
<img *ngIf="foregroundImage" [src]="foregroundImage" class="foreground" />
<img *ngIf="iconImage" [src]="iconImage" class="icon" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class ButtonWidgetComponent {

private longPressTrigger: boolean = false;
private longPressTimeout: any;
private pressed: boolean = false;

constructor(private renderer: Renderer2,
private macroDeckService: MacroDeckService,
Expand All @@ -44,6 +45,11 @@ export class ButtonWidgetComponent {
}

onMouseUp(event: Event) {
if (!this.pressed) {
return;
}

this.pressed = false;
this.setClass(event.currentTarget, 'pressed', false);
this.setClass(event.currentTarget, 'release-transition', true);

Expand All @@ -59,10 +65,15 @@ export class ButtonWidgetComponent {
clearTimeout(this.longPressTimeout);
}

async onMouseLeave(event: Event) {
this.onMouseUp(event);
}

async onMouseDown(event: Event) {
this.setClass(event.currentTarget, 'pressed', true);
this.setClass(event.currentTarget, 'release-transition', false);
this.emitInteraction(WidgetInteractionType.ButtonPress);
this.pressed = true;

let buttonLongPressDelay = await this.settingsService.getButtonLongPressDelay();

Expand Down

0 comments on commit 64219b4

Please sign in to comment.