From 2954fc5ce35126e4cf9ebfc64043c0e52a990e01 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 27 Oct 2025 17:38:28 +0800 Subject: update: ActionContext 1. Rename `local` to `proc_on_local` 2. Add `is_remote_action` --- crates/system_action/src/action.rs | 27 ++++++++++++++++++------- crates/vcs_actions/src/actions/local_actions.rs | 8 ++++---- 2 files changed, 24 insertions(+), 11 deletions(-) (limited to 'crates') diff --git a/crates/system_action/src/action.rs b/crates/system_action/src/action.rs index 8a6180a..9eef1db 100644 --- a/crates/system_action/src/action.rs +++ b/crates/system_action/src/action.rs @@ -23,7 +23,10 @@ where #[derive(Default)] pub struct ActionContext { /// Whether the action is executed locally or remotely - local: bool, + proc_on_local: bool, + + /// Whether the action being executed in the current context is a remote action + is_remote_action: bool, /// The name of the action being executed action_name: String, @@ -42,7 +45,7 @@ impl ActionContext { /// Generate local context pub fn local() -> Self { ActionContext { - local: true, + proc_on_local: true, ..Default::default() } } @@ -50,7 +53,7 @@ impl ActionContext { /// Generate remote context pub fn remote() -> Self { ActionContext { - local: false, + proc_on_local: false, ..Default::default() } } @@ -75,13 +78,23 @@ impl ActionContext { impl ActionContext { /// Whether the action is executed locally - pub fn is_local(&self) -> bool { - self.local + pub fn is_proc_on_local(&self) -> bool { + self.proc_on_local } /// Whether the action is executed remotely - pub fn is_remote(&self) -> bool { - !self.local + pub fn is_proc_on_remote(&self) -> bool { + !self.proc_on_local + } + + /// Whether the action being executed in the current context is a remote action + pub fn is_remote_action(&self) -> bool { + self.is_remote_action + } + + /// Set whether the action being executed in the current context is a remote action + pub fn set_is_remote_action(&mut self, is_remote_action: bool) { + self.is_remote_action = is_remote_action; } /// Get the connection instance in the current context diff --git a/crates/vcs_actions/src/actions/local_actions.rs b/crates/vcs_actions/src/actions/local_actions.rs index c2d9f4f..e2788ff 100644 --- a/crates/vcs_actions/src/actions/local_actions.rs +++ b/crates/vcs_actions/src/actions/local_actions.rs @@ -13,10 +13,10 @@ pub async fn hello_world_action(ctx: ActionContext, _n: ()) -> Result<(), TcpTar )); }; - if ctx.is_local() { + if ctx.is_proc_on_local() { // Local execution - communication is handled by on_proc_begin info!("Hello World action executed locally"); - } else if ctx.is_remote() { + } else if ctx.is_proc_on_remote() { // Remote execution - read the message from the client let read = instance.lock().await.read_text().await?; info!("{}", read) @@ -37,11 +37,11 @@ pub async fn set_upstream_vault_action( )); }; - if ctx.is_local() { + if ctx.is_proc_on_local() { // Invoke on local // Send the message to the server let _ = instance.lock().await.write_text("Hello World!").await; - } else if ctx.is_remote() { + } else if ctx.is_proc_on_remote() { // Remote execution - read the message from the client let read = instance.lock().await.read_text().await?; info!("Received: {}", read) -- cgit