summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2025-03-03 15:26:42 +0100
committerDavid Lönnhager <david.l@mullvad.net>2025-03-05 23:32:44 +0100
commitaba4b7a0d9b8ffb96e11eddd8b13b85737e01391 (patch)
tree86f032173ea91f9d3ef19b687ee78bf06f46a958
parentec33f4aa7085e424032d8220254b8cec9eb585ec (diff)
downloadmullvadvpn-aba4b7a0d9b8ffb96e11eddd8b13b85737e01391.tar.xz
mullvadvpn-aba4b7a0d9b8ffb96e11eddd8b13b85737e01391.zip
Add explicit clear methods to Delegate trait
-rw-r--r--installer-downloader/src/cacao_impl/delegate.rs29
-rw-r--r--installer-downloader/src/cacao_impl/ui.rs19
-rw-r--r--installer-downloader/src/controller.rs8
-rw-r--r--installer-downloader/src/delegate.rs6
-rw-r--r--installer-downloader/src/ui_downloader.rs12
-rw-r--r--installer-downloader/src/winapi_impl/delegate.rs26
-rw-r--r--installer-downloader/tests/controller.rs10
-rw-r--r--installer-downloader/tests/snapshots/controller__download-2.snap2
-rw-r--r--installer-downloader/tests/snapshots/controller__download-3.snap2
-rw-r--r--installer-downloader/tests/snapshots/controller__failed_directory_creation.snap3
-rw-r--r--installer-downloader/tests/snapshots/controller__failed_verification.snap7
11 files changed, 77 insertions, 47 deletions
diff --git a/installer-downloader/src/cacao_impl/delegate.rs b/installer-downloader/src/cacao_impl/delegate.rs
index cf9d20e1d1..73c17e7e53 100644
--- a/installer-downloader/src/cacao_impl/delegate.rs
+++ b/installer-downloader/src/cacao_impl/delegate.rs
@@ -1,9 +1,6 @@
use std::sync::{Arc, Mutex};
-use cacao::{
- control::Control,
- layout::{Layout, LayoutConstraint},
-};
+use cacao::{control::Control, layout::Layout};
use super::ui::{Action, AppWindow, ErrorView};
use crate::delegate::{AppDelegate, AppDelegateQueue};
@@ -36,24 +33,18 @@ impl AppDelegate for AppWindow {
self.status_text.set_text(text);
}
+ fn clear_status_text(&mut self) {
+ self.status_text.set_text("");
+ }
+
fn set_download_text(&mut self, text: &str) {
self.download_text.set_text(text);
+ self.readjust_status_text();
+ }
- // If there is a download_text, move status_text up to make room
-
- let offset = if text.is_empty() { 59.0 } else { 39.0 };
-
- if let Some(previous_constraint) = self.status_text_position_y.take() {
- LayoutConstraint::deactivate(&[previous_constraint]);
- }
-
- let new_constraint = self
- .status_text
- .top
- .constraint_equal_to(&self.main_view.top)
- .offset(offset);
- self.status_text_position_y = Some(new_constraint.clone());
- LayoutConstraint::activate(&[new_constraint]);
+ fn clear_download_text(&mut self) {
+ self.download_text.set_text("");
+ self.readjust_status_text();
}
fn show_download_progress(&mut self) {
diff --git a/installer-downloader/src/cacao_impl/ui.rs b/installer-downloader/src/cacao_impl/ui.rs
index b8f86e425f..f65dc6ae2a 100644
--- a/installer-downloader/src/cacao_impl/ui.rs
+++ b/installer-downloader/src/cacao_impl/ui.rs
@@ -404,6 +404,25 @@ impl AppWindow {
.constraint_equal_to(&self.beta_link_preface.center_y),
]);
}
+
+ // If there is a download_text, move status_text up to make room
+ pub fn readjust_status_text(&mut self) {
+ let text = self.download_text.get_text();
+
+ let offset = if text.is_empty() { 59.0 } else { 39.0 };
+
+ if let Some(previous_constraint) = self.status_text_position_y.take() {
+ LayoutConstraint::deactivate(&[previous_constraint]);
+ }
+
+ let new_constraint = self
+ .status_text
+ .top
+ .constraint_equal_to(&self.main_view.top)
+ .offset(offset);
+ self.status_text_position_y = Some(new_constraint.clone());
+ LayoutConstraint::activate(&[new_constraint]);
+ }
}
impl WindowDelegate for AppWindowWrapper {
diff --git a/installer-downloader/src/controller.rs b/installer-downloader/src/controller.rs
index 8bdbacfd51..a8bbbafa26 100644
--- a/installer-downloader/src/controller.rs
+++ b/installer-downloader/src/controller.rs
@@ -179,7 +179,7 @@ async fn fetch_app_version_info<Delegate, VersionProvider>(
let (retry_tx, cancel_tx) = (action_tx.clone(), action_tx);
- self_.set_status_text("");
+ self_.clear_status_text();
self_.on_error_message_retry(move || {
let _ = retry_tx.try_send(Action::Retry);
});
@@ -349,7 +349,7 @@ impl<D: AppDelegate + 'static, A: From<UiAppDownloaderParameters<D>> + AppDownlo
log::error!("Failed to create temporary directory: {error:?}");
self.queue.queue_main(move |self_| {
- self_.set_status_text("");
+ self_.clear_status_text();
self_.hide_download_button();
self_.hide_beta_text();
self_.hide_stable_text();
@@ -382,7 +382,7 @@ impl<D: AppDelegate + 'static, A: From<UiAppDownloaderParameters<D>> + AppDownlo
let app_sha256 = selected_version.sha256;
let app_size = selected_version.size;
- self_.set_download_text("");
+ self_.clear_download_text();
self_.hide_download_button();
self_.hide_beta_text();
self_.hide_stable_text();
@@ -431,7 +431,7 @@ impl<D: AppDelegate + 'static, A: From<UiAppDownloaderParameters<D>> + AppDownlo
self.queue.queue_main(move |self_| {
self_.set_status_text(&version_label);
- self_.set_download_text("");
+ self_.clear_download_text();
self_.show_download_button();
self_.hide_error_message();
diff --git a/installer-downloader/src/delegate.rs b/installer-downloader/src/delegate.rs
index bc3e4bf84c..a00e33bd13 100644
--- a/installer-downloader/src/delegate.rs
+++ b/installer-downloader/src/delegate.rs
@@ -30,9 +30,15 @@ pub trait AppDelegate {
/// Set status text
fn set_status_text(&mut self, text: &str);
+ /// Clear status text
+ fn clear_status_text(&mut self);
+
/// Set download text
fn set_download_text(&mut self, text: &str);
+ /// Clear download text
+ fn clear_download_text(&mut self);
+
/// Show download progress bar
fn show_download_progress(&mut self);
diff --git a/installer-downloader/src/ui_downloader.rs b/installer-downloader/src/ui_downloader.rs
index 69e405797b..acb6c528e5 100644
--- a/installer-downloader/src/ui_downloader.rs
+++ b/installer-downloader/src/ui_downloader.rs
@@ -49,8 +49,8 @@ impl<Delegate: AppDelegate, Downloader: AppDownloader + Send + 'static> AppDownl
}
Err(err) => {
self.queue.queue_main(move |self_| {
- self_.set_status_text("");
- self_.set_download_text("");
+ self_.clear_status_text();
+ self_.clear_download_text();
self_.hide_download_progress();
self_.hide_download_button();
self_.hide_cancel_button();
@@ -78,8 +78,8 @@ impl<Delegate: AppDelegate, Downloader: AppDownloader + Send + 'static> AppDownl
}
Err(error) => {
self.queue.queue_main(move |self_| {
- self_.set_status_text("");
- self_.set_download_text("");
+ self_.clear_status_text();
+ self_.clear_download_text();
self_.hide_download_progress();
self_.hide_download_button();
self_.hide_cancel_button();
@@ -109,8 +109,8 @@ impl<Delegate: AppDelegate, Downloader: AppDownloader + Send + 'static> AppDownl
}
Err(error) => {
self.queue.queue_main(move |self_| {
- self_.set_status_text("");
- self_.set_download_text("");
+ self_.clear_status_text();
+ self_.clear_download_text();
self_.hide_download_progress();
self_.hide_download_button();
self_.hide_cancel_button();
diff --git a/installer-downloader/src/winapi_impl/delegate.rs b/installer-downloader/src/winapi_impl/delegate.rs
index b4b9793bdd..ce69e818b9 100644
--- a/installer-downloader/src/winapi_impl/delegate.rs
+++ b/installer-downloader/src/winapi_impl/delegate.rs
@@ -40,21 +40,23 @@ impl AppDelegate for AppWindow {
}
fn set_status_text(&mut self, text: &str) {
- if !text.is_empty() {
- self.status_text.set_visible(true);
- self.status_text.set_text(text);
- } else {
- self.status_text.set_visible(false);
- }
+ self.status_text.set_visible(true);
+ self.status_text.set_text(text);
+ }
+
+ fn clear_status_text(&mut self) {
+ self.status_text.set_visible(false);
+ self.status_text.set_text("");
}
fn set_download_text(&mut self, text: &str) {
- if !text.is_empty() {
- self.download_text.set_visible(true);
- self.download_text.set_text(text);
- } else {
- self.download_text.set_visible(false);
- }
+ self.download_text.set_visible(true);
+ self.download_text.set_text(text);
+ }
+
+ fn clear_download_text(&mut self) {
+ self.download_text.set_visible(false);
+ self.download_text.set_text("");
}
fn show_download_progress(&mut self) {
diff --git a/installer-downloader/tests/controller.rs b/installer-downloader/tests/controller.rs
index 0dce2e68e5..f8b26a60e6 100644
--- a/installer-downloader/tests/controller.rs
+++ b/installer-downloader/tests/controller.rs
@@ -234,6 +234,11 @@ impl AppDelegate for FakeAppDelegate {
self.state.status_text = text.to_owned();
}
+ fn clear_status_text(&mut self) {
+ self.state.call_log.push(format!("clear_status_text"));
+ self.state.status_text = "".to_owned();
+ }
+
fn set_download_text(&mut self, text: &str) {
self.state
.call_log
@@ -241,6 +246,11 @@ impl AppDelegate for FakeAppDelegate {
self.state.download_text = text.to_owned();
}
+ fn clear_download_text(&mut self) {
+ self.state.call_log.push(format!("clear_download_text"));
+ self.state.download_text = "".to_owned();
+ }
+
fn show_download_progress(&mut self) {
self.state.call_log.push("show_download_progress".into());
self.state.download_progress_visible = true;
diff --git a/installer-downloader/tests/snapshots/controller__download-2.snap b/installer-downloader/tests/snapshots/controller__download-2.snap
index ee35e8f8ee..44bbde0152 100644
--- a/installer-downloader/tests/snapshots/controller__download-2.snap
+++ b/installer-downloader/tests/snapshots/controller__download-2.snap
@@ -36,7 +36,7 @@ call_log:
- hide_error_message
- on_error_message_retry
- on_error_message_cancel
- - "set_download_text: "
+ - clear_download_text
- hide_download_button
- hide_beta_text
- hide_stable_text
diff --git a/installer-downloader/tests/snapshots/controller__download-3.snap b/installer-downloader/tests/snapshots/controller__download-3.snap
index 5b40b79b9d..c995f67c92 100644
--- a/installer-downloader/tests/snapshots/controller__download-3.snap
+++ b/installer-downloader/tests/snapshots/controller__download-3.snap
@@ -36,7 +36,7 @@ call_log:
- hide_error_message
- on_error_message_retry
- on_error_message_cancel
- - "set_download_text: "
+ - clear_download_text
- hide_download_button
- hide_beta_text
- hide_stable_text
diff --git a/installer-downloader/tests/snapshots/controller__failed_directory_creation.snap b/installer-downloader/tests/snapshots/controller__failed_directory_creation.snap
index 575b9a4c50..505142a91c 100644
--- a/installer-downloader/tests/snapshots/controller__failed_directory_creation.snap
+++ b/installer-downloader/tests/snapshots/controller__failed_directory_creation.snap
@@ -1,6 +1,7 @@
---
source: installer-downloader/tests/controller.rs
expression: delegate.state
+snapshot_kind: text
---
status_text: ""
download_text: ""
@@ -35,7 +36,7 @@ call_log:
- hide_error_message
- on_error_message_retry
- on_error_message_cancel
- - "set_status_text: "
+ - clear_status_text
- hide_download_button
- hide_beta_text
- hide_stable_text
diff --git a/installer-downloader/tests/snapshots/controller__failed_verification.snap b/installer-downloader/tests/snapshots/controller__failed_verification.snap
index ed6177dfea..cd41099d5a 100644
--- a/installer-downloader/tests/snapshots/controller__failed_verification.snap
+++ b/installer-downloader/tests/snapshots/controller__failed_verification.snap
@@ -1,6 +1,7 @@
---
source: installer-downloader/tests/controller.rs
expression: delegate.state
+snapshot_kind: text
---
status_text: ""
download_text: ""
@@ -35,7 +36,7 @@ call_log:
- hide_error_message
- on_error_message_retry
- on_error_message_cancel
- - "set_download_text: "
+ - clear_download_text
- hide_download_button
- hide_beta_text
- hide_stable_text
@@ -48,8 +49,8 @@ call_log:
- "set_download_text: Downloading from mullvad.net... (100%)"
- "set_download_text: Download complete. Verifying..."
- disable_cancel_button
- - "set_status_text: "
- - "set_download_text: "
+ - clear_status_text
+ - clear_download_text
- hide_download_progress
- hide_download_button
- hide_cancel_button