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

Web Serial API removed and added events are never called #34887

Closed
3 tasks done
Loongwoo opened this issue Jul 12, 2022 · 2 comments · Fixed by #34958
Closed
3 tasks done

Web Serial API removed and added events are never called #34887

Loongwoo opened this issue Jul 12, 2022 · 2 comments · Fixed by #34958
Assignees
Labels
19-x-y bug 🪲 platform/macOS status/confirmed A maintainer reproduced the bug or agreed with the feature

Comments

@Loongwoo
Copy link

Loongwoo commented Jul 12, 2022

Preflight Checklist

Electron Version

19.0.8

What operating system are you using?

macOS

Operating System Version

macOS Monterey 12.4

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

I want to update UI when picking a port if a serial port is plugged in or unplugged.

Test Steps:
1, Click button to call navigator.serial.requestPort()
2, Show a modal to show port list in the select-serial-port event handler
3, Plug in or unplug a device to check the serial-port-added and serial-port-removed events

modal.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {
    //Add listeners to handle ports being added or removed before the callback for `select-serial-port`
    //is called.
    modal.webContents.session.on('serial-port-added', (event, port) => {
      console.log('serial-port-added FIRED WITH', port)
      //Optionally update portList to add the new port
    })
  
    modal.webContents.session.on('serial-port-removed', (event, port) => {
      console.log('serial-port-removed FIRED WITH', port)
      //Optionally update portList to remove the port
    })

    // modal.webContents.openDevTools();
    modal.webContents.send('update-list', portList);
    modal.show();

    event.preventDefault();
    ipcMain.once('serial-port', (_event, portId = '') => {
      callback(portId);
      modal.hide();
    });
  });

Actual Behavior

But the select-serial-port and select-serial-removed events never called. Did I use these api in a wrong way?

Testcase Gist URL

https://gist.github.com/0bbeeaa1c9e8f5affb6b59663870616e

Additional Information

No response

@Loongwoo Loongwoo changed the title [Bug]: Web Serial API removed and added events are never called Web Serial API removed and added events are never called Jul 12, 2022
@codebytere
Copy link
Member

cc @jkleinsc

@jkleinsc jkleinsc added the status/confirmed A maintainer reproduced the bug or agreed with the feature label Jul 12, 2022
@jkleinsc jkleinsc self-assigned this Jul 18, 2022
@jkleinsc
Copy link
Contributor

I have a fix for this and will put up a PR shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
19-x-y bug 🪲 platform/macOS status/confirmed A maintainer reproduced the bug or agreed with the feature
Projects
No open projects
Status: Fixed for Next Release
Development

Successfully merging a pull request may close this issue.

3 participants