mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-05-01 19:22:23 +02:00
Add a way to cancel an ongoing container upgrade
This might happen if people in a hurry want to do a conversion without having to wait for the new container to be ready.
This commit is contained in:
parent
27aa2b05a1
commit
e9ddf8b375
3 changed files with 57 additions and 21 deletions
|
@ -462,7 +462,9 @@ class InstallContainerThread(QtCore.QThread):
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
error = None
|
error = None
|
||||||
try:
|
try:
|
||||||
should_upgrade = bool(self.dangerzone.settings.get("updater_check_all"))
|
should_upgrade = bool(
|
||||||
|
self.dangerzone.settings.get("updater_container_needs_update")
|
||||||
|
)
|
||||||
installed = self.dangerzone.isolation_provider.install(
|
installed = self.dangerzone.isolation_provider.install(
|
||||||
should_upgrade=should_upgrade, callback=self.process_stdout.emit
|
should_upgrade=should_upgrade, callback=self.process_stdout.emit
|
||||||
)
|
)
|
||||||
|
@ -526,6 +528,26 @@ class WaitingWidgetContainer(WaitingWidget):
|
||||||
# Linux states
|
# Linux states
|
||||||
# - "install_container"
|
# - "install_container"
|
||||||
|
|
||||||
|
def _create_button(
|
||||||
|
self, label: str, event: QtCore.Signal, hide: bool = False
|
||||||
|
) -> QtWidgets.QWidget:
|
||||||
|
button = QtWidgets.QPushButton(label)
|
||||||
|
button.clicked.connect(event)
|
||||||
|
buttons_layout = QtWidgets.QHBoxLayout()
|
||||||
|
buttons_layout.addStretch()
|
||||||
|
buttons_layout.addWidget(button)
|
||||||
|
buttons_layout.addStretch()
|
||||||
|
|
||||||
|
widget = QtWidgets.QWidget()
|
||||||
|
widget.setLayout(buttons_layout)
|
||||||
|
if hide:
|
||||||
|
widget.hide()
|
||||||
|
return widget
|
||||||
|
|
||||||
|
def _hide_buttons(self) -> None:
|
||||||
|
self.button_check.hide()
|
||||||
|
self.button_cancel.hide()
|
||||||
|
|
||||||
def __init__(self, dangerzone: DangerzoneGui) -> None:
|
def __init__(self, dangerzone: DangerzoneGui) -> None:
|
||||||
super(WaitingWidgetContainer, self).__init__()
|
super(WaitingWidgetContainer, self).__init__()
|
||||||
self.dangerzone = dangerzone
|
self.dangerzone = dangerzone
|
||||||
|
@ -537,14 +559,10 @@ class WaitingWidgetContainer(WaitingWidget):
|
||||||
self.label.setStyleSheet("QLabel { font-size: 20px; }")
|
self.label.setStyleSheet("QLabel { font-size: 20px; }")
|
||||||
|
|
||||||
# Buttons
|
# Buttons
|
||||||
check_button = QtWidgets.QPushButton("Check Again")
|
self.button_check = self._create_button("Check Again", self.check_state)
|
||||||
check_button.clicked.connect(self.check_state)
|
self.button_cancel = self._create_button(
|
||||||
buttons_layout = QtWidgets.QHBoxLayout()
|
"Cancel", self.cancel_install, hide=True
|
||||||
buttons_layout.addStretch()
|
)
|
||||||
buttons_layout.addWidget(check_button)
|
|
||||||
buttons_layout.addStretch()
|
|
||||||
self.buttons = QtWidgets.QWidget()
|
|
||||||
self.buttons.setLayout(buttons_layout)
|
|
||||||
|
|
||||||
self.traceback = TracebackWidget()
|
self.traceback = TracebackWidget()
|
||||||
|
|
||||||
|
@ -554,7 +572,8 @@ class WaitingWidgetContainer(WaitingWidget):
|
||||||
layout.addWidget(self.label)
|
layout.addWidget(self.label)
|
||||||
layout.addWidget(self.traceback)
|
layout.addWidget(self.traceback)
|
||||||
layout.addStretch()
|
layout.addStretch()
|
||||||
layout.addWidget(self.buttons)
|
layout.addWidget(self.button_check)
|
||||||
|
layout.addWidget(self.button_cancel)
|
||||||
layout.addStretch()
|
layout.addStretch()
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
@ -584,18 +603,22 @@ class WaitingWidgetContainer(WaitingWidget):
|
||||||
# Update the state
|
# Update the state
|
||||||
self.state_change(state, error)
|
self.state_change(state, error)
|
||||||
|
|
||||||
|
def cancel_install(self) -> None:
|
||||||
|
self.install_container_t.terminate()
|
||||||
|
self.finished.emit()
|
||||||
|
|
||||||
def show_error(self, msg: str, details: Optional[str] = None) -> None:
|
def show_error(self, msg: str, details: Optional[str] = None) -> None:
|
||||||
self.label.setText(msg)
|
self.label.setText(msg)
|
||||||
show_traceback = details is not None
|
show_traceback = details is not None
|
||||||
if show_traceback:
|
if show_traceback:
|
||||||
self.traceback.set_content(details)
|
self.traceback.set_content(details)
|
||||||
self.traceback.setVisible(show_traceback)
|
self.traceback.setVisible(show_traceback)
|
||||||
self.buttons.show()
|
self.button_check.show()
|
||||||
|
|
||||||
def show_message(self, msg: str) -> None:
|
def show_message(self, msg: str) -> None:
|
||||||
self.label.setText(msg)
|
self.label.setText(msg)
|
||||||
self.traceback.setVisible(False)
|
self.traceback.setVisible(False)
|
||||||
self.buttons.hide()
|
self._hide_buttons()
|
||||||
|
|
||||||
def installation_finished(self, error: Optional[str] = None) -> None:
|
def installation_finished(self, error: Optional[str] = None) -> None:
|
||||||
if error:
|
if error:
|
||||||
|
@ -649,11 +672,23 @@ class WaitingWidgetContainer(WaitingWidget):
|
||||||
error,
|
error,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.show_message(
|
needs_update = bool(
|
||||||
"Installing the Dangerzone container image.<br><br>"
|
self.dangerzone.settings.get("updater_container_needs_update")
|
||||||
"This might take a few minutes..."
|
|
||||||
)
|
)
|
||||||
|
if needs_update:
|
||||||
|
message = (
|
||||||
|
"Downloading and upgrading the Dangerzone container image.<br><br>"
|
||||||
|
"This might take a few minutes..."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
message = (
|
||||||
|
"Installing the Dangerzone container image.<br><br>"
|
||||||
|
"This might take a few minutes..."
|
||||||
|
)
|
||||||
|
self.show_message(message)
|
||||||
self.traceback.setVisible(True)
|
self.traceback.setVisible(True)
|
||||||
|
self.button_cancel.show()
|
||||||
|
self.button_check.hide()
|
||||||
|
|
||||||
self.install_container_t = InstallContainerThread(self.dangerzone)
|
self.install_container_t = InstallContainerThread(self.dangerzone)
|
||||||
self.install_container_t.finished.connect(self.installation_finished)
|
self.install_container_t.finished.connect(self.installation_finished)
|
||||||
|
|
|
@ -169,8 +169,9 @@ def check_for_updates(settings: Settings) -> UpdaterReport:
|
||||||
slightly different answer:
|
slightly different answer:
|
||||||
|
|
||||||
1. No new updates: Return an empty update report.
|
1. No new updates: Return an empty update report.
|
||||||
2. Updates are available: Return an update report with the latest version and
|
2. Updates are available:
|
||||||
changelog, in HTML format.
|
Return an update report with the latest version and changelog, or with the
|
||||||
|
information the container image needs to be updated.
|
||||||
3. Update check failed: Return an update report that holds just the error
|
3. Update check failed: Return an update report that holds just the error
|
||||||
message.
|
message.
|
||||||
"""
|
"""
|
||||||
|
@ -215,9 +216,7 @@ def check_for_updates(settings: Settings) -> UpdaterReport:
|
||||||
report.changelog = gh_changelog
|
report.changelog = gh_changelog
|
||||||
|
|
||||||
container_name = container_utils.expected_image_name()
|
container_name = container_utils.expected_image_name()
|
||||||
container_needs_update, _ = is_container_update_available(
|
container_needs_update, _ = is_container_update_available(container_name)
|
||||||
container_name, DEFAULT_PUBKEY_LOCATION
|
|
||||||
)
|
|
||||||
report.container_needs_update = container_needs_update
|
report.container_needs_update = container_needs_update
|
||||||
|
|
||||||
settings.set(
|
settings.set(
|
||||||
|
|
|
@ -133,7 +133,9 @@ class Signature:
|
||||||
return full_digest.replace("sha256:", "")
|
return full_digest.replace("sha256:", "")
|
||||||
|
|
||||||
|
|
||||||
def is_update_available(image_str: str, pubkey: Path) -> Tuple[bool, Optional[str]]:
|
def is_update_available(
|
||||||
|
image_str: str, pubkey: Path = DEFAULT_PUBKEY_LOCATION
|
||||||
|
) -> Tuple[bool, Optional[str]]:
|
||||||
"""
|
"""
|
||||||
Check if a new image is available, doing all the necessary checks ensuring it
|
Check if a new image is available, doing all the necessary checks ensuring it
|
||||||
would be safe to upgrade.
|
would be safe to upgrade.
|
||||||
|
|
Loading…
Reference in a new issue