forked from Support/sp-hydra-veil-gui
Delete now uses the menu coordinator, and not the worker
This commit is contained in:
parent
39a6a81286
commit
1fe14ff97b
3 changed files with 65 additions and 23 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
# core
|
# core
|
||||||
from core.infrastructure.state_management.global_state_controller import connected_system_profile_id, connected_session_profile_ids
|
from core.infrastructure.state_management.global_state_controller import connected_system_profile_id, connected_session_profile_ids, is_connected
|
||||||
from core.observers.Notifications import Notifications, EventType
|
from core.observers.Notifications import Notifications, EventType
|
||||||
# from core.controllers.SessionStateController import SessionStateController
|
# from core.controllers.SessionStateController import SessionStateController
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ from core.observers.Notifications import Notifications, EventType
|
||||||
from core.controllers.ConfigurationController import ConfigurationController
|
from core.controllers.ConfigurationController import ConfigurationController
|
||||||
# from core.services.prepare_tickets.ticket_tracker import get_a_random_ticket
|
# from core.services.prepare_tickets.ticket_tracker import get_a_random_ticket
|
||||||
# from core.models.BaseProfile import BaseProfile as Profile
|
# from core.models.BaseProfile import BaseProfile as Profile
|
||||||
from core.services.profiles.profile_connections import enable_profile, disable_profile
|
from core.services.profiles.profile_connections import enable_profile, disable_profile, destroy_profile
|
||||||
from core.controllers.ProfileController import ProfileController
|
from core.controllers.ProfileController import ProfileController
|
||||||
from core.models.Configuration import Configuration, ConnectionChoice
|
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
|
from core.services.subscriptions.subscriptions_by_protocol import get_profile_subscription, start_new_payment_cycle, wipe_subscription, evaluate_repeat_cycle
|
||||||
|
|
@ -351,8 +351,35 @@ def sync_now(ui_caller: Callable):
|
||||||
connection_observer=connection_observer
|
connection_observer=connection_observer
|
||||||
)
|
)
|
||||||
|
|
||||||
# def finish(result: Result):
|
def delete_profile_action(profile_id: int, ui_caller: Callable) -> Result:
|
||||||
# print("goodbye")
|
"""Disconnect if active, then delete the profile in the background thread."""
|
||||||
|
|
||||||
|
if is_connected(profile_id):
|
||||||
|
# first disconnect on main thread:
|
||||||
|
logger.info("Disconnecting first..")
|
||||||
|
disconnected = literally_disconnect(profile_id)
|
||||||
|
if not disconnected.valid:
|
||||||
|
error_msg = "Couldn't get to delete, because we can't even disconnect."
|
||||||
|
logger.error(error_msg)
|
||||||
|
return disconnected.wrap(error_msg)
|
||||||
|
|
||||||
|
got_profile = get_profile(profile_id)
|
||||||
|
if not got_profile.valid:
|
||||||
|
return got_profile.wrap("Failed to get the profile.")
|
||||||
|
profile = got_profile.data
|
||||||
|
|
||||||
|
# threading for the delete:
|
||||||
|
logger.info("Disconnect done, now threading to destroy the files..")
|
||||||
|
take_action(
|
||||||
|
action=destroy_profile,
|
||||||
|
ui_caller=ui_caller,
|
||||||
|
profile=profile,
|
||||||
|
profile_observer=profile_observer,
|
||||||
|
ticket_observer=ticket_observer,
|
||||||
|
connection_observer=connection_observer
|
||||||
|
)
|
||||||
|
return Result(valid=True) # this doesn't mean it deleted, just that it launched.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# atexit.register(disconnect_active(ui_caller=finish))
|
# atexit.register(disconnect_active(ui_caller=finish))
|
||||||
|
|
|
||||||
|
|
@ -335,7 +335,8 @@ def profile_status_message(profile: BaseProfile, is_enabled: bool, idle: bool =
|
||||||
if profile_date is None:
|
if profile_date is None:
|
||||||
return "Offline. No subscription found."
|
return "Offline. No subscription found."
|
||||||
|
|
||||||
expiration_date = profile_date.replace(tzinfo=timezone.utc)
|
expiration_date = profile_date
|
||||||
|
#.replace(tzinfo=timezone.utc)
|
||||||
time_left = expiration_date - datetime.now(timezone.utc)
|
time_left = expiration_date - datetime.now(timezone.utc)
|
||||||
days_left = time_left.days
|
days_left = time_left.days
|
||||||
hours_left, _ = divmod(time_left.seconds, 3600)
|
hours_left, _ = divmod(time_left.seconds, 3600)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ from core.controllers.tickets.UseTicketController import (
|
||||||
get_unused_tickets,
|
get_unused_tickets,
|
||||||
modify_random_tickets_setting,
|
modify_random_tickets_setting,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from core.models.Result import Result
|
||||||
from core.models.session.SessionProfile import SessionProfile
|
from core.models.session.SessionProfile import SessionProfile
|
||||||
from core.models.system.SystemProfile import SystemProfile
|
from core.models.system.SystemProfile import SystemProfile
|
||||||
from core.Errors import (
|
from core.Errors import (
|
||||||
|
|
@ -54,7 +56,7 @@ from gui.v2.ui.widgets.terminal_widget import TerminalWidget
|
||||||
from gui.v2.workers.page_data_worker import PageDataWorker
|
from gui.v2.workers.page_data_worker import PageDataWorker
|
||||||
from gui.v2.workers.ticketing_worker_thread import TicketingWorkerThread
|
from gui.v2.workers.ticketing_worker_thread import TicketingWorkerThread
|
||||||
from gui.v2.workers.worker_thread import WorkerThread
|
from gui.v2.workers.worker_thread import WorkerThread
|
||||||
|
from gui.v2.actions.menu_coordinator import delete_profile_action
|
||||||
|
|
||||||
class Settings(Page):
|
class Settings(Page):
|
||||||
def __init__(self, page_stack, main_window, parent=None, prepared=None):
|
def __init__(self, page_stack, main_window, parent=None, prepared=None):
|
||||||
|
|
@ -778,24 +780,36 @@ class Settings(Page):
|
||||||
|
|
||||||
def handle_delete_confirmation(self, confirmed):
|
def handle_delete_confirmation(self, confirmed):
|
||||||
if confirmed:
|
if confirmed:
|
||||||
self.update_status.update_status(f'Deleting profile...')
|
profile_id = self.selected_profile_id
|
||||||
self.worker_thread = WorkerThread('DESTROY_PROFILE', profile_data={
|
self.update_status.update_status(f'Deleting profile {profile_id}...')
|
||||||
'id': self.selected_profile_id})
|
|
||||||
self.worker_thread.text_output.connect(self.delete_status_update)
|
|
||||||
self.worker_thread.start()
|
|
||||||
|
|
||||||
def delete_status_update(self, message):
|
started_delete = delete_profile_action(profile_id=profile_id, ui_caller=self.delete_status_update)
|
||||||
|
if not started_delete.valid:
|
||||||
|
message = started_delete.message
|
||||||
self.update_status.update_status(message)
|
self.update_status.update_status(message)
|
||||||
if not message.startswith('Could not delete'):
|
|
||||||
|
def delete_status_update(self, result: Result):
|
||||||
|
"""Recieve the result of the deletion."""
|
||||||
|
if not result.valid:
|
||||||
|
self.update_status.update_status(result.message)
|
||||||
|
return
|
||||||
|
|
||||||
|
self.update_status.update_status("Deleted")
|
||||||
|
|
||||||
|
# # if not message.startswith('Could not delete'):
|
||||||
menu_page = self.custom_window.navigator.get_cached("menu")
|
menu_page = self.custom_window.navigator.get_cached("menu")
|
||||||
if menu_page is not None and hasattr(menu_page, 'clear_profile_details'):
|
if menu_page is not None and hasattr(menu_page, 'clear_profile_details'):
|
||||||
menu_page.clear_profile_details()
|
menu_page.clear_profile_details()
|
||||||
if menu_page is not None and hasattr(menu_page, 'refresh_menu_buttons'):
|
if menu_page is not None and hasattr(menu_page, 'refresh_menu_buttons'):
|
||||||
menu_page.refresh_menu_buttons()
|
menu_page.refresh_menu_buttons()
|
||||||
self.content_layout.removeWidget(self.delete_page)
|
|
||||||
self.delete_page = self.create_delete_page()
|
# back to the main page:
|
||||||
self.content_layout.addWidget(self.delete_page)
|
self.custom_window.navigator.navigate("menu")
|
||||||
self.content_layout.setCurrentWidget(self.delete_page)
|
|
||||||
|
# self.content_layout.removeWidget(self.delete_page)
|
||||||
|
# self.delete_page = self.create_delete_page()
|
||||||
|
# self.content_layout.addWidget(self.delete_page)
|
||||||
|
# self.content_layout.setCurrentWidget(self.delete_page)
|
||||||
|
|
||||||
def get_checkbox_style(self) -> str:
|
def get_checkbox_style(self) -> str:
|
||||||
return checkbox_style(self.font_style)
|
return checkbox_style(self.font_style)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue