From 23ab36a34ff6847b7a8ee35006b13217ac5f25a1 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 6 Jul 2022 16:08:53 +0200 Subject: [PATCH] Added connectivity status. Improved navigation. --- Makefile | 5 ++- main.py | 76 ++++++++++++++++++++++++++++++++++++++++++++- sideband/core.py | 10 +++--- ui/announces.py | 2 +- ui/conversations.py | 8 ++--- ui/layouts.py | 25 ++++++++------- ui/messages.py | 4 +-- 7 files changed, 104 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 317d3bd..62d441a 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,10 @@ apk: prepare release postbuild devapk: prepare debug postbuild install: - adb install bin/sideband-0.1.4-arm64-v8a-debug.apk + adb install bin/sideband-0.1.5-arm64-v8a-debug.apk + +install-release: + adb install bin/sideband-0.1.5-arm64-v8a-release.apk console: (adb logcat | grep python) diff --git a/main.py b/main.py index db43091..fea4fe6 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ from sideband.core import SidebandCore from kivymd.app import MDApp from kivy.core.window import Window +from kivy.base import EventLoop from kivy.clock import Clock from kivy.lang.builder import Builder @@ -85,13 +86,34 @@ class SidebandApp(MDApp): self.announces_view.update() def on_start(self): + self.last_exit_event = time.time() + EventLoop.window.bind(on_keyboard=self.keyboard_event) + EventLoop.window.bind(on_key_down=self.keydown_event) + self.root.ids.screen_manager.app = self self.root.ids.app_version_info.text = "Sideband v"+__version__+" "+__variant__ - self.open_conversations() Clock.schedule_interval(self.jobs, 1) + def keydown_event(self, instance, keyboard, keycode, text, modifiers): + if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "w" or text == "q"): + self.quit_action(self) + + def keyboard_event(self, window, key, *largs): + # Handle escape/back + if key == 27: + if self.root.ids.screen_manager.current == "conversations_screen": + if time.time() - self.last_exit_event < 2: + self.quit_action(self) + else: + self.last_exit_event = time.time() + + else: + self.open_conversations(direction="right") + + return True + def widget_hide(self, w, hide=True): if hasattr(w, "saved_attrs"): if not hide: @@ -277,6 +299,58 @@ class SidebandApp(MDApp): self.root.ids.screen_manager.current = "conversations_screen" self.root.ids.messages_scrollview.active_conversation = None + def connectivity_status(self, sender): + hs = dp(22) + connectivity_status = "" + if RNS.vendor.platformutils.get_platform() == "android": + if self.sideband.reticulum.is_connected_to_shared_instance: + connectivity_status = "[size=22dp][b]Connectivity Status[/b][/size]\n\nSideband is connected via a shared Reticulum instance running on this system. Use the rnstatus utility to obtain full connectivity info." + + else: + ws = "Disabled" + ts = "Disabled" + i2s = "Disabled" + + if self.sideband.interface_local != None: + np = len(self.sideband.interface_local.peers) + if np == 1: + ws = "1 reachable peer" + else: + ws = str(np)+" reachable peers" + + if self.sideband.interface_tcp != None: + if self.sideband.interface_tcp.online: + ts = "Connected to "+str(self.sideband.interface_tcp.target_ip)+":"+str(self.sideband.interface_tcp.target_port) + else: + ts = "Interface Down" + + if self.sideband.interface_i2p != None: + if self.sideband.interface_i2p.online: + i2s = "Connected" + else: + i2s = "Connecting to I2P" + + connectivity_status = "[size=22dp][b]Connectivity Status[/b][/size]\n\n[b]Local[/b]\n{ws}\n\n[b]TCP[/b]\n{ts}\n\n[b]I2P[/b]\n{i2s}".format(ws=ws, ts=ts, i2s=i2s) + + else: + if self.sideband.reticulum.is_connected_to_shared_instance: + connectivity_status = "[size=22dp][b]Connectivity Status[/b][/size]\n\nSideband is connected via a shared Reticulum instance running on this system. Use the rnstatus utility to obtain full connectivity info." + else: + connectivity_status = "[size=22dp][b]Connectivity Status[/b][/size]\n\nSideband is currently running a standalone or master Reticulum instance on this system. Use the rnstatus utility to obtain full connectivity info." + + yes_button = MDFlatButton( + text="OK", + ) + dialog = MDDialog( + text=connectivity_status, + buttons=[ yes_button ], + ) + def dl_yes(s): + dialog.dismiss() + + yes_button.bind(on_release=dl_yes) + dialog.open() + def lxmf_sync_action(self, sender): if self.sideband.message_router.get_outbound_propagation_node() == None: yes_button = MDFlatButton( diff --git a/sideband/core.py b/sideband/core.py index 6d55123..c30095a 100644 --- a/sideband/core.py +++ b/sideband/core.py @@ -777,8 +777,6 @@ class SidebandCore(): if self.config["connect_i2p"]: try: - RNS.log("Adding I2P Interface...") - if self.config["connect_i2p_b32"].endswith(".b32.i2p"): if self.config["connect_i2p_ifac_netname"] == "": @@ -801,16 +799,16 @@ class SidebandCore(): i2pinterface.OUT = True self.reticulum._add_interface(i2pinterface,ifac_netname=ifac_netname,ifac_netkey=ifac_netkey) - self.interface_i2p = i2pinterface + + for si in RNS.Transport.interfaces: + if type(si) == RNS.Interfaces.I2PInterface.I2PInterfacePeer: + self.interface_i2p = si except Exception as e: RNS.log("Error while adding I2P Interface. The contained exception was: "+str(e)) self.interface_i2p = None - - - RNS.log(str(RNS.Transport.interfaces)) self.message_router = LXMF.LXMRouter(identity = self.identity, storagepath = self.lxmf_storage, autopeer = True) self.message_router.register_delivery_callback(self.lxmf_delivery) diff --git a/ui/announces.py b/ui/announces.py index ce7a362..6905760 100644 --- a/ui/announces.py +++ b/ui/announces.py @@ -115,7 +115,7 @@ class Announces(): { "viewclass": "OneLineListItem", "text": "Converse", - "height": dp(64), + "height": dp(40), "on_release": gen_conv(context_dest, item) }, # { diff --git a/ui/conversations.py b/ui/conversations.py index ae39451..0e035b9 100644 --- a/ui/conversations.py +++ b/ui/conversations.py @@ -186,19 +186,19 @@ class Conversations(): { "viewclass": "OneLineListItem", "text": "Edit", - "height": dp(64), + "height": dp(40), "on_release": gen_edit(context_dest, item) }, { "text": "Clear Messages", "viewclass": "OneLineListItem", - "height": dp(64), + "height": dp(40), "on_release": gen_clear(context_dest, item) }, { "text": "Delete Conversation", "viewclass": "OneLineListItem", - "height": dp(64), + "height": dp(40), "on_release": gen_del(context_dest, item) } ] @@ -208,7 +208,7 @@ class Conversations(): item.dmenu = MDDropdownMenu( caller=item.iconr, items=dm_items, - position="center", + position="auto", width_mult=4, ) diff --git a/ui/layouts.py b/ui/layouts.py index fc0589d..b1d930c 100644 --- a/ui/layouts.py +++ b/ui/layouts.py @@ -10,14 +10,17 @@ MDNavigationLayout: BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: title: "Conversations" elevation: 10 pos_hint: {"top": 1} left_action_items: - [['menu', lambda x: nav_drawer.set_state("open")]] + [ + ['menu', lambda x: nav_drawer.set_state("open")], + ] right_action_items: [ + ['webhook', lambda x: root.ids.screen_manager.app.connectivity_status(self)], ['access-point', lambda x: root.ids.screen_manager.app.announce_now_action(self)], ['email-sync', lambda x: root.ids.screen_manager.app.lxmf_sync_action(self)], ['account-plus', lambda x: root.ids.screen_manager.app.new_conversation_action(self)], @@ -33,7 +36,7 @@ MDNavigationLayout: BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: id: messages_toolbar title: "Messages" elevation: 10 @@ -98,7 +101,7 @@ MDNavigationLayout: BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: title: "Local Broadcasts" elevation: 10 pos_hint: {"top": 1} @@ -130,7 +133,7 @@ MDNavigationLayout: BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: title: "Connectivity" elevation: 10 pos_hint: {"top": 1} @@ -318,7 +321,7 @@ MDNavigationLayout: BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: title: "Guide" elevation: 10 pos_hint: {"top": 1} @@ -350,7 +353,7 @@ MDNavigationLayout: BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: title: "App & Version Information" elevation: 10 pos_hint: {"top": 1} @@ -382,7 +385,7 @@ MDNavigationLayout: BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: title: "Local Area Map" elevation: 10 pos_hint: {"top": 1} @@ -414,7 +417,7 @@ MDNavigationLayout: BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: title: "Encryption Keys" elevation: 10 pos_hint: {"top": 1} @@ -446,7 +449,7 @@ MDNavigationLayout: BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: title: "Announce Stream" elevation: 10 pos_hint: {"top": 1} @@ -483,7 +486,7 @@ MDNavigationLayout: BoxLayout: orientation: "vertical" - MDToolbar: + MDTopAppBar: title: "Settings" elevation: 10 pos_hint: {"top": 1} diff --git a/ui/messages.py b/ui/messages.py index bc47e2e..7402ae3 100644 --- a/ui/messages.py +++ b/ui/messages.py @@ -166,13 +166,13 @@ class Messages(): { "viewclass": "OneLineListItem", "text": "Copy", - "height": dp(64), + "height": dp(40), "on_release": gen_copy(m["content"].decode("utf-8"), item) }, { "text": "Delete", "viewclass": "OneLineListItem", - "height": dp(64), + "height": dp(40), "on_release": gen_del(m["hash"], item) } ]