ssh_commander_core/
vnc_client.rs1use crate::desktop_protocol::{DesktopProtocol, FrameUpdate, VncConfig};
2use anyhow::Result;
3use async_trait::async_trait;
4use tokio::sync::mpsc;
5use tokio_util::sync::CancellationToken;
6
7pub struct VncClient {
18 config: VncConfig,
19 desktop_width: u16,
20 desktop_height: u16,
21 connected: bool,
22}
23
24impl VncClient {
25 pub async fn connect(config: &VncConfig) -> Result<Self> {
31 if config.host.is_empty() {
32 return Err(anyhow::anyhow!("VNC host cannot be empty"));
33 }
34
35 Err(anyhow::anyhow!(
45 "VNC protocol support is not yet implemented. \
46 Connection to {}:{} cannot be established.",
47 config.host,
48 config.port
49 ))
50 }
51
52 #[allow(dead_code)]
54 fn new_disconnected(config: VncConfig) -> Self {
55 Self {
56 desktop_width: 1024,
57 desktop_height: 768,
58 config,
59 connected: false,
60 }
61 }
62}
63
64#[async_trait]
65impl DesktopProtocol for VncClient {
66 async fn start_frame_loop(
67 &self,
68 _frame_tx: mpsc::UnboundedSender<FrameUpdate>,
69 _cancel: CancellationToken,
70 ) -> Result<()> {
71 if !self.connected {
72 return Err(anyhow::anyhow!("VNC client is not connected"));
73 }
74 Ok(())
76 }
77
78 async fn send_key(&self, _key_code: u32, _down: bool) -> Result<()> {
79 if !self.connected {
80 return Err(anyhow::anyhow!("VNC client is not connected"));
81 }
82 Ok(())
84 }
85
86 async fn send_pointer(&self, _x: u16, _y: u16, _button_mask: u8) -> Result<()> {
87 if !self.connected {
88 return Err(anyhow::anyhow!("VNC client is not connected"));
89 }
90 Ok(())
92 }
93
94 async fn request_full_frame(&self) -> Result<()> {
95 if !self.connected {
96 return Err(anyhow::anyhow!("VNC client is not connected"));
97 }
98 Ok(())
100 }
101
102 async fn set_clipboard(&self, _text: String) -> Result<()> {
103 if !self.connected {
104 return Err(anyhow::anyhow!("VNC client is not connected"));
105 }
106 Ok(())
108 }
109
110 fn desktop_size(&self) -> (u16, u16) {
111 (self.desktop_width, self.desktop_height)
112 }
113
114 async fn resize(&mut self, _width: u16, _height: u16) -> Result<()> {
115 Ok(())
118 }
119
120 async fn disconnect(&mut self) -> Result<()> {
121 if self.connected {
122 self.connected = false;
124 tracing::info!(
125 "VNC disconnected from {}:{}",
126 self.config.host,
127 self.config.port
128 );
129 }
130 Ok(())
131 }
132}