2023-04-18 23:02:37 +08:00
|
|
|
use hbb_common::ResultType;
|
2023-04-19 11:21:37 +08:00
|
|
|
use serde_derive::{Deserialize, Serialize};
|
2023-04-18 23:02:37 +08:00
|
|
|
use serde_json;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::ffi::{c_char, CStr};
|
|
|
|
|
2023-04-19 11:21:37 +08:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2023-04-18 23:02:37 +08:00
|
|
|
pub struct UiButton {
|
|
|
|
key: String,
|
|
|
|
text: String,
|
2023-04-23 15:40:55 +08:00
|
|
|
icon: String, // icon can be int in flutter, but string in other ui framework. And it is flexible to use string.
|
2023-04-18 23:02:37 +08:00
|
|
|
tooltip: String,
|
|
|
|
action: String, // The action to be triggered when the button is clicked.
|
|
|
|
}
|
|
|
|
|
2023-04-19 11:21:37 +08:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2023-04-18 23:02:37 +08:00
|
|
|
pub struct UiCheckbox {
|
|
|
|
key: String,
|
|
|
|
text: String,
|
|
|
|
tooltip: String,
|
|
|
|
action: String, // The action to be triggered when the checkbox is checked or unchecked.
|
|
|
|
}
|
|
|
|
|
2023-04-19 11:21:37 +08:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2023-04-18 23:02:37 +08:00
|
|
|
#[serde(tag = "t", content = "c")]
|
|
|
|
pub enum UiType {
|
|
|
|
Button(UiButton),
|
|
|
|
Checkbox(UiCheckbox),
|
|
|
|
}
|
|
|
|
|
2023-04-20 10:29:24 +08:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2023-04-18 23:02:37 +08:00
|
|
|
pub struct Location {
|
2023-04-19 11:21:37 +08:00
|
|
|
pub ui: HashMap<String, UiType>,
|
2023-04-18 23:02:37 +08:00
|
|
|
}
|
|
|
|
|
2023-04-20 10:29:24 +08:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2023-04-18 23:02:37 +08:00
|
|
|
pub struct ConfigItem {
|
2023-04-19 11:21:37 +08:00
|
|
|
pub key: String,
|
|
|
|
pub default: String,
|
|
|
|
pub description: String,
|
2023-04-18 23:02:37 +08:00
|
|
|
}
|
|
|
|
|
2023-04-24 18:45:22 +08:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2023-04-18 23:02:37 +08:00
|
|
|
pub struct Config {
|
2023-04-23 15:40:55 +08:00
|
|
|
pub shared: Vec<ConfigItem>,
|
2023-04-19 11:21:37 +08:00
|
|
|
pub peer: Vec<ConfigItem>,
|
2023-04-18 23:02:37 +08:00
|
|
|
}
|
|
|
|
|
2023-04-20 10:29:24 +08:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2023-04-18 23:02:37 +08:00
|
|
|
pub struct Desc {
|
|
|
|
id: String,
|
|
|
|
name: String,
|
|
|
|
version: String,
|
|
|
|
description: String,
|
|
|
|
author: String,
|
|
|
|
home: String,
|
|
|
|
license: String,
|
|
|
|
published: String,
|
|
|
|
released: String,
|
|
|
|
github: String,
|
|
|
|
location: Location,
|
|
|
|
config: Config,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Desc {
|
|
|
|
pub fn from_cstr(s: *const c_char) -> ResultType<Self> {
|
|
|
|
let s = unsafe { CStr::from_ptr(s) };
|
|
|
|
Ok(serde_json::from_str(s.to_str()?)?)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn id(&self) -> &str {
|
|
|
|
&self.id
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn name(&self) -> &str {
|
|
|
|
&self.name
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn version(&self) -> &str {
|
|
|
|
&self.version
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn description(&self) -> &str {
|
|
|
|
&self.description
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn author(&self) -> &str {
|
|
|
|
&self.author
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn home(&self) -> &str {
|
|
|
|
&self.home
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn license(&self) -> &str {
|
|
|
|
&self.license
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn published(&self) -> &str {
|
|
|
|
&self.published
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn released(&self) -> &str {
|
|
|
|
&self.released
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn github(&self) -> &str {
|
|
|
|
&self.github
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn location(&self) -> &Location {
|
|
|
|
&self.location
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn config(&self) -> &Config {
|
|
|
|
&self.config
|
|
|
|
}
|
|
|
|
}
|