diff --git a/scripts/showen_v2.service b/scripts/showen_v2.service new file mode 100644 index 0000000..1a7d60c --- /dev/null +++ b/scripts/showen_v2.service @@ -0,0 +1,19 @@ +[Unit] +Description=ShowenV2 — 数字生命窗口平台 +After=network.target dbus.service +Wants=network.target + +[Service] +Type=simple +User=showen +Environment=DISPLAY=:0 +Environment=XAUTHORITY=/home/showen/.Xauthority +WorkingDirectory=/home/showen/Showen/ShowenV2 +ExecStart=/home/showen/Showen/ShowenV2/target/release/showen_v2 --config /home/showen/Showen/ShowenV2/configs/dog_state_machine.json +Restart=on-failure +RestartSec=3 +StandardOutput=journal +StandardError=journal + +[Install] +WantedBy=graphical.target diff --git a/src/plugins/video/state_machine.rs b/src/plugins/video/state_machine.rs index 73baea9..062d929 100644 --- a/src/plugins/video/state_machine.rs +++ b/src/plugins/video/state_machine.rs @@ -50,6 +50,13 @@ impl StateMachine { return Ok(false); } + // 有待执行的触发器时,跳过 sequence 剩余 step,立即切换状态 + if self.pending_trigger_target.is_some() { + let target_state = self.pending_trigger_target.take().unwrap(); + self.transition_to_state(&target_state)?; + return Ok(self.current_state != old_state); + } + let sequence_len = self .current_state_config() .ok_or_else(|| anyhow::anyhow!("当前状态不存在: {}", self.current_state))? @@ -410,16 +417,10 @@ mod tests { assert_eq!(machine.current_state, "idle"); assert_eq!(machine.current_loop_remaining, 1); - assert!(!machine - .on_video_completed() - .expect("should advance within same state")); - assert_eq!(machine.current_sequence_index, 1); - assert_eq!(machine.current_loop_remaining, 1); - assert_eq!(machine.current_video_id().as_deref(), Some("tail")); - + // 当前 step 播完后,有 pending trigger 应立即跳转,跳过后续 step assert!(machine .on_video_completed() - .expect("pending trigger should fire at sequence end")); + .expect("pending trigger should fire after current step ends")); assert_eq!(machine.current_state, "called"); assert_eq!(machine.current_video_id().as_deref(), Some("called")); assert!(!machine.has_pending_trigger());