diff --git a/sbapp/main.py b/sbapp/main.py index 99f2e5b..41d8d6f 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -52,9 +52,15 @@ if RNS.vendor.platformutils.get_platform() == "android": from android.runnable import run_on_ui_thread class SidebandApp(MDApp): + STARTING = 0x00 + ACTIVE = 0x01 + PAUSED = 0x02 + STOPPING = 0x03 + def __init__(self, **kwargs): super().__init__(**kwargs) self.title = "Sideband" + self.app_state = SidebandApp.STARTING self.sideband = SidebandCore(self) @@ -82,6 +88,7 @@ class SidebandApp(MDApp): if RNS.vendor.platformutils.get_platform() == "android": Clock.schedule_once(dismiss_splash, 0) + self.app_state = SidebandApp.ACTIVE def start_android_service(self): service = autoclass('io.unsigned.sideband.ServiceSidebandservice') @@ -94,6 +101,23 @@ class SidebandApp(MDApp): # General helpers # ################################################# + def on_pause(self): + self.app_state = SidebandApp.PAUSED + self.sideband.should_persist_data() + return True + + def on_resume(self): + self.app_state = SidebandApp.ACTIVE + + def on_stop(self): + self.app_state = SidebandApp.STOPPING + + def is_in_foreground(self): + if self.app_state == SidebandApp.ACTIVE: + return True + else: + return False + def notify(self, title, content): notifications_enabled = True diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 2abe789..1a7fa0c 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -161,6 +161,11 @@ class SidebandCore(): if not os.path.isfile(self.db_path): self.__db_init() + def should_persist_data(self): + if self.reticulum != None: + self.reticulum._should_persist_data() + + self.save_configuration() def __load_config(self): RNS.log("Loading Sideband identity...") @@ -896,10 +901,17 @@ class SidebandCore(): return True def lxm_ingest(self, message, originator = False): + should_notify = False + is_trusted = False + if originator: context_dest = message.destination_hash else: context_dest = message.source_hash + is_trusted = self.is_trusted(context_dest) + + if is_trusted: + should_notify = True if self._db_message(message.hash): RNS.log("Message exists, setting state to: "+str(message.state), RNS.LOG_DEBUG) @@ -916,6 +928,10 @@ class SidebandCore(): if self.owner_app.root.ids.messages_scrollview.active_conversation != context_dest: self.unread_conversation(context_dest) self.owner_app.flag_unread_conversations = True + else: + RNS.log("CHECKING FG STATE") + if self.owner_app.is_in_foreground(): + should_notify = False else: self.unread_conversation(context_dest) self.owner_app.flag_unread_conversations = True @@ -925,6 +941,15 @@ class SidebandCore(): except Exception as e: RNS.log("Error in conversation update callback: "+str(e)) + if should_notify: + nlen = 128 + text = message.content.decode("utf-8") + notification_content = text[:nlen] + if len(text) > nlen: + text += "..." + + self.owner_app.notify(title="Message from "+self.peer_display_name(context_dest), content=notification_content) + def start(self): self._db_clean_messages() diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py index eeaf0d6..9cfe9b2 100644 --- a/sbapp/ui/layouts.py +++ b/sbapp/ui/layouts.py @@ -6,8 +6,8 @@ MDNavigationLayout: ScreenManager: id: screen_manager - # transition: SlideTransition() - transition: NoTransition() + transition: SlideTransition() + # transition: NoTransition() MDScreen: name: "starting_screen"