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

Expose started status #1329

Open
jzaefferer opened this issue Feb 3, 2025 · 0 comments
Open

Expose started status #1329

jzaefferer opened this issue Feb 3, 2025 · 0 comments

Comments

@jzaefferer
Copy link
Contributor

jzaefferer commented Feb 3, 2025

Currently BleManager.start has to be called once before using any other BleManager methods. In our app, we want to defer this to the point where a BLE-related feature is actually needed and after checking permissions. To avoid calling it multiple times, we keep track of the started state and a module-level variable, like this:

// Define a module-scoped variable to track BleManager initialization
// unfortunately there's no way to ask BleManager if it has been started
export let isBleManagerInitialized = false;

export const setBleManagerInitialized = (value: boolean) => {
  isBleManagerInitialized = value;
};

const checkBTState = async () => {
  if (!isBleManagerInitialized) {
    await BleManager.start({ showAlert: false });
    setBleManagerInitialized(true);
  }
  return BleManager.checkState();
};

// permission checking code later calls checkBTState()
...
// other modules can import isBleManagerInitialized and setBleManagerInitialized(true)

While this works, we have to be careful not to add BleManager.start anywhere else. It would be great if we could instead ask BleManager to check if it has already been started. Would that be something to consider to add to the API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants