davidhealey / waistline

Libre calorie counter app for Android. Built with Cordova.
577 stars 69 forks source link

[Bug] Scanner does not check network connection after starting #721

Open jncosideout opened 1 year ago

jncosideout commented 1 year ago

Description

It looks like the scanner only checks "reachability" status when it starts, and assumes it hasn't changed while the scanner is active.

Reproduction Steps

  1. Make sure Wi-Fi and cellular network are off
  2. Open Diary
  3. Add a food to a meal. From the Foods/Meals/Recipes activity, tap the barcode button in the top right corner
  4. While the scanner is active, turn on WiFi or Mobile Data (cellular network)
  5. Go back to the app, and scan a barcode
  6. Barcode is recognized, but an error pop-up displays "No Internet Connection"

Expected

App should recognize that the internet connection has been restored in the meantime since scanner was activated, and then perform the network call to fetch food data for the scanned barcode.

Screen Recordings

WiFi

https://github.com/davidhealey/waistline/assets/25991237/5a79be01-74e5-45d2-9dec-c201ffa3439a

Cellular

(*Note that I have "Only show images over Wi-Fi" set to true)

https://github.com/davidhealey/waistline/assets/25991237/e49975fa-53ac-47f6-b1c7-3d6f9b7c8ff9

Environment

App version: 3.6.0 Phone: Moto G7 Power OS: "LineageOS with MicroG" 19.1 (LOS 19.1 is equivalent to stock Android 12)

EmilJunker commented 1 year ago

This seems to be a bug in the Cordova network plugin. Waistline is definitely checking the connection after the barcode was scanned: https://github.com/davidhealey/waistline/blob/e2aa35b318d70f1d699c26627e391e7b4e7ba74c/www/activities/foodlist/js/foodlist.js#L441

I guess the plugin doesn't update the status while the app is in the background, i.e. while the scanner screen is visible. I don't know if there is a workaround for that.