Fixed erroneous error display

This commit is contained in:
Mark Qvist 2023-11-04 19:42:06 +01:00
parent 61347e9451
commit c0133407ed
3 changed files with 180 additions and 166 deletions

View File

@ -1,4 +1,4 @@
__debug_build__ = False __debug_build__ = True
__disable_shaders__ = False __disable_shaders__ = False
__version__ = "0.7.2" __version__ = "0.7.2"
__variant__ = "beta" __variant__ = "beta"
@ -438,10 +438,6 @@ class SidebandApp(MDApp):
def on_pause(self): def on_pause(self):
if self.sideband: if self.sideband:
if self.sideband.getstate("flag.focusfix_pause"):
self.sideband.setstate("flag.focusfix_pause", False)
return True
else:
RNS.log("App pausing...", RNS.LOG_DEBUG) RNS.log("App pausing...", RNS.LOG_DEBUG)
self.sideband.setstate("app.running", True) self.sideband.setstate("app.running", True)
self.sideband.setstate("app.foreground", False) self.sideband.setstate("app.foreground", False)
@ -458,10 +454,6 @@ class SidebandApp(MDApp):
def on_resume(self): def on_resume(self):
if self.sideband: if self.sideband:
if self.sideband.getstate("flag.focusfix_resume"):
self.sideband.setstate("flag.focusfix_resume", False)
return True
else:
RNS.log("App resuming...", RNS.LOG_DEBUG) RNS.log("App resuming...", RNS.LOG_DEBUG)
self.sideband.setstate("app.running", True) self.sideband.setstate("app.running", True)
self.sideband.setstate("app.foreground", True) self.sideband.setstate("app.foreground", True)
@ -728,14 +720,18 @@ class SidebandApp(MDApp):
if self.conversations_view != None: if self.conversations_view != None:
self.conversations_view.update() self.conversations_view.update()
invalid_values = ["None", "False", "True", True, False, None]
imr = self.sideband.getstate("lxm_uri_ingest.result", allow_cache=True) imr = self.sideband.getstate("lxm_uri_ingest.result", allow_cache=True)
if imr and imr != "None" and imr != "False": if imr:
if imr in invalid_values:
self.sideband.setstate("lxm_uri_ingest.result", False)
else:
info_text = str(imr) info_text = str(imr)
self.sideband.setstate("lxm_uri_ingest.result", False) self.sideband.setstate("lxm_uri_ingest.result", False)
ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18)) ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18))
dialog = MDDialog( dialog = MDDialog(
title="Message Scan", title="Message Scan",
text=str(info_text), text=info_text,
buttons=[ ok_button ], buttons=[ ok_button ],
# elevation=0, # elevation=0,
) )
@ -745,14 +741,18 @@ class SidebandApp(MDApp):
ok_button.bind(on_release=dl_ok) ok_button.bind(on_release=dl_ok)
dialog.open() dialog.open()
invalid_values = ["None", "False", "True", True, False, None]
hwe = self.sideband.getstate("hardware_operation.error", allow_cache=True) hwe = self.sideband.getstate("hardware_operation.error", allow_cache=True)
if hwe and hwe != "None" and hwe != "False": if hwe:
if hwe in invalid_values:
self.sideband.setstate("hardware_operation.error", False)
else:
info_text = str(hwe) info_text = str(hwe)
self.sideband.setstate("hardware_operation.error", False) self.sideband.setstate("hardware_operation.error", False)
ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18)) ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18))
dialog = MDDialog( dialog = MDDialog(
title="Error", title="Error",
text=str(info_text), text=info_text,
buttons=[ ok_button ], buttons=[ ok_button ],
# elevation=0, # elevation=0,
) )
@ -966,6 +966,7 @@ class SidebandApp(MDApp):
while self.sideband.service_available(): while self.sideband.service_available():
time.sleep(0.2) time.sleep(0.2)
RNS.log("Service stopped") RNS.log("Service stopped")
self.sideband.service_stopped = True
if RNS.vendor.platformutils.is_android(): if RNS.vendor.platformutils.is_android():
RNS.log("Finishing activity") RNS.log("Finishing activity")
@ -1594,7 +1595,6 @@ class SidebandApp(MDApp):
te = ids[e] te = ids[e]
ts = str(te).split(" ")[0].replace("<", "") ts = str(te).split(" ")[0].replace("<", "")
if ts in BIND_CLASSES and not hasattr(e, "no_clipboard"): if ts in BIND_CLASSES and not hasattr(e, "no_clipboard"):
RNS.log("Binding clipboard action to "+str(e))
te.bind(on_double_tap=self.ui_clipboard_action) te.bind(on_double_tap=self.ui_clipboard_action)
def settings_init(self, sender=None): def settings_init(self, sender=None):

View File

@ -1,4 +1,4 @@
__debug_build__ = False __debug_build__ = True
import sys import sys
import time import time
@ -351,6 +351,7 @@ class SidebandService():
self.sideband.setstate("service.connectivity_status", self.get_connectivity_status()) self.sideband.setstate("service.connectivity_status", self.get_connectivity_status())
if self.sideband.getstate("wants.service_stop"): if self.sideband.getstate("wants.service_stop"):
self.sideband.service_stopped = True
self.should_run = False self.should_run = False
sleep_time = 0 sleep_time = 0

View File

@ -13,6 +13,7 @@ import RNS.Interfaces.Interface as Interface
import multiprocessing.connection import multiprocessing.connection
from threading import Lock
from .res import sideband_fb_data from .res import sideband_fb_data
from .sense import Telemeter, Commands from .sense import Telemeter, Commands
@ -128,7 +129,9 @@ class SidebandCore():
self.pending_telemetry_request = False self.pending_telemetry_request = False
self.telemetry_request_max_history = 7*24*60*60 self.telemetry_request_max_history = 7*24*60*60
self.state_db = {} self.state_db = {}
self.state_lock = Lock()
self.rpc_connection = None self.rpc_connection = None
self.service_stopped = False
self.app_dir = plyer.storagepath.get_home_dir()+"/.config/sideband" self.app_dir = plyer.storagepath.get_home_dir()+"/.config/sideband"
self.cache_dir = self.app_dir+"/cache" self.cache_dir = self.app_dir+"/cache"
@ -179,8 +182,6 @@ class SidebandCore():
self.interface_local_adding = False self.interface_local_adding = False
self.next_auto_announce = time.time() + 60*(random.random()*(SidebandCore.AUTO_ANNOUNCE_RANDOM_MAX-SidebandCore.AUTO_ANNOUNCE_RANDOM_MIN)) self.next_auto_announce = time.time() + 60*(random.random()*(SidebandCore.AUTO_ANNOUNCE_RANDOM_MAX-SidebandCore.AUTO_ANNOUNCE_RANDOM_MIN))
self.getstate_cache = {}
try: try:
if not os.path.isfile(self.config_path): if not os.path.isfile(self.config_path):
self.__init_config() self.__init_config()
@ -1149,6 +1150,7 @@ class SidebandCore():
return True return True
except Exception as e: except Exception as e:
RNS.log("Error while getting service heartbeat: "+str(e), RNS.LOG_ERROR) RNS.log("Error while getting service heartbeat: "+str(e), RNS.LOG_ERROR)
RNS.log("Response was: "+str(service_heartbeat), RNS.LOG_ERROR)
return False return False
def gui_foreground(self): def gui_foreground(self):
@ -1161,9 +1163,11 @@ class SidebandCore():
return self.getstate("app.active_conversation") return self.getstate("app.active_conversation")
def setstate(self, prop, val): def setstate(self, prop, val):
with self.state_lock:
if not self.service_stopped:
if not RNS.vendor.platformutils.is_android(): if not RNS.vendor.platformutils.is_android():
self.getstate_cache[prop] = val self.state_db[prop] = val
self._db_setstate(prop, val) return True
else: else:
if self.is_service: if self.is_service:
self.state_db[prop] = val self.state_db[prop] = val
@ -1227,11 +1231,16 @@ class SidebandCore():
return False return False
def getstate(self, prop, allow_cache=False): def getstate(self, prop, allow_cache=False):
with self.state_lock:
if not self.service_stopped:
# TODO: remove # TODO: remove
# us = time.time() # us = time.time()
if not RNS.vendor.platformutils.is_android(): if not RNS.vendor.platformutils.is_android():
return self._db_getstate(prop) if prop in self.state_db:
return self.state_db[prop]
else:
return None
else: else:
if self.is_service: if self.is_service:
if prop in self.state_db: if prop in self.state_db:
@ -1293,7 +1302,11 @@ class SidebandCore():
except Exception as e: except Exception as e:
RNS.log("Error on client RPC connection: "+str(e), RNS.LOG_ERROR) RNS.log("Error on client RPC connection: "+str(e), RNS.LOG_ERROR)
try:
connection.close() connection.close()
except:
pass
return rpc_client_job return rpc_client_job
threading.Thread(target=job_factory(rpc_connection), daemon=True).start() threading.Thread(target=job_factory(rpc_connection), daemon=True).start()
@ -1373,74 +1386,74 @@ class SidebandCore():
db.commit() db.commit()
def _db_initstate(self): def _db_initstate(self):
db = self.__db_connect() # db = self.__db_connect()
dbc = db.cursor() # dbc = db.cursor()
dbc.execute("DROP TABLE IF EXISTS state") # dbc.execute("DROP TABLE IF EXISTS state")
dbc.execute("CREATE TABLE state (property BLOB PRIMARY KEY, value BLOB)") # dbc.execute("CREATE TABLE state (property BLOB PRIMARY KEY, value BLOB)")
db.commit() # db.commit()
self._db_setstate("database_ready", True) self.setstate("database_ready", True)
def _db_getstate(self, prop): # def _db_getstate(self, prop):
try: # try:
db = self.__db_connect() # db = self.__db_connect()
dbc = db.cursor() # dbc = db.cursor()
query = "select * from state where property=:uprop" # query = "select * from state where property=:uprop"
dbc.execute(query, {"uprop": prop.encode("utf-8")}) # dbc.execute(query, {"uprop": prop.encode("utf-8")})
result = dbc.fetchall() # result = dbc.fetchall()
if len(result) < 1: # if len(result) < 1:
return None # return None
else: # else:
try: # try:
entry = result[0] # entry = result[0]
val = msgpack.unpackb(entry[1]) # val = msgpack.unpackb(entry[1])
return val # return val
except Exception as e: # except Exception as e:
RNS.log("Could not unpack state value from database for property \""+str(prop)+"\". The contained exception was: "+str(e), RNS.LOG_ERROR) # RNS.log("Could not unpack state value from database for property \""+str(prop)+"\". The contained exception was: "+str(e), RNS.LOG_ERROR)
return None # return None
except Exception as e: # except Exception as e:
RNS.log("An error occurred during getstate database operation: "+str(e), RNS.LOG_ERROR) # RNS.log("An error occurred during getstate database operation: "+str(e), RNS.LOG_ERROR)
self.db = None # self.db = None
def _db_setstate(self, prop, val): # def _db_setstate(self, prop, val):
try: # try:
uprop = prop.encode("utf-8") # uprop = prop.encode("utf-8")
bval = msgpack.packb(val) # bval = msgpack.packb(val)
if self._db_getstate(prop) == None: # if self._db_getstate(prop) == None:
try: # try:
db = self.__db_connect() # db = self.__db_connect()
dbc = db.cursor() # dbc = db.cursor()
query = "INSERT INTO state (property, value) values (?, ?)" # query = "INSERT INTO state (property, value) values (?, ?)"
data = (uprop, bval) # data = (uprop, bval)
dbc.execute(query, data) # dbc.execute(query, data)
db.commit() # db.commit()
except Exception as e: # except Exception as e:
RNS.log("Error while setting state property "+str(prop)+" in DB: "+str(e), RNS.LOG_ERROR) # RNS.log("Error while setting state property "+str(prop)+" in DB: "+str(e), RNS.LOG_ERROR)
RNS.log("Retrying as update query...", RNS.LOG_ERROR) # RNS.log("Retrying as update query...", RNS.LOG_ERROR)
db = self.__db_connect() # db = self.__db_connect()
dbc = db.cursor() # dbc = db.cursor()
query = "UPDATE state set value=:bval where property=:uprop;" # query = "UPDATE state set value=:bval where property=:uprop;"
dbc.execute(query, {"bval": bval, "uprop": uprop}) # dbc.execute(query, {"bval": bval, "uprop": uprop})
db.commit() # db.commit()
else: # else:
db = self.__db_connect() # db = self.__db_connect()
dbc = db.cursor() # dbc = db.cursor()
query = "UPDATE state set value=:bval where property=:uprop;" # query = "UPDATE state set value=:bval where property=:uprop;"
dbc.execute(query, {"bval": bval, "uprop": uprop}) # dbc.execute(query, {"bval": bval, "uprop": uprop})
db.commit() # db.commit()
except Exception as e: # except Exception as e:
RNS.log("An error occurred during setstate database operation: "+str(e), RNS.LOG_ERROR) # RNS.log("An error occurred during setstate database operation: "+str(e), RNS.LOG_ERROR)
self.db = None # self.db = None
def _db_initpersistent(self): def _db_initpersistent(self):
db = self.__db_connect() db = self.__db_connect()
@ -3369,7 +3382,7 @@ class SidebandCore():
thread.setDaemon(True) thread.setDaemon(True)
thread.start() thread.start()
self._db_setstate("core.started", True) self.setstate("core.started", True)
RNS.log("Sideband Core "+str(self)+" started") RNS.log("Sideband Core "+str(self)+" started")
def stop_webshare(self): def stop_webshare(self):