Skip to content

Commit 2892725

Browse files
committed
Format code with cargo fmt
1 parent dde966c commit 2892725

31 files changed

Lines changed: 651 additions & 295 deletions

File tree

crates/linglide-auth/src/device.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,17 @@ mod tests {
146146
#[test]
147147
fn test_device_type_parsing() {
148148
assert_eq!("ios".parse::<DeviceType>().unwrap(), DeviceType::Ios);
149-
assert_eq!("android".parse::<DeviceType>().unwrap(), DeviceType::Android);
150-
assert_eq!("browser".parse::<DeviceType>().unwrap(), DeviceType::Browser);
151-
assert_eq!("unknown".parse::<DeviceType>().unwrap(), DeviceType::Unknown);
149+
assert_eq!(
150+
"android".parse::<DeviceType>().unwrap(),
151+
DeviceType::Android
152+
);
153+
assert_eq!(
154+
"browser".parse::<DeviceType>().unwrap(),
155+
DeviceType::Browser
156+
);
157+
assert_eq!(
158+
"unknown".parse::<DeviceType>().unwrap(),
159+
DeviceType::Unknown
160+
);
152161
}
153162
}

crates/linglide-auth/src/pairing.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ impl PairingManager {
184184
}
185185

186186
/// Verify a PIN and complete pairing
187-
pub async fn verify_pin(&self, request: PairingVerifyRequest) -> PairingResult<PairingVerifyResponse> {
187+
pub async fn verify_pin(
188+
&self,
189+
request: PairingVerifyRequest,
190+
) -> PairingResult<PairingVerifyResponse> {
188191
// Find and validate session
189192
let session = {
190193
let sessions = self.sessions.read().await;
@@ -232,7 +235,11 @@ impl PairingManager {
232235
sessions.get(session_id).map(|s| {
233236
// Truncate fingerprint to first 20 chars for QR code
234237
let fp = self.cert_fingerprint.as_ref().map(|f| {
235-
if f.len() > 20 { f[..20].to_string() } else { f.clone() }
238+
if f.len() > 20 {
239+
f[..20].to_string()
240+
} else {
241+
f.clone()
242+
}
236243
});
237244

238245
QrCodeData {

crates/linglide-auth/src/storage.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ mod tests {
195195
let storage = DeviceStorage::with_path(path.clone()).await.unwrap();
196196

197197
// Create device
198-
let device = Device::new("Test".to_string(), DeviceType::Browser, "hash123".to_string());
198+
let device = Device::new(
199+
"Test".to_string(),
200+
DeviceType::Browser,
201+
"hash123".to_string(),
202+
);
199203
let id = device.id.clone();
200204

201205
// Save
@@ -222,8 +226,11 @@ mod tests {
222226
let device_id;
223227
{
224228
let storage = DeviceStorage::with_path(path.clone()).await.unwrap();
225-
let device =
226-
Device::new("Persistent".to_string(), DeviceType::Ios, "hash456".to_string());
229+
let device = Device::new(
230+
"Persistent".to_string(),
231+
DeviceType::Ios,
232+
"hash456".to_string(),
233+
);
227234
device_id = device.id.clone();
228235
storage.save_device(device).await.unwrap();
229236
}

crates/linglide-capture/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ impl ScreenCapture {
3838
Ok(Self::PipeWire(PipeWireCapture::new(width, height)?))
3939
} else {
4040
tracing::info!("Detected X11 session, using MIT-SHM capture");
41-
Ok(Self::X11(X11Capture::new(width, height, offset_x, offset_y)?))
41+
Ok(Self::X11(X11Capture::new(
42+
width, height, offset_x, offset_y,
43+
)?))
4244
}
4345
}
4446

crates/linglide-capture/src/pipewire_capture.rs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ impl PipeWireCapture {
4848
}
4949

5050
pub fn capture(&mut self) -> Result<Frame> {
51-
let data = self.frame_data.lock()
51+
let data = self
52+
.frame_data
53+
.lock()
5254
.map_err(|_| Error::CaptureError("Lock poisoned".into()))?
5355
.clone();
5456

@@ -87,14 +89,16 @@ fn run_capture(
8789
let proxy = Screencast::new().await?;
8890
let session = proxy.create_session().await?;
8991

90-
proxy.select_sources(
91-
&session,
92-
CursorMode::Embedded,
93-
SourceType::Monitor.into(),
94-
false,
95-
None,
96-
PersistMode::DoNot,
97-
).await?;
92+
proxy
93+
.select_sources(
94+
&session,
95+
CursorMode::Embedded,
96+
SourceType::Monitor.into(),
97+
false,
98+
None,
99+
PersistMode::DoNot,
100+
)
101+
.await?;
98102

99103
info!("Please select a screen to share in the dialog...");
100104

@@ -179,16 +183,25 @@ fn run_pipewire(
179183
// Check buffer type
180184
if count < 3 {
181185
let data_type = datas[0].type_();
182-
info!("Buffer type: {:?}, fd: {:?}", data_type, datas[0].as_raw().fd);
186+
info!(
187+
"Buffer type: {:?}, fd: {:?}",
188+
data_type,
189+
datas[0].as_raw().fd
190+
);
183191
}
184192

185193
// Try to get data - for DMA-BUF we need to mmap the fd
186194
let data_result = datas[0].data();
187195

188196
if let Some(slice) = data_result {
189197
if count < 3 {
190-
info!("Frame {}: offset={}, size={}, slice_len={}",
191-
count, offset, size, slice.len());
198+
info!(
199+
"Frame {}: offset={}, size={}, slice_len={}",
200+
count,
201+
offset,
202+
size,
203+
slice.len()
204+
);
192205
}
193206

194207
if size > 0 && offset + size <= slice.len() {
@@ -222,15 +235,20 @@ fn run_pipewire(
222235
);
223236

224237
if ptr != libc::MAP_FAILED {
225-
let mapped_slice = std::slice::from_raw_parts(ptr as *const u8, map_size);
238+
let mapped_slice =
239+
std::slice::from_raw_parts(ptr as *const u8, map_size);
226240

227241
if count < 3 {
228-
info!("DMA-BUF mapped successfully, {} bytes", map_size);
242+
info!(
243+
"DMA-BUF mapped successfully, {} bytes",
244+
map_size
245+
);
229246
}
230247

231248
if let Ok(mut guard) = frame_data_inner.lock() {
232249
let copy_len = map_size.min(expected_size);
233-
guard[..copy_len].copy_from_slice(&mapped_slice[..copy_len]);
250+
guard[..copy_len]
251+
.copy_from_slice(&mapped_slice[..copy_len]);
234252
}
235253

236254
libc::munmap(ptr, map_size);
@@ -266,7 +284,9 @@ fn run_pipewire(
266284

267285
// Run until stopped - iterate the loop and check for shutdown
268286
while running.load(Ordering::SeqCst) {
269-
mainloop.loop_().iterate(std::time::Duration::from_millis(16));
287+
mainloop
288+
.loop_()
289+
.iterate(std::time::Duration::from_millis(16));
270290
}
271291

272292
Ok(())

crates/linglide-capture/src/virtual_display.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ impl VirtualDisplay {
8484
));
8585
}
8686
DeviceNode::get().ok_or_else(|| {
87-
Error::VirtualDisplayCreation("Failed to get EVDI device after adding".to_string())
87+
Error::VirtualDisplayCreation(
88+
"Failed to get EVDI device after adding".to_string(),
89+
)
8890
})?
8991
}
9092
};
@@ -117,9 +119,10 @@ impl VirtualDisplay {
117119

118120
/// Initialize the buffer after mode is received (call this from async context)
119121
pub async fn init_buffer(&mut self) -> Result<()> {
120-
let handle = self.handle.as_ref().ok_or_else(|| {
121-
Error::CaptureError("Virtual display not enabled".to_string())
122-
})?;
122+
let handle = self
123+
.handle
124+
.as_ref()
125+
.ok_or_else(|| Error::CaptureError("Virtual display not enabled".to_string()))?;
123126

124127
let mut handle_guard = handle.lock().await;
125128

@@ -145,7 +148,10 @@ impl VirtualDisplay {
145148
.await
146149
.map_err(|e| Error::CaptureError(format!("Timeout waiting for display mode. Did you enable the display in Settings > Displays? Error: {:?}", e)))?;
147150

148-
info!("Received mode from compositor: {}x{}", mode.width, mode.height);
151+
info!(
152+
"Received mode from compositor: {}x{}",
153+
mode.width, mode.height
154+
);
149155

150156
// Create a buffer for this mode
151157
let buffer_id = handle_guard.new_buffer(&mode);
@@ -176,9 +182,10 @@ impl VirtualDisplay {
176182

177183
/// Capture a frame from the virtual display (async)
178184
pub async fn capture_async(&mut self) -> Result<Frame> {
179-
let handle = self.handle.as_ref().ok_or_else(|| {
180-
Error::CaptureError("Virtual display not enabled".to_string())
181-
})?;
185+
let handle = self
186+
.handle
187+
.as_ref()
188+
.ok_or_else(|| Error::CaptureError("Virtual display not enabled".to_string()))?;
182189

183190
let buffer_id = self.buffer_id.ok_or_else(|| {
184191
Error::CaptureError("Buffer not initialized. Call init_buffer() first".to_string())
@@ -189,9 +196,7 @@ impl VirtualDisplay {
189196
// Request an update - timeout is OK, we'll use the last buffer content
190197
// EVDI only sends updates when there are actual changes on screen
191198
let timeout = Duration::from_millis(50);
192-
let _ = handle_guard
193-
.request_update(buffer_id, timeout)
194-
.await;
199+
let _ = handle_guard.request_update(buffer_id, timeout).await;
195200
// Ignore timeout errors - buffer still has valid data from last update
196201

197202
// Get the buffer data (may be from a previous update if timeout)
@@ -200,9 +205,10 @@ impl VirtualDisplay {
200205
.ok_or_else(|| Error::CaptureError("Buffer not found".to_string()))?;
201206

202207
let bytes = buffer.bytes();
203-
let mode = self.mode.as_ref().ok_or_else(|| {
204-
Error::CaptureError("Mode not set".to_string())
205-
})?;
208+
let mode = self
209+
.mode
210+
.as_ref()
211+
.ok_or_else(|| Error::CaptureError("Mode not set".to_string()))?;
206212

207213
let width = mode.width;
208214
let height = mode.height;

crates/linglide-capture/src/x11_capture.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ impl X11Capture {
2626
/// Create a new X11 capture instance
2727
pub fn new(width: u32, height: u32, offset_x: i32, offset_y: i32) -> Result<Self> {
2828
// Connect to X11
29-
let (conn, screen_num) = xcb::Connection::connect(None)
30-
.map_err(|e| Error::X11Connection(e.to_string()))?;
29+
let (conn, screen_num) =
30+
xcb::Connection::connect(None).map_err(|e| Error::X11Connection(e.to_string()))?;
3131

3232
// Check for SHM extension
3333
let shm_cookie = conn.send_request(&xcb::shm::QueryVersion {});
@@ -40,13 +40,8 @@ impl X11Capture {
4040
let buffer_size = (width * height * 4) as usize;
4141

4242
// Create shared memory segment
43-
let shm_id = unsafe {
44-
libc::shmget(
45-
libc::IPC_PRIVATE,
46-
buffer_size,
47-
libc::IPC_CREAT | 0o777,
48-
)
49-
};
43+
let shm_id =
44+
unsafe { libc::shmget(libc::IPC_PRIVATE, buffer_size, libc::IPC_CREAT | 0o777) };
5045

5146
if shm_id < 0 {
5247
return Err(Error::CaptureError(format!(
@@ -126,9 +121,8 @@ impl X11Capture {
126121

127122
// Copy data from shared memory
128123
let buffer_size = (self.width * self.height * 4) as usize;
129-
let data = unsafe {
130-
std::slice::from_raw_parts(self.shm_addr as *const u8, buffer_size).to_vec()
131-
};
124+
let data =
125+
unsafe { std::slice::from_raw_parts(self.shm_addr as *const u8, buffer_size).to_vec() };
132126

133127
self.sequence += 1;
134128

crates/linglide-core/src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ impl std::str::FromStr for DisplayPosition {
3333
"left-of" | "left" => Ok(DisplayPosition::LeftOf),
3434
"above" | "top" => Ok(DisplayPosition::Above),
3535
"below" | "bottom" => Ok(DisplayPosition::Below),
36-
_ => Err(format!("Invalid position: {}. Use: right-of, left-of, above, below", s)),
36+
_ => Err(format!(
37+
"Invalid position: {}. Use: right-of, left-of, above, below",
38+
s
39+
)),
3740
}
3841
}
3942
}

crates/linglide-core/src/protocol.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,11 @@ pub enum ServerMessage {
177177
codec_data: Option<String>,
178178
},
179179
/// Error message
180-
Error {
181-
message: String,
182-
},
180+
Error { message: String },
183181
/// Server is ready to stream
184182
Ready,
185183
/// Ping for connection keepalive
186-
Ping {
187-
timestamp: u64,
188-
},
184+
Ping { timestamp: u64 },
189185
}
190186

191187
/// Client-to-server control messages
@@ -195,13 +191,9 @@ pub enum ClientMessage {
195191
/// Client is ready to receive video
196192
Ready,
197193
/// Pong response to ping
198-
Pong {
199-
timestamp: u64,
200-
},
194+
Pong { timestamp: u64 },
201195
/// Request quality change
202-
SetQuality {
203-
bitrate: u32,
204-
},
196+
SetQuality { bitrate: u32 },
205197
}
206198

207199
/// Frame metadata for video synchronization

crates/linglide-desktop/src/app.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ impl LinGlideApp {
153153

154154
let elapsed = self.last_countdown_update.elapsed().as_secs() as i64;
155155
if elapsed > 0 {
156-
self.pairing_state.expires_in =
157-
(self.pairing_state.expires_in - elapsed).max(0);
156+
self.pairing_state.expires_in = (self.pairing_state.expires_in - elapsed).max(0);
158157
self.last_countdown_update = Instant::now();
159158

160159
// If expired, clear pairing state

0 commit comments

Comments
 (0)