emericg / WatchFlower

A plant monitoring application that reads and plots data from compatible Bluetooth sensors and thermometers like Xiaomi 'Flower Care' or Parrot 'Flower Power'
https://emeric.io/WatchFlower
GNU General Public License v3.0
195 stars 29 forks source link

Bluetooth disabled notification after allowing bluetooth access M1 macOS 12.4 #68

Open lesleyblankendal opened 2 years ago

lesleyblankendal commented 2 years ago

Describe the bug Bluetooth disabled notification after allowing bluetooth acces macOS 12.4. When the app launches I give it permission but all devices show as offline with a notification that my bluetooth is disabled. Also granted additional access in privacy & settings > bluetooth, to see if that makes any difference.

iPad version that can be run from Mac App Store on M1 iMac doesn't have this issue

Expected behavior Sensors show as online

To Reproduce Steps to reproduce the behavior:

  1. Open app on macOS
  2. grant bluetooth access
  3. Go to Home Screen
  4. See error

Screenshots

Schermafbeelding 2022-06-29 om 16 18 29

Your environment Please describe the environment you are using:

  1. macOS 12.4, iMac 24 inch late 2020
  2. downloaded 4.1 update just now to see if it was fixed. Bug was introduced in 4.0
  3. 4.1
emericg commented 2 years ago

Yes the Bluetooth and permission detection can be a little shaky on macOS, but that's usually not that problematic. I'll see if I can fix that once and for... well until next time it break anyway...

steveatinfincia commented 2 years ago

I'm seeing this one too, though it works if the binary is launched from a terminal rather than through finder which is certainly strange.

jeeftor commented 1 year ago

I also see it on an M1

jeeftor commented 1 year ago

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSBluetoothAlwaysUsageDescription key with a string value explaining to the user how the app uses this data.

I got this error when I ran it from CLI

jeeftor commented 1 year ago

Sounds like a .plist issue...

jeeftor commented 1 year ago

image

But it looks like you have the plist stuff...

emericg commented 1 year ago

Indeed. Can you try with a more recent build? https://github.com/emericg/WatchFlower/actions/runs/3660319742

It has both improvements and newer Qt version, maybe that will help.

fabiang commented 1 year ago

Still having this issue with version 5 on Mac OS 13.2.1. Also tried a recent build with no luck.

emericg commented 1 year ago

Yes I'm really sorry, this problem has proven difficult to understand and to solve... But I haven't forgotten it. It's just that I failed every time I had a look at it (last time being tonight :)

fabiang commented 1 year ago

I've also spent an hour trying to find the error. Imho this must be an upstream bug in Qt and/or OS X?

// Edit: Imho either the .entitlements is not applied correctly when the app is build for OS X and/or bluetooth access is only possible when the app correctly signed (and its a bug for untrusted apps).

emericg commented 1 year ago

Imho this must be an upstream bug in Qt and/or OS X?

Yes Qt doesn't have a great integration of the "new" Bluetooth permission for macOS. That permission appeared recently, and it was working better before, that is a fact. I had high hopes for the new permission system of Qt 6.5, but so far not much luck with it.

the .entitlements is not applied correctly when the app is build for OS X

There were even weirder cases before, like the app run through Qt Creator, run with a terminal or launched through the icon not behaving the same. But now on my mac it is working, I don't have the permission issue anymore. It is working poorly though, it needs time to bring up the permission popup and after granting the permission it takes time to start working.

bluetooth access is only possible when the app correctly signed (and its a bug for untrusted apps).

That is definitely an issue. I think the app cannot save the permission if not signed, and so every time you launch the app it will ask for it again, and exhibit this issue. It cannot just launch with a permission granted and run like it was running before the permission issue.

fabiang commented 11 months ago

I think I figured it out. On my local install, I've just added this to my Info.plist:

<key>UIBackgroundModes</key>
<array>
   <string>bluetooth-central</string>
</array>

bluetooth-peripheral seems to work too as a value for this setting. According to this bluetooth-centralis the correct value: https://docs.silabs.com/bluetooth/3.1/general/connections/central-and-peripheral-roles#:~:text=In%20the%20BLE%20world%2C%20the,incoming%20connection%20request%20after%20advertising

Someone able to confirm this? Have it from here: https://stackoverflow.com/a/48390949 Possible value are here: https://developer.apple.com/documentation/bundleresources/information_property_list/uibackgroundmodes

emericg commented 11 months ago

That's interesting, but it is said that UIBackgroundModes is only for iOS, and that using it prevents you from being accepted on the app store. Weird option...

I'll test this on a mac but yes we'll need people to confirm this has an actual impact beyond placebo.

fabiang commented 10 months ago

@emericg I've just checked if this automatically prevents you from being accepted to the Appstore and that should only be the case if your App doesn't use Bluetooth (or an Apple employee doesn't understand that is does). And from what I've read this values is definitely needed for Bluetooth to function. I've now working the fifth day with this option.

emericg commented 10 months ago

It made zero difference in my testing, and the doc still says for iOS only. But truth be told I don't really care enough to go against this, so I've added this line to the plist, we'll see if anyone report an actual difference in behavior...

fabiang commented 10 months ago

Tested once again with build 7233199927 and can confirm it's working.

NathanBnm commented 10 months ago

I have the same issue with the last build (https://github.com/emericg/WatchFlower/actions/runs/7233199927) Capture d’écran 2024-01-03 à 14 34 07 Capture d’écran 2024-01-03 à 14 34 28

fabiang commented 10 months ago

I removed the permission manually and now I'm unable to get it working again. Very weird.