From 43711454673f55822075f1e6488692b48aeb5e11 Mon Sep 17 00:00:00 2001 From: szymon Date: Tue, 29 Sep 2026 14:09:10 +0200 Subject: [PATCH] feat: implement get_server_caps --- src/functions.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/functions.rs b/src/functions.rs index 8e37e2d..a606191 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -67,8 +67,39 @@ pub fn get_app_icon() -> Option { /// Queries the server capabilities. /// Synchronously queries the server for its capabilities and returns them in a list. -pub fn get_server_caps() -> Vec { - todo!() +pub fn get_server_caps() -> Option> { + let mut vec: Vec = vec![]; + + let list = unsafe { notify_get_server_caps() }; + if list.is_null() { + return None; + } + + let mut current = list; + + loop { + let data = unsafe { *current }.data; + let data_char = data as *const std::os::raw::c_char; + + if !data.is_null() { + let s: String = unsafe { std::ffi::CStr::from_ptr(data_char) } + .to_string_lossy() + .to_string(); + vec.push(s); + } + + unsafe { g_free(data) }; + + if unsafe { *current }.next.is_null() { + break; + } + + current = unsafe { *current }.next; + } + + unsafe { g_list_free(list) }; + + if vec.is_empty() { None } else { Some(vec) } } pub struct ServerInfo {