Skip to content

Commit

Permalink
Merge pull request #466 from Zondax/dynamic_tap_approve
Browse files Browse the repository at this point in the history
Dynamic tap
  • Loading branch information
ftheirs authored Jul 22, 2024
2 parents 99f6bf4 + 24ac97a commit b9885b1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/Zemu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,16 @@ export default class Zemu {
// Approve can be performed with Tap or PressAndHold
const 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));

if (matchingEvent != null) {
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,
button: approveButton,
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],
]);
}
2 changes: 1 addition & 1 deletion src/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class EmuContainer {
}

const displayEnvironment: string =
process.platform === "darwin" ? "host.docker.internal:0" : process.env.DISPLAY ?? "";
process.platform === "darwin" ? "host.docker.internal:0" : (process.env.DISPLAY ?? "");
const environment = [
`SCP_PRIVKEY='${DEV_CERT_PRIVATE_KEY}'`,
`BOLOS_SDK='${BOLOS_SDK}'`,
Expand Down
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,
}
5 changes: 2 additions & 3 deletions src/zondax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export function zondaxMainmenuNavigation(model: TModel, clickArray?: number[]):
if (isTouchDevice(model)) {
return new TouchNavigation(model, [
ButtonKind.InfoButton,
ButtonKind.SettingsNavRightButton,
ButtonKind.SettingsNavRightButton,
ButtonKind.ToggleSettingButton1,
ButtonKind.ToggleSettingButton1,
ButtonKind.SettingsNavRightButton,
ButtonKind.SettingsNavRightButton,
ButtonKind.SettingsQuitButton,
]);
}
Expand All @@ -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 b9885b1

Please sign in to comment.