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,43 +438,35 @@ class SidebandApp(MDApp):
def on_pause(self): def on_pause(self):
if self.sideband: if self.sideband:
if self.sideband.getstate("flag.focusfix_pause"): RNS.log("App pausing...", RNS.LOG_DEBUG)
self.sideband.setstate("flag.focusfix_pause", False) self.sideband.setstate("app.running", True)
return True self.sideband.setstate("app.foreground", False)
else: self.app_state = SidebandApp.PAUSED
RNS.log("App pausing...", RNS.LOG_DEBUG) self.sideband.should_persist_data()
self.sideband.setstate("app.running", True) if self.conversations_view != None:
self.sideband.setstate("app.foreground", False) self.conversations_view.ids.conversations_scrollview.effect_cls = ScrollEffect
self.app_state = SidebandApp.PAUSED self.conversations_view.ids.conversations_scrollview.scroll = 1
self.sideband.should_persist_data()
if self.conversations_view != None:
self.conversations_view.ids.conversations_scrollview.effect_cls = ScrollEffect
self.conversations_view.ids.conversations_scrollview.scroll = 1
RNS.log("App paused", RNS.LOG_DEBUG) RNS.log("App paused", RNS.LOG_DEBUG)
return True return True
else: else:
return True return True
def on_resume(self): def on_resume(self):
if self.sideband: if self.sideband:
if self.sideband.getstate("flag.focusfix_resume"): RNS.log("App resuming...", RNS.LOG_DEBUG)
self.sideband.setstate("flag.focusfix_resume", False) self.sideband.setstate("app.running", True)
return True self.sideband.setstate("app.foreground", True)
self.sideband.setstate("wants.clear_notifications", True)
self.app_state = SidebandApp.ACTIVE
if self.conversations_view != None:
self.conversations_view.ids.conversations_scrollview.effect_cls = ScrollEffect
self.conversations_view.ids.conversations_scrollview.scroll = 1
else: else:
RNS.log("App resuming...", RNS.LOG_DEBUG) RNS.log("Conversations view did not exist", RNS.LOG_DEBUG)
self.sideband.setstate("app.running", True)
self.sideband.setstate("app.foreground", True)
self.sideband.setstate("wants.clear_notifications", True)
self.app_state = SidebandApp.ACTIVE
if self.conversations_view != None:
self.conversations_view.ids.conversations_scrollview.effect_cls = ScrollEffect
self.conversations_view.ids.conversations_scrollview.scroll = 1
else: RNS.log("App resumed", RNS.LOG_DEBUG)
RNS.log("Conversations view did not exist", RNS.LOG_DEBUG)
RNS.log("App resumed", RNS.LOG_DEBUG)
def on_stop(self): def on_stop(self):
RNS.log("App stopping...", RNS.LOG_DEBUG) RNS.log("App stopping...", RNS.LOG_DEBUG)
@ -728,39 +720,47 @@ 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:
info_text = str(imr) if imr in invalid_values:
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)) else:
dialog = MDDialog( info_text = str(imr)
title="Message Scan", self.sideband.setstate("lxm_uri_ingest.result", False)
text=str(info_text), ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18))
buttons=[ ok_button ], dialog = MDDialog(
# elevation=0, title="Message Scan",
) text=info_text,
def dl_ok(s): buttons=[ ok_button ],
dialog.dismiss() # elevation=0,
)
def dl_ok(s):
dialog.dismiss()
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:
info_text = str(hwe) if hwe in invalid_values:
self.sideband.setstate("hardware_operation.error", False) self.sideband.setstate("hardware_operation.error", False)
ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18)) else:
dialog = MDDialog( info_text = str(hwe)
title="Error", self.sideband.setstate("hardware_operation.error", False)
text=str(info_text), ok_button = MDRectangleFlatButton(text="OK",font_size=dp(18))
buttons=[ ok_button ], dialog = MDDialog(
# elevation=0, title="Error",
) text=info_text,
def dl_ok(s): buttons=[ ok_button ],
dialog.dismiss() # elevation=0,
)
def dl_ok(s):
dialog.dismiss()
ok_button.bind(on_release=dl_ok) ok_button.bind(on_release=dl_ok)
dialog.open() dialog.open()
def on_start(self): def on_start(self):
self.last_exit_event = time.time() self.last_exit_event = time.time()
@ -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,30 +1163,32 @@ class SidebandCore():
return self.getstate("app.active_conversation") return self.getstate("app.active_conversation")
def setstate(self, prop, val): def setstate(self, prop, val):
if not RNS.vendor.platformutils.is_android(): with self.state_lock:
self.getstate_cache[prop] = val if not self.service_stopped:
self._db_setstate(prop, val) if not RNS.vendor.platformutils.is_android():
else: self.state_db[prop] = val
if self.is_service: return True
self.state_db[prop] = val else:
return True if self.is_service:
else: self.state_db[prop] = val
def set(): return True
if self.rpc_connection == None: else:
self.rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key) def set():
self.rpc_connection.send({"setstate": (prop, val)}) if self.rpc_connection == None:
response = self.rpc_connection.recv() self.rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
return response self.rpc_connection.send({"setstate": (prop, val)})
response = self.rpc_connection.recv()
return response
try: try:
set() set()
except Exception as e: except Exception as e:
RNS.log("Error while setting state over RPC: "+str(e)+". Retrying once.", RNS.LOG_DEBUG) RNS.log("Error while setting state over RPC: "+str(e)+". Retrying once.", RNS.LOG_DEBUG)
try: try:
set() set()
except Exception as e: except Exception as e:
RNS.log("Error on retry as well: "+str(e)+". Giving up.", RNS.LOG_DEBUG) RNS.log("Error on retry as well: "+str(e)+". Giving up.", RNS.LOG_DEBUG)
return False return False
def service_set_latest_telemetry(self, latest_telemetry, latest_packed_telemetry): def service_set_latest_telemetry(self, latest_telemetry, latest_packed_telemetry):
if not RNS.vendor.platformutils.is_android(): if not RNS.vendor.platformutils.is_android():
@ -1227,31 +1231,36 @@ class SidebandCore():
return False return False
def getstate(self, prop, allow_cache=False): def getstate(self, prop, allow_cache=False):
# TODO: remove with self.state_lock:
# us = time.time() if not self.service_stopped:
# TODO: remove
# 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:
else: return self.state_db[prop]
if self.is_service: else:
if prop in self.state_db: return None
return self.state_db[prop]
else: else:
return None if self.is_service:
else: if prop in self.state_db:
try: return self.state_db[prop]
if self.rpc_connection == None: else:
self.rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key) return None
self.rpc_connection.send({"getstate": prop}) else:
response = self.rpc_connection.recv() try:
# TODO: Remove if self.rpc_connection == None:
# RNS.log("RPC getstate result for "+str(prop)+"="+str(response)+" in "+RNS.prettytime(time.time()-us), RNS.LOG_WARNING) self.rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
return response self.rpc_connection.send({"getstate": prop})
response = self.rpc_connection.recv()
# TODO: Remove
# RNS.log("RPC getstate result for "+str(prop)+"="+str(response)+" in "+RNS.prettytime(time.time()-us), RNS.LOG_WARNING)
return response
except Exception as e: except Exception as e:
RNS.log("Error while retrieving state "+str(prop)+" over RPC: "+str(e), RNS.LOG_DEBUG) RNS.log("Error while retrieving state "+str(prop)+" over RPC: "+str(e), RNS.LOG_DEBUG)
self.rpc_connection = None self.rpc_connection = None
return None return None
def __start_rpc_listener(self): def __start_rpc_listener(self):
try: try:
@ -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)
connection.close() try:
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):