mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2024-11-29 08:40:36 +01:00
Improved settings saving
This commit is contained in:
parent
b716855d61
commit
5cc047c758
@ -313,7 +313,6 @@ class SidebandApp(MDApp):
|
|||||||
ok_button.bind(on_release=dl_ok)
|
ok_button.bind(on_release=dl_ok)
|
||||||
dialog.open()
|
dialog.open()
|
||||||
|
|
||||||
|
|
||||||
def on_pause(self):
|
def on_pause(self):
|
||||||
if self.sideband:
|
if self.sideband:
|
||||||
if self.sideband.getstate("flag.focusfix_pause"):
|
if self.sideband.getstate("flag.focusfix_pause"):
|
||||||
@ -1149,40 +1148,43 @@ class SidebandApp(MDApp):
|
|||||||
def settings_init(self, sender=None):
|
def settings_init(self, sender=None):
|
||||||
if not self.settings_ready:
|
if not self.settings_ready:
|
||||||
self.root.ids.settings_scrollview.effect_cls = ScrollEffect
|
self.root.ids.settings_scrollview.effect_cls = ScrollEffect
|
||||||
def save_disp_name(sender=None, event=None):
|
|
||||||
in_name = self.root.ids.settings_display_name.text
|
|
||||||
if in_name == "":
|
|
||||||
new_name = "Anonymous Peer"
|
|
||||||
else:
|
|
||||||
new_name = in_name
|
|
||||||
|
|
||||||
self.sideband.config["display_name"] = new_name
|
def save_disp_name(sender=None, event=None):
|
||||||
self.sideband.save_configuration()
|
if not sender.focus:
|
||||||
|
in_name = self.root.ids.settings_display_name.text
|
||||||
|
if in_name == "":
|
||||||
|
new_name = "Anonymous Peer"
|
||||||
|
else:
|
||||||
|
new_name = in_name
|
||||||
|
|
||||||
|
self.sideband.config["display_name"] = new_name
|
||||||
|
self.sideband.save_configuration()
|
||||||
|
|
||||||
def save_prop_addr(sender=None, event=None):
|
def save_prop_addr(sender=None, event=None):
|
||||||
in_addr = self.root.ids.settings_propagation_node_address.text
|
if not sender.focus:
|
||||||
|
in_addr = self.root.ids.settings_propagation_node_address.text
|
||||||
|
|
||||||
new_addr = None
|
|
||||||
if in_addr == "":
|
|
||||||
new_addr = None
|
new_addr = None
|
||||||
self.root.ids.settings_propagation_node_address.error = False
|
if in_addr == "":
|
||||||
else:
|
|
||||||
if len(in_addr) != RNS.Reticulum.TRUNCATED_HASHLENGTH//8*2:
|
|
||||||
new_addr = None
|
new_addr = None
|
||||||
else:
|
|
||||||
try:
|
|
||||||
new_addr = bytes.fromhex(in_addr)
|
|
||||||
except Exception as e:
|
|
||||||
new_addr = None
|
|
||||||
|
|
||||||
if new_addr == None:
|
|
||||||
self.root.ids.settings_propagation_node_address.error = True
|
|
||||||
else:
|
|
||||||
self.root.ids.settings_propagation_node_address.error = False
|
self.root.ids.settings_propagation_node_address.error = False
|
||||||
|
else:
|
||||||
|
if len(in_addr) != RNS.Reticulum.TRUNCATED_HASHLENGTH//8*2:
|
||||||
|
new_addr = None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
new_addr = bytes.fromhex(in_addr)
|
||||||
|
except Exception as e:
|
||||||
|
new_addr = None
|
||||||
|
|
||||||
|
if new_addr == None:
|
||||||
|
self.root.ids.settings_propagation_node_address.error = True
|
||||||
|
else:
|
||||||
|
self.root.ids.settings_propagation_node_address.error = False
|
||||||
|
|
||||||
|
|
||||||
self.sideband.config["lxmf_propagation_node"] = new_addr
|
self.sideband.config["lxmf_propagation_node"] = new_addr
|
||||||
self.sideband.set_active_propagation_node(self.sideband.config["lxmf_propagation_node"])
|
self.sideband.set_active_propagation_node(self.sideband.config["lxmf_propagation_node"])
|
||||||
|
|
||||||
def save_dark_ui(sender=None, event=None):
|
def save_dark_ui(sender=None, event=None):
|
||||||
self.sideband.config["dark_ui"] = self.root.ids.settings_dark_ui.active
|
self.sideband.config["dark_ui"] = self.root.ids.settings_dark_ui.active
|
||||||
@ -1206,15 +1208,16 @@ class SidebandApp(MDApp):
|
|||||||
self.sideband.save_configuration()
|
self.sideband.save_configuration()
|
||||||
|
|
||||||
def save_print_command(sender=None, event=None):
|
def save_print_command(sender=None, event=None):
|
||||||
in_cmd = self.root.ids.settings_print_command.text
|
if not sender.focus:
|
||||||
if in_cmd == "":
|
in_cmd = self.root.ids.settings_print_command.text
|
||||||
new_cmd = "lp"
|
if in_cmd == "":
|
||||||
else:
|
new_cmd = "lp"
|
||||||
new_cmd = in_cmd
|
else:
|
||||||
|
new_cmd = in_cmd
|
||||||
|
|
||||||
self.sideband.config["print_command"] = new_cmd.strip()
|
self.sideband.config["print_command"] = new_cmd.strip()
|
||||||
self.root.ids.settings_print_command.text = self.sideband.config["print_command"]
|
self.root.ids.settings_print_command.text = self.sideband.config["print_command"]
|
||||||
self.sideband.save_configuration()
|
self.sideband.save_configuration()
|
||||||
|
|
||||||
def save_lxmf_periodic_sync(sender=None, event=None, save=True):
|
def save_lxmf_periodic_sync(sender=None, event=None, save=True):
|
||||||
if self.root.ids.settings_lxmf_periodic_sync.active:
|
if self.root.ids.settings_lxmf_periodic_sync.active:
|
||||||
@ -1239,14 +1242,12 @@ class SidebandApp(MDApp):
|
|||||||
self.root.ids.settings_identity_hash.text = RNS.hexrep(self.sideband.lxmf_destination.identity.hash, delimit=False)
|
self.root.ids.settings_identity_hash.text = RNS.hexrep(self.sideband.lxmf_destination.identity.hash, delimit=False)
|
||||||
|
|
||||||
self.root.ids.settings_display_name.text = self.sideband.config["display_name"]
|
self.root.ids.settings_display_name.text = self.sideband.config["display_name"]
|
||||||
self.root.ids.settings_display_name.bind(on_text_validate=save_disp_name)
|
|
||||||
self.root.ids.settings_display_name.bind(focus=save_disp_name)
|
self.root.ids.settings_display_name.bind(focus=save_disp_name)
|
||||||
|
|
||||||
if RNS.vendor.platformutils.is_android():
|
if RNS.vendor.platformutils.is_android():
|
||||||
self.widget_hide(self.root.ids.settings_print_command, True)
|
self.widget_hide(self.root.ids.settings_print_command, True)
|
||||||
else:
|
else:
|
||||||
self.root.ids.settings_print_command.text = self.sideband.config["print_command"]
|
self.root.ids.settings_print_command.text = self.sideband.config["print_command"]
|
||||||
self.root.ids.settings_print_command.bind(on_text_validate=save_print_command)
|
|
||||||
self.root.ids.settings_print_command.bind(focus=save_print_command)
|
self.root.ids.settings_print_command.bind(focus=save_print_command)
|
||||||
|
|
||||||
if self.sideband.config["lxmf_propagation_node"] == None:
|
if self.sideband.config["lxmf_propagation_node"] == None:
|
||||||
@ -1255,7 +1256,6 @@ class SidebandApp(MDApp):
|
|||||||
prop_node_addr = RNS.hexrep(self.sideband.config["lxmf_propagation_node"], delimit=False)
|
prop_node_addr = RNS.hexrep(self.sideband.config["lxmf_propagation_node"], delimit=False)
|
||||||
|
|
||||||
self.root.ids.settings_propagation_node_address.text = prop_node_addr
|
self.root.ids.settings_propagation_node_address.text = prop_node_addr
|
||||||
self.root.ids.settings_propagation_node_address.bind(on_text_validate=save_prop_addr)
|
|
||||||
self.root.ids.settings_propagation_node_address.bind(focus=save_prop_addr)
|
self.root.ids.settings_propagation_node_address.bind(focus=save_prop_addr)
|
||||||
|
|
||||||
if not RNS.vendor.platformutils.is_android() or android_api_version >= 26:
|
if not RNS.vendor.platformutils.is_android() or android_api_version >= 26:
|
||||||
|
@ -124,6 +124,7 @@ class SidebandCore():
|
|||||||
self.exports_dir = self.app_dir+"/exports"
|
self.exports_dir = self.app_dir+"/exports"
|
||||||
|
|
||||||
self.first_run = True
|
self.first_run = True
|
||||||
|
self.saving_configuration = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.isfile(self.config_path):
|
if not os.path.isfile(self.config_path):
|
||||||
@ -409,9 +410,20 @@ class SidebandCore():
|
|||||||
|
|
||||||
def __save_config(self):
|
def __save_config(self):
|
||||||
RNS.log("Saving Sideband configuration...", RNS.LOG_DEBUG)
|
RNS.log("Saving Sideband configuration...", RNS.LOG_DEBUG)
|
||||||
config_file = open(self.config_path, "wb")
|
def save_function():
|
||||||
config_file.write(msgpack.packb(self.config))
|
while self.saving_configuration:
|
||||||
config_file.close()
|
time.sleep(0.15)
|
||||||
|
try:
|
||||||
|
self.saving_configuration = True
|
||||||
|
config_file = open(self.config_path, "wb")
|
||||||
|
config_file.write(msgpack.packb(self.config))
|
||||||
|
config_file.close()
|
||||||
|
self.saving_configuration = False
|
||||||
|
except Exception as e:
|
||||||
|
self.saving_configuration = False
|
||||||
|
RNS.log("Error while saving Sideband configuration: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
|
threading.Thread(target=save_function, daemon=True).start()
|
||||||
|
|
||||||
if self.is_client:
|
if self.is_client:
|
||||||
self.setstate("wants.settings_reload", True)
|
self.setstate("wants.settings_reload", True)
|
||||||
|
Loading…
Reference in New Issue
Block a user