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

js:usbdisk wasEjected returns always true (macOS mount) #106

Open
rbartolome opened this issue Apr 23, 2024 · 4 comments
Open

js:usbdisk wasEjected returns always true (macOS mount) #106

rbartolome opened this issue Apr 23, 2024 · 4 comments
Labels
bugfix Something isn't working help-wanted Extra attention is needed needs-more-info Requires more information to triage

Comments

@rbartolome
Copy link

Describe the bug.

Using usbdisk.wasEjected() in javascript returns always true when mounted in macOS. Mass Storage app works correct.

Reproduction

  1. Use Javascript code
let usbdisk = require("usbdisk");
let image = "/ext/apps_data/mass_storage/AImage.img";
usbdisk.start(image);
delay(5000);
print("USB Disk activated");
while (true) 
{
  print(usbdisk.wasEjected());
  delay(1000);
}
  1. Run Code while Flipper is attached to macOS
  2. The Image is mounted correct
  3. The while loop always prints true even when the volume is mounted and unmounted

Target

No response

Logs

No response

Anything else?

I'm running the latest dev build

@Willy-JL
Copy link
Member

Interesting find... to be completely honest, the wasEjected logic is a bit of a hack because I couldn't find any reliable metric for when ejection happens, so I remember using the next best things from the events that the code handled, and seems like you just found a side effect

@Willy-JL Willy-JL added bugfix Something isn't working help-wanted Extra attention is needed labels Apr 23, 2024
@rbartolome
Copy link
Author

Maybe it's my mistake. I did play a little bit around. If I use the code above alone it works. If I use it with badusb before it didn't. Maybe you can close this issue.

let badusb = require("badusb");
let usbdisk = require("usbdisk");
let dialog = require("dialog");

let imageName = "0D";
let image = "/ext/apps_data/mass_storage/" + imageName + ".img";
 
// **************************
// Remove the following Code it worked
print("init BadUSB...");
badusb.setup(
{
  vid: 0x05ac,
  pid: 0x0250,
  mfr_name: "Apple Inc.",
  prod_name: "Apple Keyboard",
  layout_path: dialog.pickFile("/ext/badusb/assets/layouts", ".kl")
});

print("Connecting BadUSB...");
while (!badusb.isConnected()) 
{
  delay(500);
}

print("deinit BadUSB...");
badusb.quit();
// Remove the Code above it worked
// **************************


print("init USB Disk...");
usbdisk.start(image);
delay(5000);
print("USB Disk activated");

while (!usbdisk.wasEjected()) 
{
  print(usbdisk.wasEjected());
  delay(1000);
}

usbdisk.stop();

print("Done");

@rbartolome
Copy link
Author

When I add a delay(5000); after badusb.quit() it works. Sorry for wasting your time.

@Willy-JL
Copy link
Member

Still, this deserves some more investigation. But very good that you found more info on it! I'll try to have a look when I get the chance

@Willy-JL Willy-JL added the needs-more-info Requires more information to triage label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Something isn't working help-wanted Extra attention is needed needs-more-info Requires more information to triage
Projects
Status: Next Up
Development

No branches or pull requests

2 participants