From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 4DE101FF187 for ; Tue, 2 Dec 2025 11:02:22 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7D37AAA31; Tue, 2 Dec 2025 11:02:46 +0100 (CET) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Tue, 2 Dec 2025 11:02:39 +0100 Message-ID: <20251202100239.117392-1-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1764669720118 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.032 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH proxmox-yew-comp] apt package manager: add distinct message type to avoid spurious subscription popups X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" The freshly introduced subscription check works via sending a message to the component which is then processed by the `update` function. When implementing, it was overlooked that there is was already a selection change listener set up to send messages on selection change, which led to the behavior of triggering the subscription check whenever a package was selected by the list. This is fixed by adding a distinct Message enum type with variants for the selection change event and the check subscription event. Signed-off-by: Lukas Wagner --- src/apt_package_manager.rs | 55 +++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/apt_package_manager.rs b/src/apt_package_manager.rs index 78e82a0..0b4ae2e 100644 --- a/src/apt_package_manager.rs +++ b/src/apt_package_manager.rs @@ -154,6 +154,12 @@ pub enum ViewState { ShowSubscriptionPopup, } +/// Messages for [`ProxmoxAptManager::update`] +pub enum Msg { + CheckSubscription, + SelectionChange, +} + pub struct ProxmoxAptPackageManager { tree_store: TreeStore, selection: Selection, @@ -163,13 +169,13 @@ pub struct ProxmoxAptPackageManager { impl LoadableComponent for ProxmoxAptPackageManager { type Properties = AptPackageManager; - type Message = (); + type Message = Msg; type ViewState = ViewState; fn create(ctx: &LoadableComponentContext) -> Self { let tree_store = TreeStore::new().view_root(false); let columns = Self::columns(ctx, tree_store.clone()); - let selection = Selection::new().on_select(ctx.link().callback(|_| ())); + let selection = Selection::new().on_select(ctx.link().callback(|_| Msg::SelectionChange)); Self { tree_store, @@ -179,27 +185,32 @@ impl LoadableComponent for ProxmoxAptPackageManager { } } - fn update(&mut self, ctx: &LoadableComponentContext, _msg: Self::Message) -> bool { - let link = ctx.link().clone(); - let props = ctx.props(); - let url = props - .clone() - .subscription_url - .unwrap_or("/nodes/localhost/subscription".into()); - let task_base_url = props.task_base_url.clone(); - let command = format!("{}/update", props.base_url); - self.async_pool.spawn(async move { - let data = crate::http_get::(url.as_str(), None).await; - let is_active = subscription_is_active(&Some(data)); + fn update(&mut self, ctx: &LoadableComponentContext, msg: Self::Message) -> bool { + match msg { + Msg::CheckSubscription => { + let link = ctx.link().clone(); + let props = ctx.props(); + let url = props + .clone() + .subscription_url + .unwrap_or("/nodes/localhost/subscription".into()); + let task_base_url = props.task_base_url.clone(); + let command = format!("{}/update", props.base_url); + self.async_pool.spawn(async move { + let data = crate::http_get::(url.as_str(), None).await; + let is_active = subscription_is_active(&Some(data)); - if is_active { - link.task_base_url(task_base_url); - link.start_task(&command, None, false); - } else { - link.change_view(Some(ViewState::ShowSubscriptionPopup)); + if is_active { + link.task_base_url(task_base_url); + link.start_task(&command, None, false); + } else { + link.change_view(Some(ViewState::ShowSubscriptionPopup)); + } + }); + true } - }); - true + Msg::SelectionChange => true, + } } fn load( @@ -255,7 +266,7 @@ impl LoadableComponent for ProxmoxAptPackageManager { move |_| { if sub_check { - link.send_message(()); + link.send_message(Msg::CheckSubscription); } else { link.start_task(&command, None, false); } -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel