Skip to content
Snippets Groups Projects
Commit 0e929af7 authored by Mateusz Żebrak's avatar Mateusz Żebrak
Browse files

Ensure form cleanup is done when exiting form

parent 3e2b9e40
No related branches found
No related tags found
2 merge requests!600v1.27.5.21 Release,!558Remove welcome profile from TUIWorld, set TUIWorld profile during CreateProfile wizard instead
......@@ -20,6 +20,10 @@ class CreateProfileForm(Form):
await self.world.create_new_profile("temp_name")
self.profile.skip_saving()
async def cleanup(self) -> None:
await self.world.switch_profile(None)
self.app.call_later(lambda: self.app.remove_mode("create_profile"))
def compose_form(self) -> Iterator[type[FormScreenBase]]:
if not Profile.is_any_profile_saved():
yield CreateProfileWelcomeFormScreen
......
......@@ -48,6 +48,9 @@ class Form(ContextualHolder[FormContextT], CliveScreen[None]):
async def initialize(self) -> None:
"""Do actions that should be executed before the first form is displayed."""
async def cleanup(self) -> None:
"""Do actions that should be executed when exiting the form."""
def next_screen(self) -> None:
if not self._check_valid_range(self._current_screen_index + 1):
return
......
......@@ -62,6 +62,7 @@ class FormScreen(FormScreenBase[FormContextT], ABC):
return
if self.back_screen_mode == "back_to_unlock":
await self._owner.cleanup()
await self._back_to_unlock_screen()
return
......
from __future__ import annotations
import contextlib
from datetime import timedelta
from typing import TYPE_CHECKING
from textual import on
from textual.app import InvalidModeError
from textual.containers import Horizontal
from textual.validation import Integer
from textual.widgets import Button, Checkbox, Static
......@@ -11,6 +13,7 @@ from textual.widgets import Button, Checkbox, Static
from clive.__private.core.constants.tui.messages import PRESS_HELP_MESSAGE
from clive.__private.core.profile import Profile
from clive.__private.ui.clive_widget import CliveWidget
from clive.__private.ui.forms.create_profile.create_profile_form import CreateProfileForm
from clive.__private.ui.get_css import get_relative_css_path
from clive.__private.ui.screens.base_screen import BaseScreen
from clive.__private.ui.widgets.buttons import CliveButton
......@@ -129,6 +132,10 @@ class Unlock(BaseScreen):
@on(Button.Pressed, "#new-profile-button")
async def create_new_profile(self) -> None:
with contextlib.suppress(InvalidModeError):
# If the mode is already added, we don't want to add it again
self.app.add_mode("create_profile", CreateProfileForm)
await self.app.switch_mode("create_profile")
@on(SelectProfile.Changed)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment