Skip to content

Commit

Permalink
allow passing custom functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jleni committed Apr 8, 2020
1 parent 84b8c26 commit 1da11d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
22 changes: 12 additions & 10 deletions src/emuContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class EmuContainer {
this.elfLocalPath = elfLocalPath;
}

async runContainer(logging, X11) {
async runContainer(options) {
return new Promise((resolve, reject) => {
// eslint-disable-next-line global-require
const Docker = require("dockerode");
Expand All @@ -36,21 +36,23 @@ export default class EmuContainer {
const app_filename = path.basename(this.elfLocalPath);
const app_dir = path.dirname(this.elfLocalPath);

let displaySetting = "--display headless"
if (X11) {
displaySetting = ""
}

const command = `/home/zondax/speculos/speculos.py ${displaySetting} --vnc-port ${DEFAULT_VNC_PORT} ${DEFAULT_APP_PATH}/${app_filename}`;

let dirBindings = [
`${app_dir}:${DEFAULT_APP_PATH}`
]

if (X11) {
let displaySetting = "--display headless"
if ("X11" in options && options["X11"] === true ){
displaySetting = ""
dirBindings.push("/tmp/.X11-unix:/tmp/.X11-unix:ro")
}

let customOptions = "";
if ("custom" in options) {
customOptions = options["custom"]
}

const command = `/home/zondax/speculos/speculos.py ${displaySetting} ${customOptions} --vnc-port ${DEFAULT_VNC_PORT} ${DEFAULT_APP_PATH}/${app_filename}`;

docker.createContainer({
Image: this.image,
Tty: true,
Expand Down Expand Up @@ -79,7 +81,7 @@ export default class EmuContainer {
.then(container => {
this.currentContainer = container;

if (logging) {
if ("logging" in options && options["logging"] === true ){
container.attach({ stream: true, stdout: true, stderr: true }, function(err, stream) {
stream.pipe(process.stdout);
});
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export default class Zemu {
this.emuContainer = new EmuContainer(this.elfPath, DEFAULT_EMU_IMG);
}

async start(logging = false, x11 = false) {
await this.emuContainer.runContainer(logging, x11);
async start(options = {}) {
await this.emuContainer.runContainer(options);
// eslint-disable-next-line func-names
await this.connect().catch(error => {
console.log(error);
Expand Down
2 changes: 1 addition & 1 deletion tests/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test("Zemu-Start&Close", async () => {
const sim = new Zemu(DEMO_APP_PATH);
expect(sim).not.toBeNull();
try {
await sim.start(true);
await sim.start({ logging: true });
} finally {
await sim.close();
}
Expand Down

0 comments on commit 1da11d3

Please sign in to comment.