meile-gui icon indicating copy to clipboard operation
meile-gui copied to clipboard

[BUG] Connection switch turns off if user cancels on disconnect

Open MathNodes opened this issue 2 years ago • 15 comments

Sounds like a relatively easy fix, but there are some intricacies involved in this.

The heart of the bug is in connect_to_node() in https://github.com/MathNodes/meile-gui/blob/ffb085ef452e167eb2a1f822f34ddb602b674dc3/src/ui/widgets.py#L660

and disconnect_from_node() in https://github.com/MathNodes/meile-gui/blob/ffb085ef452e167eb2a1f822f34ddb602b674dc3/src/ui/screens.py#L563

The idea would be to check the returncode of the calling disconnect() backend function, and if not 0 or the appropriate value for each platform, then the disconnect_from_node() function should return False and connect_to_node() should handle this False value and turn the switch back to active so the user can disconnect from it at a later time.

I'm offering a bounty for this so I don't spend time testing methods that may or may not work and need to spend time on other things.

MathNodes avatar Sep 08 '23 19:09 MathNodes

Hi @MathNodes I want to work on this issue.

HammadRafique29 avatar Sep 09 '23 16:09 HammadRafique29

@MathNodes

What i have understand is:

  • disconnect_to_node() ==> return False if node failed to terminate
  • connect_to_node() condition 1: if mw.NodeSwitch['switch']... ==> returns True if disconnected oterwise return False condition 2: if mw.CONNECTED ==> return None

Detailed Info:

  • connect_to_node() have 3 conditions. First for DISCONNECTING Second for CONNECTED Third for CONNECTING
  1. First Condition [DISCONNECTING]: return True if node terminated return False if node failed to terminate

  2. Second Condition [CONNECTED]: return None as alredy CONNECTED

  3. Third Condition [CONNECTING]: connect to new location

  • disconnect_to_node() returns False if node not terminated

HammadRafique29 avatar Sep 09 '23 18:09 HammadRafique29

Thanks for tackling this. I'll have a look at it Monday as I'm busy this weekend and afk.

If it suffices we will pay the bounty. I will personally test it on Monday.

Have a good weekend!

freQniK avatar Sep 09 '23 20:09 freQniK

This isn't going to work. There is a UI element that needs changing. Namely self.ids.node_switch in widgets.py which has an attribute active. It should be set back to True so that the UI element stays active. The issue I've been having in my testing is that when I set self.ids.node_switch.active = True is that it keeps trying to reconnect to the node because it triggers on_active within the meile.kv. Basically in an infinite loop. Not sure how I can set the switch to be back on without it trying to connect. Maybe check if mw.CONNECTED is still True in which case don't try to reconnect.

freQniK avatar Sep 11 '23 20:09 freQniK

@freQniK Sure, i will figure this out

HammadRafique29 avatar Sep 12 '23 01:09 HammadRafique29

This isn't going to work. There is a UI element that needs changing. Namely self.ids.node_switch in widgets.py which has an attribute active. It should be set back to True so that the UI element stays active. The issue I've been having in my testing is that when I set self.ids.node_switch.active = True is that it keeps trying to reconnect to the node because it triggers on_active within the meile.kv. Basically in an infinite loop. Not sure how I can set the switch to be back on without it trying to connect. Maybe check if mw.CONNECTED is still True in which case don't try to reconnect.

Inifinite loop, means that the switch button is calling itself, repeatedly.

HammadRafique29 avatar Sep 12 '23 01:09 HammadRafique29

Upping the bounty to 0.2 XMR

freQniK avatar Sep 12 '23 01:09 freQniK

Upping the bounty to 0.2 XMR

@freQniK Will you provide a little video of running codde in your system, it will help me to find the bug and understand the core logic

HammadRafique29 avatar Sep 12 '23 01:09 HammadRafique29

This isn't going to work. There is a UI element that needs changing. Namely self.ids.node_switch in widgets.py which has an attribute active. It should be set back to True so that the UI element stays active. The issue I've been having in my testing is that when I set self.ids.node_switch.active = True is that it keeps trying to reconnect to the node because it triggers on_active within the meile.kv. Basically in an infinite loop. Not sure how I can set the switch to be back on without it trying to connect. Maybe check if mw.CONNECTED is still True in which case don't try to reconnect.

Inifinite loop, means that the switch button is calling itself, repeatedly.

Yeah. Basically when the user clicks disconnect the switch goes to off. But if the user click disconnect and cancels the sudo prompt then the switch stays off but they are still connected. Handling the cancel request and setting self.ids.node_switch.active = True calls connect_to_node() again. So there should be a temp variable that causes the routine to do nothing if the user already cancelled thereby leaving the switch to the on position.

freQniK avatar Sep 12 '23 01:09 freQniK

Upping the bounty to 0.2 XMR

@freQniK Will you provide a little video of running codde in your system, it will help me to find the bug and understand the core logic

Sure. I can do that tomorrow

freQniK avatar Sep 12 '23 01:09 freQniK

@freQniK I have fixed the major bug, according to my logic, if still there is problem let me know (Pull Request)

HammadRafique29 avatar Sep 12 '23 03:09 HammadRafique29

@freQniK @MathNodes

HammadRafique29 avatar Sep 14 '23 13:09 HammadRafique29

This is not going to work either. call_ip_get() is called once a connection is established so you dont want to fool around with changing the switch in that routine. Not to mention your logic is backwards as once it had successfully connected you turn the switch off so the user has no way to disconnect.

I can't spend any more time on this and have decided to scrap the switch in favor of a global Connect/Disconnect button that will roll out in v1.8.0.

I will however pay half the bounty to you (0.1 XMR) for your time spent reviewing the code and your attempts to resolve the issue even though they were not successful.

Please drop a Monero address in the comments and I will send the coins. Thank you for your time and please check back as we will be posting many more Monero bounties in the future.

freQniK avatar Sep 14 '23 14:09 freQniK

8BGZnRN3NF4UzLHz13Ae3BRzGC9JbDxznF8ERD8JpW7zQZqhvHCGRRxANyBApnsBpwKJqRwZpbWnW4jtX2cXCs835rSDnib

HammadRafique29 avatar Sep 14 '23 15:09 HammadRafique29

Screenshot_20230914-110855.png

freQniK avatar Sep 14 '23 15:09 freQniK

Single connect/disconnect button in 2.0. Thanks for everyone's assitance.

MathNodes avatar Aug 01 '24 05:08 MathNodes