Skip to content

Commit

Permalink
Add status messages when connecting to node. Slow progress bar. Alter…
Browse files Browse the repository at this point in the history
… connection dialog.
  • Loading branch information
freQniK committed Jun 17, 2024
1 parent 3b15e46 commit 48335f6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 24 deletions.
24 changes: 23 additions & 1 deletion src/cli/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ def connect(self, ID, address, type):
CONFIG = MeileConfig.read_configuration(MeileConfig.CONFFILE)
PASSWORD = CONFIG['wallet'].get('password', '')
KEYNAME = CONFIG['wallet'].get('keyname', '')

confile = path.join(ConfParams.KEYRINGDIR, "connect.log")
conndesc = open(confile, 'w')



self.RPC = CONFIG['network'].get('rpc', HTTParams.RPC)
Expand All @@ -523,10 +527,14 @@ def connect(self, ID, address, type):
sessions = sdk.sessions.QuerySessionsForSubscription(int(ID))
for session in sessions:
if session.status == Status.ACTIVE.value:
conndesc.write("Terminating any active session on chain...\n")
conndesc.flush()
tx = sdk.sessions.EndSession(session_id=session.id, rating=0, tx_params=tx_params)
print(sdk.sessions.wait_for_tx(tx["hash"]))

tx = sdk.sessions.StartSession(subscription_id=int(ID), address=address, tx_params=tx_params)
conndesc.write("Creating new session...\n")
conndesc.flush()
# Will need to handle log responses with friendly UI response in case of session create error
if tx.get("log", None) is not None:
self.connected = {"v2ray_pid" : None, "result": False, "status" : tx["log"]}
Expand Down Expand Up @@ -582,6 +590,8 @@ def connect(self, ID, address, type):
"signature": base64.b64encode(signature).decode("utf-8"),
}
print(payload)
conndesc.write("Fetching credentials from node...\n")
conndesc.flush()
response = requests.post(
f"{node.remote_url}/accounts/{sdk._account.address}/sessions/{session_id}",
json=payload,
Expand Down Expand Up @@ -612,7 +622,8 @@ def connect(self, ID, address, type):
self.connected = {"v2ray_pid" : None, "result": False, "status" : f"Incorrect result size: {len(decode)}"}
print(self.connected)
return

conndesc.write("Bringing up dVPN tunnel...\n")
conndesc.flush()
ipv4_address = socket.inet_ntoa(decode[0:4]) + "/32"
ipv6_address = socket.inet_ntop(socket.AF_INET6, decode[4:20]) + "/128"
host = socket.inet_ntoa(decode[20:24])
Expand Down Expand Up @@ -663,9 +674,14 @@ def connect(self, ID, address, type):

if psutil.net_if_addrs().get(iface):
self.connected = {"v2ray_pid" : None, "result": True, "status" : iface}
conndesc.write("Checking network connection...\n")
conndesc.flush()
self.get_ip_address()
conndesc.close()
return
else: # v2ray
conndesc.write("Bringing up V2Ray socks tunnel...\n")
conndesc.flush()
if len(decode) != 7:
self.connected = {"v2ray_pid" : None, "result": False, "status" : f"Incorrect result size: {len(decode)}"}
print(self.connected)
Expand Down Expand Up @@ -729,12 +745,18 @@ def connect(self, ID, address, type):
if tuniface is True:
self.connected = {"v2ray_pid" : v2ray_handler.v2ray_pid, "result": True, "status" : tuniface}
print(self.connected)
conndesc.write("Checking network connection...\n")
conndesc.flush()
self.get_ip_address()
conndesc.close()
return
else:
try:
conndesc.write("Error connecting to V2Ray node...\n")
conndesc.flush()
v2ray_handler.v2ray_script = f"{v2ray_tun2routes_connect_bash} down"
v2ray_handler.kill_daemon()
conndesc.close()
except Exception as e:
print(str(e))

Expand Down
36 changes: 26 additions & 10 deletions src/kv/meile.kv
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ WindowManager:
pos_hint: {'center_x': 0.5, 'top': .925}
spacing: '40dp'
Image:
id: qr
source: root.qr_address
pos_hint: {'x': 0, 'top': 1}
size_hint_y: .5
Expand Down Expand Up @@ -1948,16 +1949,31 @@ WindowManager:

<ConnectionDialog>
size_hint_y: None
height: "7dp"

MDProgressBar:
id: pb
value: 0.01
min: 0
max: 1
color: get_color_from_hex(MeileColors.MEILE)
pos_hint: {'center_x' : .5, "y" : .5}
size_hint_x: .85
orientation: "vertical"
height: "30dp" # Adjusted height for visibility
padding: "10dp"
spacing: "10dp"
MDBoxLayout:
orientation: "vertical"
size_hint_y: None
height: self.minimum_height
MDLabel:
id: status
text: "Connecting..."
halign: "center" # Center align the text for better visibility
size_hint_y: None
height: self.texture_size[1] + dp(10) # Ensure the label has a height

MDProgressBar:
id: pb
value: 0.01
min: 0
max: 1
color: get_color_from_hex(MeileColors.MEILE)
size_hint_y: None
height: "10dp" # Set explicit height for the progress bar
size_hint_x: .85
pos_hint: {'center_x': .5}

<WalletInfoContent>
orientation: "vertical"
Expand Down
2 changes: 1 addition & 1 deletion src/ui/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ClickableTextFieldRoundCVV(MDRelativeLayout):
class TXContent(BoxLayout):
pass

class ConnectionDialog(MDFloatLayout):
class ConnectionDialog(MDBoxLayout):
pass


58 changes: 46 additions & 12 deletions src/ui/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def __init__(self, node_tree, **kwargs):

Clock.schedule_once(self.get_config,1)
Clock.schedule_once(self.build, 1)

Clock.schedule_interval(self.update_wallet, 60)
menu_icons = ["cloud-refresh", "sort", "shield-lock", "exit-to-app"]
menu_items = [
{
Expand All @@ -406,6 +406,12 @@ def __init__(self, node_tree, **kwargs):
caller=self.ids.settings_menu,
width_mult=3,
background_color=get_color_from_hex(MeileColors.BLACK))

def update_wallet(self, dt):
MeileConfig = MeileGuiConfig()
CONFIG = MeileConfig.read_configuration(MeileGuiConfig.CONFFILE)

self.address = CONFIG['wallet'].get('address', None)
def ping(self):
UUID = Meile.app.root.get_screen(WindowNames.PRELOAD).UUID
try:
Expand All @@ -427,24 +433,45 @@ def connect_routine(self):

@delayable
def connect():
cd = ConnectionDialog()
self.set_conn_dialog(cd, "Connecting...")
CONNFILE_OPENED = False
self.cd = ConnectionDialog()
self.set_conn_dialog(self.cd, " ")
yield 0.3

confile = path.join(ConfParams.KEYRINGDIR, "connect.log")
if path.isfile(confile):
remove(confile)

with open(confile, 'a'):
pass


hwf = HandleWalletFunctions()
thread = Thread(target=lambda: self.ping())
thread.start()
t = Thread(target=lambda: hwf.connect(ID, naddress, type))
t.start()

while t.is_alive():
yield 0.0365
if "WireGuard" not in type:
cd.ids.pb.value += 0.001
else:
cd.ids.pb.value += 0.00175

cd.ids.pb.value = 1
yield 0.0314
self.cd.ids.pb.value += 0.00085

#if "WireGuard" not in type:
# self.cd.ids.pb.value += 0.001
#else:
# self.cd.ids.pb.value += 0.001
try:
if path.isfile(confile) and not CONNFILE_OPENED:
conndesc = open(confile, 'r')
CONNFILE_OPENED = True
elif path.isfile(confile):
self.update_conn_dialog_title(conndesc.readlines()[-1])
except IndexError:
pass


#conndesc.close()
self.cd.ids.pb.value = 1

self.ConnectedDict = deepcopy(hwf.connected)
yield 0.420
Expand Down Expand Up @@ -1279,6 +1306,11 @@ def set_conn_dialog(self, cd, title):
md_bg_color=get_color_from_hex(MeileColors.BLACK),
)
self.dialog.open()

def update_conn_dialog_title(self, new_title):
if self.dialog:
self.cd.ids.status.text = new_title


def load_country_nodes(self, country, *kwargs):
mw = Meile.app.root.get_screen(WindowNames.MAIN_WINDOW)
Expand Down Expand Up @@ -1858,7 +1890,9 @@ class PlanScreen(MDBoxLayout):
def __init__(self, **kwargs):
super(PlanScreen, self).__init__()
self.mw = Meile.app.root.get_screen(WindowNames.MAIN_WINDOW)
wallet = self.mw.address
MeileConfig = MeileGuiConfig()
CONFIG = MeileConfig.read_configuration(MeileGuiConfig.CONFFILE)
wallet = CONFIG['wallet'].get('address', None)
Request = HTTPRequests.MakeRequest()
http = Request.hadapter()

Expand Down

0 comments on commit 48335f6

Please sign in to comment.