Skip to content

Commit

Permalink
dynamic tap
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Jul 22, 2024
1 parent 541ca09 commit 927a706
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/Zemu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,19 @@ export default class Zemu {

if (!runLastAction) return imageIndex; // do not run last action if requested


// Approve can be performed with Tap or PressAndHold

Check failure on line 713 in src/Zemu.ts

View workflow job for this annotation

GitHub Actions / Format and Lint

'approveButton' is never reassigned. Use 'const' instead
const approveButton = getTouchElement(this.startOptions.model, this.startOptions.approveAction);
let approveButton = getTouchElement(this.startOptions.model, this.startOptions.approveAction);

if (this.startOptions.approveAction === ButtonKind.DynamicTapButton) {
const events = await this.getEvents();
const matchingEvent = events.find((event: IEvent) => textRegex.test(event.text));

Check failure on line 719 in src/Zemu.ts

View workflow job for this annotation

GitHub Actions / Format and Lint

Unexpected nullable object value in conditional. An explicit null check is required
if (matchingEvent) {
approveButton.x = Math.round(matchingEvent.x + matchingEvent.w / 2);
approveButton.y = Math.round(matchingEvent.y + matchingEvent.h / 2);
}
}

const nav: INavElement = {
type: touchDevice ? ActionKind.Touch : ActionKind.BothClick,
Expand Down
2 changes: 2 additions & 0 deletions src/buttons_flex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,7 @@ export namespace flex {
[ButtonKind.ConfirmNoButton, flex.confirmNoButton],
[ButtonKind.ShowQRButton, flex.showQRButton],
[ButtonKind.CloseQRButton, flex.closeQRButton],

[ButtonKind.DynamicTapButton, flex.approveTapButton],
]);
}
2 changes: 2 additions & 0 deletions src/buttons_stax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,7 @@ export namespace stax {
[ButtonKind.ConfirmNoButton, stax.confirmNoButton],
[ButtonKind.ShowQRButton, stax.showQRButton],
[ButtonKind.CloseQRButton, stax.closeQRButton],

[ButtonKind.DynamicTapButton, stax.approveTapButton],
]);
}
10 changes: 8 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export interface ISnapshot {
}

export interface IEvent {
text: string;
x: number;
y: number;
text: string;
w: number;
h: number;
clear: boolean;
}

export interface ISwipeCoordinates {
x: number;
y: number;
Expand Down Expand Up @@ -114,4 +116,8 @@ export const enum ButtonKind {

ShowQRButton,
CloseQRButton,

// Text to compare must match this button
// Zemu will find the center where the text is displayed and tap there
DynamicTapButton,
}
1 change: 0 additions & 1 deletion src/zondax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export function zondaxToggleExpertMode(model: TModel, clickArray?: number[]): Cl
if (isTouchDevice(model)) {
return new TouchNavigation(model, [
ButtonKind.InfoButton,
ButtonKind.NavRightButton,
ButtonKind.ToggleSettingButton1,
ButtonKind.SettingsQuitButton,
]);
Expand Down

0 comments on commit 927a706

Please sign in to comment.