2023-08-18 07:19:20 +02:00
|
|
|
//! RMenu-Plugin Object Implementations
|
2023-07-18 07:49:07 +02:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2023-08-18 07:19:20 +02:00
|
|
|
/// Methods allowed to Execute Actions on Selection
|
2023-08-17 08:21:55 +02:00
|
|
|
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
2023-08-04 02:22:04 +02:00
|
|
|
#[serde(rename_all = "lowercase")]
|
2023-07-18 07:49:07 +02:00
|
|
|
pub enum Method {
|
2023-08-04 02:22:04 +02:00
|
|
|
Terminal(String),
|
|
|
|
Run(String),
|
2023-08-12 01:24:30 +02:00
|
|
|
Echo(String),
|
2023-08-04 02:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Method {
|
2023-08-18 07:19:20 +02:00
|
|
|
/// Generate the Required Method from a Function
|
2023-08-04 02:22:04 +02:00
|
|
|
pub fn new(exec: String, terminal: bool) -> Self {
|
|
|
|
match terminal {
|
|
|
|
true => Self::Terminal(exec),
|
|
|
|
false => Self::Run(exec),
|
|
|
|
}
|
|
|
|
}
|
2023-07-18 07:49:07 +02:00
|
|
|
}
|
|
|
|
|
2023-08-18 07:19:20 +02:00
|
|
|
/// RMenu Entry Action Definition
|
2023-08-17 08:21:55 +02:00
|
|
|
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
2023-07-18 07:49:07 +02:00
|
|
|
pub struct Action {
|
2023-07-19 00:55:35 +02:00
|
|
|
pub name: String,
|
2023-08-04 02:22:04 +02:00
|
|
|
pub exec: Method,
|
2023-07-18 07:49:07 +02:00
|
|
|
pub comment: Option<String>,
|
|
|
|
}
|
|
|
|
|
2023-07-25 06:53:23 +02:00
|
|
|
impl Action {
|
2023-08-18 07:19:20 +02:00
|
|
|
/// Generate a simple Execution Action
|
|
|
|
pub fn exec(exec: &str) -> Self {
|
2023-07-25 06:53:23 +02:00
|
|
|
Self {
|
|
|
|
name: "main".to_string(),
|
2023-08-04 02:22:04 +02:00
|
|
|
exec: Method::Run(exec.to_string()),
|
2023-07-25 06:53:23 +02:00
|
|
|
comment: None,
|
|
|
|
}
|
|
|
|
}
|
2023-08-18 07:19:20 +02:00
|
|
|
/// Generate a simple Echo Action
|
2023-08-12 01:24:30 +02:00
|
|
|
pub fn echo(echo: &str) -> Self {
|
|
|
|
Self {
|
|
|
|
name: "main".to_string(),
|
|
|
|
exec: Method::Echo(echo.to_string()),
|
|
|
|
comment: None,
|
|
|
|
}
|
|
|
|
}
|
2023-07-25 06:53:23 +02:00
|
|
|
}
|
|
|
|
|
2023-08-18 07:19:20 +02:00
|
|
|
/// RMenu Menu-Entry Implementation
|
2023-08-17 08:21:55 +02:00
|
|
|
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
2023-08-19 04:58:19 +02:00
|
|
|
#[serde(tag = "type", rename = "entry")]
|
2023-07-18 07:49:07 +02:00
|
|
|
pub struct Entry {
|
|
|
|
pub name: String,
|
2023-07-19 00:55:35 +02:00
|
|
|
pub actions: Vec<Action>,
|
2023-07-18 07:49:07 +02:00
|
|
|
pub comment: Option<String>,
|
|
|
|
pub icon: Option<String>,
|
2023-08-17 08:21:55 +02:00
|
|
|
pub icon_alt: Option<String>,
|
2023-07-18 07:49:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Entry {
|
2023-08-18 07:19:20 +02:00
|
|
|
/// Generate a simplified Exec Action Entry
|
2023-07-25 06:53:23 +02:00
|
|
|
pub fn new(name: &str, action: &str, comment: Option<&str>) -> Self {
|
2023-07-18 07:49:07 +02:00
|
|
|
Self {
|
|
|
|
name: name.to_owned(),
|
2023-08-18 07:19:20 +02:00
|
|
|
actions: vec![Action::exec(action)],
|
2023-07-25 06:53:23 +02:00
|
|
|
comment: comment.map(|c| c.to_owned()),
|
2023-07-18 07:49:07 +02:00
|
|
|
icon: Default::default(),
|
2023-08-17 08:21:55 +02:00
|
|
|
icon_alt: Default::default(),
|
2023-07-18 07:49:07 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-18 07:19:20 +02:00
|
|
|
/// Generate a simplified Echo Action Entry
|
2023-08-12 01:24:30 +02:00
|
|
|
pub fn echo(echo: &str, comment: Option<&str>) -> Self {
|
|
|
|
Self {
|
|
|
|
name: echo.to_owned(),
|
|
|
|
actions: vec![Action::echo(echo)],
|
|
|
|
comment: comment.map(|c| c.to_owned()),
|
|
|
|
icon: Default::default(),
|
2023-08-17 08:21:55 +02:00
|
|
|
icon_alt: Default::default(),
|
2023-08-12 01:24:30 +02:00
|
|
|
}
|
|
|
|
}
|
2023-07-18 07:49:07 +02:00
|
|
|
}
|
2023-08-17 08:21:55 +02:00
|
|
|
|
2023-08-19 04:58:19 +02:00
|
|
|
/// Additional Plugin Option Overrides
|
|
|
|
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
|
2023-08-19 10:09:39 +02:00
|
|
|
#[serde(default, tag = "type", rename = "options")]
|
2023-08-19 04:58:19 +02:00
|
|
|
pub struct Options {
|
|
|
|
// base settings
|
2023-08-19 10:09:39 +02:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2023-08-20 19:27:18 +02:00
|
|
|
pub css: Option<String>,
|
2023-08-20 23:12:17 +02:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub page_size: Option<usize>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub page_load: Option<f64>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub jump_dist: Option<usize>,
|
2024-04-09 23:38:28 +02:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub hover_select: Option<bool>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub single_click: Option<bool>,
|
2023-08-19 04:58:19 +02:00
|
|
|
// search settings
|
2023-08-19 10:09:39 +02:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub placeholder: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub search_restrict: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub search_min_length: Option<usize>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub search_max_length: Option<usize>,
|
2023-08-19 04:58:19 +02:00
|
|
|
// key settings
|
2023-08-19 10:09:39 +02:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub key_exec: Option<Vec<String>>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub key_exit: Option<Vec<String>>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub key_move_next: Option<Vec<String>>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub key_move_prev: Option<Vec<String>>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub key_open_menu: Option<Vec<String>>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub key_close_menu: Option<Vec<String>>,
|
2023-08-20 21:04:47 +02:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub key_jump_next: Option<Vec<String>>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub key_jump_prev: Option<Vec<String>>,
|
2023-08-19 04:58:19 +02:00
|
|
|
// window settings
|
2023-08-19 10:09:39 +02:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub title: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub decorate: Option<bool>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2023-08-20 22:59:32 +02:00
|
|
|
pub transparent: Option<bool>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2023-08-19 10:09:39 +02:00
|
|
|
pub fullscreen: Option<bool>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub window_width: Option<f64>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub window_height: Option<f64>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Valid RMenu Plugin Messages
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
#[serde(tag = "type", rename_all = "lowercase")]
|
|
|
|
pub enum Message {
|
|
|
|
Entry(Entry),
|
|
|
|
Options(Options),
|
2023-08-19 04:58:19 +02:00
|
|
|
}
|
|
|
|
|
2023-08-17 08:21:55 +02:00
|
|
|
/// Retrieve EXE of Self
|
|
|
|
#[inline]
|
|
|
|
pub fn self_exe() -> String {
|
|
|
|
std::env::current_exe()
|
|
|
|
.expect("Cannot Find EXE of Self")
|
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
.to_string()
|
|
|
|
}
|