Fixed UI redraw bug causing black screen on Android on app resume

This commit is contained in:
Mark Qvist 2024-11-23 14:24:45 +01:00
parent 9f86c4130c
commit bf8fbe5f86

View File

@ -303,7 +303,6 @@ class SidebandApp(MDApp):
self.hw_error_dialog = None self.hw_error_dialog = None
self.final_load_completed = False self.final_load_completed = False
self.wants_wake_update = False
self.service_last_available = 0 self.service_last_available = 0
self.closing_app = False self.closing_app = False
@ -700,9 +699,12 @@ class SidebandApp(MDApp):
else: else:
RNS.log("Conversations view did not exist", RNS.LOG_DEBUG) RNS.log("Conversations view did not exist", RNS.LOG_DEBUG)
def cb(dt): def ui_update_job():
self.wants_wake_update = True time.sleep(0.05)
Clock.schedule_once(cb, 1.2) def cb(dt):
self.perform_wake_update()
Clock.schedule_once(cb, 0.1)
threading.Thread(target=ui_update_job, daemon=True).start()
RNS.log("App resumed", RNS.LOG_DEBUG) RNS.log("App resumed", RNS.LOG_DEBUG)
@ -719,6 +721,21 @@ class SidebandApp(MDApp):
else: else:
return False return False
def perform_wake_update(self):
# This workaround mitigates a bug in Kivy on Android
# which causes the UI to turn black on app resume,
# probably due to an invalid GL draw context. By
# simply opening and immediately closing the nav
# drawer, we force the UI to do a frame redraw, which
# results in the UI actually being visible again.
if RNS.vendor.platformutils.is_android():
RNS.log("Performing app wake UI update", RNS.LOG_DEBUG)
self.root.ids.nav_drawer.set_state("open")
def cb(dt):
self.root.ids.nav_drawer.set_state("closed")
Clock.schedule_once(cb, 0)
def check_bluetooth_permissions(self): def check_bluetooth_permissions(self):
if RNS.vendor.platformutils.get_platform() == "android": if RNS.vendor.platformutils.get_platform() == "android":
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
@ -977,11 +994,6 @@ class SidebandApp(MDApp):
if self.conversations_view != None: if self.conversations_view != None:
self.conversations_view.update() self.conversations_view.update()
if self.wants_wake_update:
self.wants_wake_update = False
if self.conversations_view != None:
self.conversations_view.update()
if self.sideband.getstate("app.flags.lxmf_sync_dialog_open", allow_cache=True) and self.sync_dialog != None: if self.sideband.getstate("app.flags.lxmf_sync_dialog_open", allow_cache=True) and self.sync_dialog != None:
state = self.sideband.message_router.propagation_transfer_state state = self.sideband.message_router.propagation_transfer_state
@ -1003,11 +1015,6 @@ class SidebandApp(MDApp):
if self.announces_view != None: if self.announces_view != None:
self.announces_view.update() self.announces_view.update()
if self.wants_wake_update:
self.wants_wake_update = False
if self.announces_view != None:
self.announces_view.update()
elif self.root.ids.screen_manager.current == "map_screen": elif self.root.ids.screen_manager.current == "map_screen":
if self.map_screen and hasattr(self.map_screen.ids.map_layout, "map") and self.map_screen.ids.map_layout.map != None: if self.map_screen and hasattr(self.map_screen.ids.map_layout, "map") and self.map_screen.ids.map_layout.map != None:
self.sideband.config["map_lat"] = self.map_screen.ids.map_layout.map.lat self.sideband.config["map_lat"] = self.map_screen.ids.map_layout.map.lat
@ -1018,10 +1025,6 @@ class SidebandApp(MDApp):
if self.last_telemetry_received > self.last_map_update: if self.last_telemetry_received > self.last_map_update:
self.map_update_markers() self.map_update_markers()
if self.wants_wake_update:
self.wants_wake_update = False
self.map_update_markers()
if self.sideband.getstate("app.flags.new_conversations", allow_cache=True): if self.sideband.getstate("app.flags.new_conversations", allow_cache=True):
if self.conversations_view != None: if self.conversations_view != None:
self.conversations_view.update() self.conversations_view.update()