Permission check flow

This commit is contained in:
Mark Qvist 2022-10-03 00:47:27 +02:00
parent b06db067e6
commit 8aeb643b81
4 changed files with 30 additions and 10 deletions

View File

@ -8,8 +8,8 @@ import base64
import threading import threading
from kivy.logger import Logger, LOG_LEVELS from kivy.logger import Logger, LOG_LEVELS
# Logger.setLevel(LOG_LEVELS["debug"]) Logger.setLevel(LOG_LEVELS["debug"])
Logger.setLevel(LOG_LEVELS["error"]) # Logger.setLevel(LOG_LEVELS["error"])
if RNS.vendor.platformutils.get_platform() != "android": if RNS.vendor.platformutils.get_platform() != "android":
local = os.path.dirname(__file__) local = os.path.dirname(__file__)
@ -36,6 +36,8 @@ if RNS.vendor.platformutils.get_platform() == "android":
from android import mActivity from android import mActivity
from android.permissions import request_permissions, check_permission from android.permissions import request_permissions, check_permission
from kivymd.utils.set_bars_colors import set_bars_colors
else: else:
from .sideband.core import SidebandCore from .sideband.core import SidebandCore
@ -86,9 +88,9 @@ class SidebandApp(MDApp):
Window.softinput_mode = "below_target" Window.softinput_mode = "below_target"
self.icon = self.sideband.asset_dir+"/icon.png" self.icon = self.sideband.asset_dir+"/icon.png"
self.notification_icon = self.sideband.asset_dir+"/notification_icon.png" self.notification_icon = self.sideband.asset_dir+"/notification_icon.png"
self.check_permissions()
def start_core(self, dt): def start_core(self, dt):
self.check_permissions()
self.start_service() self.start_service()
Clock.schedule_interval(self.jobs, 1) Clock.schedule_interval(self.jobs, 1)
@ -110,6 +112,8 @@ class SidebandApp(MDApp):
else: else:
self.open_conversations() self.open_conversations()
self.set_bars_colors()
self.app_state = SidebandApp.ACTIVE self.app_state = SidebandApp.ACTIVE
def start_service(self): def start_service(self):
@ -149,6 +153,14 @@ class SidebandApp(MDApp):
else: else:
self.theme_cls.theme_style = "Light" self.theme_cls.theme_style = "Light"
def set_bars_colors(self):
if RNS.vendor.platformutils.get_platform() == "android":
set_bars_colors(
self.theme_cls.primary_color, # status bar color
[0,0,0,0], # navigation bar color
"Light", # icons color of status bar
)
def share_text(self, text): def share_text(self, text):
if RNS.vendor.platformutils.get_platform() == "android": if RNS.vendor.platformutils.get_platform() == "android":
Intent = autoclass('android.content.Intent') Intent = autoclass('android.content.Intent')
@ -350,7 +362,7 @@ class SidebandApp(MDApp):
dialog = MDDialog( dialog = MDDialog(
text="An announce for your LXMF destination was sent on all available interfaces", text="An announce for your LXMF destination was sent on all available interfaces",
buttons=[ yes_button ], buttons=[ yes_button ],
elevation=0, # elevation=0,
) )
def dl_yes(s): def dl_yes(s):
dialog.dismiss() dialog.dismiss()

View File

@ -3,8 +3,8 @@ import RNS
from os import environ from os import environ
from kivy.logger import Logger, LOG_LEVELS from kivy.logger import Logger, LOG_LEVELS
# Logger.setLevel(LOG_LEVELS["debug"]) Logger.setLevel(LOG_LEVELS["debug"])
Logger.setLevel(LOG_LEVELS["error"]) # Logger.setLevel(LOG_LEVELS["error"])
if RNS.vendor.platformutils.get_platform() == "android": if RNS.vendor.platformutils.get_platform() == "android":
from jnius import autoclass, cast from jnius import autoclass, cast

View File

@ -118,7 +118,6 @@ class SidebandCore():
except Exception as e: except Exception as e:
RNS.log("Error while configuring Sideband: "+str(e), RNS.LOG_ERROR) RNS.log("Error while configuring Sideband: "+str(e), RNS.LOG_ERROR)
# Initialise Reticulum configuration # Initialise Reticulum configuration
if RNS.vendor.platformutils.get_platform() == "android": if RNS.vendor.platformutils.get_platform() == "android":
try: try:
@ -180,10 +179,13 @@ class SidebandCore():
self.config["connect_i2p_ifac_netname"] = "" self.config["connect_i2p_ifac_netname"] = ""
self.config["connect_i2p_ifac_passphrase"] = "" self.config["connect_i2p_ifac_passphrase"] = ""
self.__save_config()
if not os.path.isfile(self.db_path): if not os.path.isfile(self.db_path):
self.__db_init() self.__db_init()
else:
self._db_initstate()
self._db_initpersistent()
self.__save_config()
def should_persist_data(self): def should_persist_data(self):
if self.reticulum != None: if self.reticulum != None:
@ -434,6 +436,8 @@ class SidebandCore():
pass pass
def __db_init(self): def __db_init(self):
# TODO: Remove
print("------------------ DB INIT")
db = sqlite3.connect(self.db_path) db = sqlite3.connect(self.db_path)
dbc = db.cursor() dbc = db.cursor()
@ -454,6 +458,8 @@ class SidebandCore():
db.commit() db.commit()
db.close() db.close()
# TODO: Remove
print("------------------ DB INIT DONE")
def _db_initstate(self): def _db_initstate(self):
db = sqlite3.connect(self.db_path) db = sqlite3.connect(self.db_path)
@ -906,7 +912,7 @@ class SidebandCore():
self.service_thread.start() self.service_thread.start()
def __start_jobs_immediate(self): def __start_jobs_immediate(self):
self.reticulum = RNS.Reticulum(configdir=self.rns_configdir, loglevel=3) self.reticulum = RNS.Reticulum(configdir=self.rns_configdir, loglevel=7)
if RNS.vendor.platformutils.get_platform() == "android": if RNS.vendor.platformutils.get_platform() == "android":
if not self.reticulum.is_connected_to_shared_instance: if not self.reticulum.is_connected_to_shared_instance:

View File

@ -3,6 +3,8 @@ root_layout = """
#: import SlideTransition kivy.uix.screenmanager.SlideTransition #: import SlideTransition kivy.uix.screenmanager.SlideTransition
MDNavigationLayout: MDNavigationLayout:
md_bg_color: app.theme_cls.bg_darkest
ScreenManager: ScreenManager:
id: screen_manager id: screen_manager
transition: SlideTransition() transition: SlideTransition()