flare_im_core/client/
sys_handler.rs1use crate::client::client::ClientState;
2use flare_core::error::Result;
3use async_trait::async_trait;
4use log::debug;
5use flare_core::flare_net::net::Command;
6
7#[async_trait]
8pub trait ClientSystemHandler: Send + Sync + 'static {
9 async fn login_out(&self) -> Result<()>;
11
12 async fn set_background(&self) -> Result<()>;
14
15 async fn set_language(&self) -> Result<()>;
17
18 async fn kick_online(&self) -> Result<()>;
20
21 async fn close(&self) -> Result<()>;
23
24 async fn on_state_change(&self, state: ClientState);
26 fn supported_commands(&self) -> Vec<Command>{
28 vec![Command::LoginOut , Command::SetBackground ,
29 Command::SetLanguage , Command::KickOnline ,
30 Command::Close]
31 }
32
33 fn supports_command(&self, command: Command) -> bool {
35 self.supported_commands().contains(&command)
36 }
37}
38
39pub struct DefClientSystemHandler;
41
42impl DefClientSystemHandler {
43 pub fn new() -> Self {
44 Self
45 }
46}
47
48#[async_trait]
49impl ClientSystemHandler for DefClientSystemHandler {
50 async fn login_out(&self) -> Result<()> {
51 debug!("处理退出登录");
52 Ok(())
53 }
54
55 async fn set_background(&self) -> Result<()> {
56 debug!("处理设置后台运行");
57 Ok(())
58 }
59
60 async fn set_language(&self) -> Result<()> {
61 debug!("处理设置语言");
62 Ok(())
63 }
64
65 async fn kick_online(&self) -> Result<()> {
66 debug!("处理强制下线");
67 Ok(())
68 }
69
70 async fn close(&self) -> Result<()> {
71 debug!("处理关闭连接");
72 Ok(())
73 }
74
75 async fn on_state_change(&self, state: ClientState) {
76 debug!("连接状态变化: {:?}", state);
77 }
78}