Added periodic sync. Improved sync dialog UI.

This commit is contained in:
Mark Qvist 2022-10-08 22:47:08 +02:00
parent d5231da5bb
commit 7df2a69b4b
3 changed files with 91 additions and 13 deletions

View File

@ -1,3 +1,4 @@
# TODO: Reset
__debug_build__ = True __debug_build__ = True
__disable_shaders__ = True __disable_shaders__ = True
__version__ = "0.2.2" __version__ = "0.2.2"
@ -65,9 +66,10 @@ else:
from .ui.messages import Messages, ts_format from .ui.messages import Messages, ts_format
from .ui.helpers import ContentNavigationDrawer, DrawerList, IconListItem from .ui.helpers import ContentNavigationDrawer, DrawerList, IconListItem
from kivy.metrics import dp from kivy.metrics import dp, sp
from kivymd.uix.button import MDFlatButton from kivymd.uix.button import MDFlatButton, MDRectangleFlatButton
from kivymd.uix.dialog import MDDialog from kivymd.uix.dialog import MDDialog
from kivymd.color_definitions import colors
dark_theme_text_color = "ddd" dark_theme_text_color = "ddd"
@ -178,12 +180,24 @@ class SidebandApp(MDApp):
else: else:
self.theme_cls.theme_style = "Light" self.theme_cls.theme_style = "Light"
self.update_ui_colors()
def update_ui_colors(self):
if self.sideband.config["dark_ui"]:
self.color_reject = colors["DeepOrange"]["900"]
self.color_accept = colors["LightGreen"]["700"]
else:
self.color_reject = colors["DeepOrange"]["800"]
self.color_accept = colors["LightGreen"]["700"]
def update_ui_theme(self): def update_ui_theme(self):
if self.sideband.config["dark_ui"]: if self.sideband.config["dark_ui"]:
self.theme_cls.theme_style = "Dark" self.theme_cls.theme_style = "Dark"
else: else:
self.theme_cls.theme_style = "Light" self.theme_cls.theme_style = "Light"
self.update_ui_colors()
st = time.time() st = time.time()
RNS.log("Recursing widgets...") RNS.log("Recursing widgets...")
for wid in self.root.ids: for wid in self.root.ids:
@ -311,6 +325,12 @@ class SidebandApp(MDApp):
self.sync_dialog.ids.sync_progress.value = self.sideband.get_sync_progress()*100 self.sync_dialog.ids.sync_progress.value = self.sideband.get_sync_progress()*100
self.sync_dialog.ids.sync_status.text = self.sideband.get_sync_status() self.sync_dialog.ids.sync_status.text = self.sideband.get_sync_status()
state = self.sideband.message_router.propagation_transfer_state
if state > LXMF.LXMRouter.PR_IDLE and state < LXMF.LXMRouter.PR_COMPLETE:
self.widget_hide(self.sync_dialog.stop_button, False)
else:
self.widget_hide(self.sync_dialog.stop_button, True)
elif self.root.ids.screen_manager.current == "announces_screen": elif self.root.ids.screen_manager.current == "announces_screen":
if self.sideband.getstate("app.flags.new_announces"): if self.sideband.getstate("app.flags.new_announces"):
if self.announces_view != None: if self.announces_view != None:
@ -674,27 +694,40 @@ class SidebandApp(MDApp):
else: else:
sl = None sl = None
self.sideband.setpersistent("lxmf.lastsync", time.time())
self.sideband.setpersistent("lxmf.syncretrying", False)
self.sideband.request_lxmf_sync(limit=sl) self.sideband.request_lxmf_sync(limit=sl)
close_button = MDFlatButton(text="Close", font_size=dp(20)) # , font_size=dp(20)
# stop_button = MDFlatButton(text="Stop", font_size=dp(20)) close_button = MDRectangleFlatButton(text="Close",font_size=sp(18))
stop_button = MDRectangleFlatButton(text="Stop",font_size=sp(18), theme_text_color="Custom", line_color=self.color_reject, text_color=self.color_reject)
dialog_content = MsgSync() dialog_content = MsgSync()
dialog = MDDialog( dialog = MDDialog(
title="LXMF Sync via "+RNS.prettyhexrep(self.sideband.message_router.get_outbound_propagation_node()), title="LXMF Sync via "+RNS.prettyhexrep(self.sideband.message_router.get_outbound_propagation_node()),
type="custom", type="custom",
content_cls=dialog_content, content_cls=dialog_content,
buttons=[ close_button ], buttons=[ stop_button, close_button ],
# elevation=0, # elevation=0,
) )
dialog.d_content = dialog_content dialog.d_content = dialog_content
def dl_close(s): def dl_close(s):
self.sideband.setstate("app.flags.lxmf_sync_dialog_open", False) self.sideband.setstate("app.flags.lxmf_sync_dialog_open", False)
dialog.dismiss() dialog.dismiss()
# self.sideband.cancel_lxmf_sync()
def dl_stop(s):
# self.sideband.setstate("app.flags.lxmf_sync_dialog_open", False)
# dialog.dismiss()
self.sideband.cancel_lxmf_sync() self.sideband.cancel_lxmf_sync()
def cb(dt):
self.widget_hide(self.sync_dialog.stop_button, True)
Clock.schedule_once(cb, 0.25)
close_button.bind(on_release=dl_close) close_button.bind(on_release=dl_close)
stop_button.bind(on_release=dl_stop)
self.sideband.setstate("app.flags.lxmf_sync_dialog_open", True) self.sideband.setstate("app.flags.lxmf_sync_dialog_open", True)
self.sync_dialog = dialog_content self.sync_dialog = dialog_content
self.sync_dialog.stop_button = stop_button
dialog.open() dialog.open()
dialog_content.ids.sync_progress.value = self.sideband.get_sync_progress()*100 dialog_content.ids.sync_progress.value = self.sideband.get_sync_progress()*100
dialog_content.ids.sync_status.text = self.sideband.get_sync_status() dialog_content.ids.sync_status.text = self.sideband.get_sync_status()
@ -854,6 +887,7 @@ class SidebandApp(MDApp):
self.root.ids.settings_lxmf_sync_periodic.text = "Auto sync every "+interval_text self.root.ids.settings_lxmf_sync_periodic.text = "Auto sync every "+interval_text
if pre != self.root.ids.settings_lxmf_sync_periodic.text: if pre != self.root.ids.settings_lxmf_sync_periodic.text:
if save: if save:
self.sideband.config["lxmf_sync_interval"] = interval
self.sideband.save_configuration() self.sideband.save_configuration()
self.root.ids.settings_lxmf_address.text = RNS.hexrep(self.sideband.lxmf_destination.hash, delimit=False) self.root.ids.settings_lxmf_address.text = RNS.hexrep(self.sideband.lxmf_destination.hash, delimit=False)

View File

@ -63,7 +63,9 @@ class SidebandCore():
MAX_ANNOUNCES = 24 MAX_ANNOUNCES = 24
JOB_INTERVAL = 1 SERVICE_JOB_INTERVAL = 1
PERIODIC_JOBS_INTERVAL = 60
PERIODIC_SYNC_RETRY = 360
aspect_filter = "lxmf.delivery" aspect_filter = "lxmf.delivery"
def received_announce(self, destination_hash, announced_identity, app_data): def received_announce(self, destination_hash, announced_identity, app_data):
@ -929,10 +931,46 @@ class SidebandCore():
def _service_jobs(self): def _service_jobs(self):
if self.is_service: if self.is_service:
while True: while True:
time.sleep(SidebandCore.JOB_INTERVAL) time.sleep(SidebandCore.SERVICE_JOB_INTERVAL)
if self.getstate("wants.announce"): if self.getstate("wants.announce"):
self.lxmf_announce() self.lxmf_announce()
def _periodic_jobs(self):
if self.is_service or self.is_standalone:
while True:
time.sleep(SidebandCore.PERIODIC_JOBS_INTERVAL)
if self.config["lxmf_periodic_sync"] == True:
if self.getpersistent("lxmf.lastsync") == None:
# TODO: Remove
RNS.log("Lastsync was none, setting now as initial", RNS.LOG_DEBUG)
self.setpersistent("lxmf.lastsync", time.time())
else:
now = time.time()
syncinterval = self.config["lxmf_sync_interval"]
lastsync = self.getpersistent("lxmf.lastsync")
nextsync = lastsync+syncinterval
RNS.log("Last sync was "+RNS.prettytime(now-lastsync)+" ago", RNS.LOG_DEBUG)
RNS.log("Next sync is "+("in "+RNS.prettytime(nextsync-now) if nextsync-now > 0 else "now"), RNS.LOG_DEBUG)
if now > nextsync:
# TODO: Remove
RNS.log("Syncing now...", RNS.LOG_DEBUG)
if self.request_lxmf_sync():
RNS.log("Scheduled LXMF sync succeeded", RNS.LOG_DEBUG)
self.setpersistent("lxmf.lastsync", time.time())
self.setpersistent("lxmf.syncretrying", False)
else:
if not self.getpersistent("lxmf.syncretrying"):
RNS.log("Scheduled LXMF sync failed, retrying in "+RNS.prettytime(SidebandCore.PERIODIC_SYNC_RETRY), RNS.LOG_DEBUG)
self.setpersistent("lxmf.lastsync", lastsync+SidebandCore.PERIODIC_SYNC_RETRY)
self.setpersistent("lxmf.syncretrying", True)
else:
RNS.log("Retry of scheduled LXMF sync failed too, waiting until next scheduled sync to try again", RNS.LOG_DEBUG)
self.setpersistent("lxmf.lastsync", time.time())
self.setpersistent("lxmf.syncretrying", False)
def __start_jobs_deferred(self): def __start_jobs_deferred(self):
if self.config["start_announce"]: if self.config["start_announce"]:
self.lxmf_announce() self.lxmf_announce()
@ -940,6 +978,10 @@ class SidebandCore():
if self.is_service: if self.is_service:
self.service_thread = threading.Thread(target=self._service_jobs, daemon=True) self.service_thread = threading.Thread(target=self._service_jobs, daemon=True)
self.service_thread.start() self.service_thread.start()
if self.is_standalone or self.is_service:
self.periodic_thread = threading.Thread(target=self._periodic_jobs, daemon=True)
self.periodic_thread.start()
def __start_jobs_immediate(self): def __start_jobs_immediate(self):
if self.log_verbose: if self.log_verbose:

View File

@ -71,13 +71,14 @@ MDNavigationLayout:
MDIconButton: MDIconButton:
pos_hint: {"center_x": .5, "center_y": .5} pos_hint: {"center_x": .5, "center_y": .5}
icon: "close-network-outline" # icon: "close-network-outline"
icon: "waves"
icon_size: "72dp" icon_size: "72dp"
MDLabel: MDLabel:
id: connecting_info id: connecting_info
halign: "center" halign: "center"
text: "Shutting down..." text: "Dissolving Reticulum"
font_size: "32dp" font_size: "32dp"
size_hint_y: None size_hint_y: None
text_size: self.width, None text_size: self.width, None
@ -1117,17 +1118,18 @@ MDNavigationLayout:
orientation: "vertical" orientation: "vertical"
spacing: "24dp" spacing: "24dp"
size_hint_y: None size_hint_y: None
padding: [0, 0, 0, dp(16)]
height: self.minimum_height+dp(24) height: self.minimum_height+dp(24)
MDProgressBar:
id: sync_progress
value: 0
MDLabel: MDLabel:
id: sync_status id: sync_status
hint_text: "Name" hint_text: "Name"
text: "Initiating sync..." text: "Initiating sync..."
MDProgressBar:
id: sync_progress
value: 0
<ConvSettings> <ConvSettings>
orientation: "vertical" orientation: "vertical"
spacing: "24dp" spacing: "24dp"