forked from Support/sp-hydra-veil-gui
Disconnect routed directly through actions to core
This commit is contained in:
parent
ffea00e1ff
commit
031704471b
2 changed files with 79 additions and 13 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# core
|
||||
from core.controllers.ConfigurationController import ConfigurationController
|
||||
# from core.services.prepare_tickets.ticket_tracker import get_a_random_ticket
|
||||
from core.services.profiles.profile_connections import enable_profile #, disable_profile
|
||||
from core.services.profiles.profile_connections import enable_profile, disable_profile
|
||||
from core.controllers.ProfileController import ProfileController
|
||||
from core.models.Configuration import Configuration, ConnectionChoice
|
||||
from core.services.subscriptions.subscriptions_by_protocol import get_profile_subscription, start_new_payment_cycle, wipe_subscription, evaluate_repeat_cycle
|
||||
|
|
@ -149,8 +149,7 @@ def NOT_need_tor_warnings(profile_id: int) -> Result:
|
|||
|
||||
@register_action(ResultError.ENDPOINT_VERIFICATION)
|
||||
def literally_connect(
|
||||
profile_id: int,
|
||||
ignore_state_conflict: Optional[bool] = False
|
||||
profile_id: int
|
||||
) -> Result:
|
||||
|
||||
# Step 1: Get the Profile
|
||||
|
|
@ -161,7 +160,7 @@ def literally_connect(
|
|||
profile = profile_result.data
|
||||
|
||||
# EXCEPTIONS
|
||||
ignored = get_ignored_exceptions(ignore_state_conflict=ignore_state_conflict)
|
||||
ignored = get_ignored_exceptions(ignore_state_conflict=True)
|
||||
|
||||
# SCREEN SIZE:
|
||||
max_resolution = get_max_screensize()
|
||||
|
|
@ -188,8 +187,7 @@ def literally_connect(
|
|||
@register_action(ResultError.STATE_CONFLICT)
|
||||
def ignore_state_conflict(profile_id: int) -> Result:
|
||||
return literally_connect(
|
||||
profile_id=profile_id,
|
||||
ignore_state_conflict=True
|
||||
profile_id=profile_id
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -239,3 +237,46 @@ def connect_with_billing_code(profile_id: int, billing_code: str) -> Result:
|
|||
return paid_result
|
||||
|
||||
return literally_connect(profile_id=profile_id)
|
||||
|
||||
|
||||
@type_checker
|
||||
def literally_disconnect(
|
||||
profile_id: int,
|
||||
ignore_state_conflict: Optional[bool] = False
|
||||
) -> Result:
|
||||
"""Get a profile and use core to disable it."""
|
||||
|
||||
# Step 1: Get the Profile
|
||||
profile_result = get_profile(profile_id)
|
||||
if not profile_result:
|
||||
return Result(valid=False, error_type=ResultError.INVALID_INPUT, message="This profile does not match one of your configuration files.")
|
||||
|
||||
profile = profile_result.data
|
||||
|
||||
# EXCEPTIONS
|
||||
ignored = get_ignored_exceptions(ignore_state_conflict=ignore_state_conflict)
|
||||
|
||||
try:
|
||||
final_result = disable_profile(
|
||||
profile=profile,
|
||||
ignore=ignored,
|
||||
profile_observer=profile_observer,
|
||||
connection_observer=connection_observer,
|
||||
ticket_observer=ticket_observer
|
||||
)
|
||||
if final_result:
|
||||
return final_result
|
||||
else:
|
||||
return Result(valid=True)
|
||||
except Exception as error:
|
||||
return translate_error(error=error, profile_id=profile_id)
|
||||
|
||||
|
||||
def disconnect_profile(profile_id: int, ui_caller: Callable) -> Result:
|
||||
"""Background Thread to literally_disconnect"""
|
||||
take_action(
|
||||
action=literally_disconnect,
|
||||
ui_caller=ui_caller,
|
||||
profile_id=profile_id
|
||||
)
|
||||
return Result(valid=True)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ from PyQt6.QtWidgets import (
|
|||
QMessageBox, QPushButton, QScrollArea, QTextEdit, QVBoxLayout, QWidget,
|
||||
)
|
||||
|
||||
from gui.v2.actions.menu_coordinator import connect_profile
|
||||
from gui.v2.actions.menu_coordinator import connect_profile, disconnect_profile
|
||||
|
||||
from gui.v2.actions.menu_profiles import find_verification_icon, get_profile_details, load_menu_profiles, menu_icons
|
||||
from gui.v2.actions.menu_tasks import (
|
||||
|
|
@ -582,6 +582,25 @@ class MenuPage(Page):
|
|||
# and not self.connection_manager.is_profile_connected(self.reverse_id))
|
||||
|
||||
|
||||
def post_disconnect(self, result: Result):
|
||||
"""Recieve the callback after disconnection"""
|
||||
# --------------------
|
||||
# BOTTOM LEFT STATUS BAR
|
||||
# --------------------
|
||||
if result.message:
|
||||
if len(result.message) > 20:
|
||||
self.update_status.disable_marquee
|
||||
self.update_status.update_status(result.message)
|
||||
|
||||
# --------------------
|
||||
# WORKED
|
||||
# --------------------
|
||||
if result.valid:
|
||||
self.boton_edit.setEnabled(True)
|
||||
return
|
||||
|
||||
self.deal_with_errors(result)
|
||||
|
||||
def post_connect(self, result: Result):
|
||||
"""Recieve the callback after a connection attempt."""
|
||||
|
||||
|
|
@ -599,9 +618,9 @@ class MenuPage(Page):
|
|||
if result.valid:
|
||||
return
|
||||
|
||||
# --------------------
|
||||
# FAILURE EVALUATION
|
||||
# --------------------
|
||||
self.deal_with_errors(result)
|
||||
|
||||
def deal_with_errors(self, result: Result):
|
||||
if result.error_type == ResultError.NAVIGATE_TO:
|
||||
print(f"We are auto-navigating to page {result.navigate_to}")
|
||||
self.custom_window.navigator.navigate(result.navigate_to)
|
||||
|
|
@ -631,10 +650,16 @@ class MenuPage(Page):
|
|||
return
|
||||
|
||||
def disconnect(self):
|
||||
self._set_task_busy(True)
|
||||
self.update_status.update_status("Disconnecting...")
|
||||
self.worker = disable_profile(self.reverse_id, self.connection_manager.get_connected_profiles(),
|
||||
self.handle_task_result)
|
||||
disconnect_profile(profile_id=self.reverse_id, ui_caller=self.post_disconnect)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# self._set_task_busy(True)
|
||||
# self.worker = disable_profile(self.reverse_id, self.connection_manager.get_connected_profiles(),
|
||||
# self.handle_task_result)
|
||||
|
||||
def create_prof(self):
|
||||
self._set_task_busy(True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue