You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
707 B

use std::ffi::{c_char, c_double, CStr, CString};
#[no_mangle]
pub static id: &str = "weather";
#[no_mangle]
pub static name: &str = "Weather";
#[no_mangle]
pub extern "C" fn panel() -> *const c_char {
str_to_ptr(include_str!("./panel/dist/index.js"))
}
#[no_mangle]
pub extern "C" fn get_priority(data: *const c_char) -> c_double {
if ptr_to_string(data).starts_with("wttr") {
69.0
} else {
0.0
}
}
fn ptr_to_string(c_buf: *const c_char) -> String {
let c_str: &CStr = unsafe { CStr::from_ptr(c_buf) };
let str_slice: &str = c_str.to_str().unwrap();
let str_buf: String = str_slice.to_owned();
str_buf
}
fn str_to_ptr(str: &str) -> *const c_char {
CString::new(str).unwrap().into_raw()
}