Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic tap #466

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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