diff --git a/dev_plugin/gauntlet.toml b/dev_plugin/gauntlet.toml index 1c66244..9511ee9 100644 --- a/dev_plugin/gauntlet.toml +++ b/dev_plugin/gauntlet.toml @@ -5,7 +5,8 @@ A reasonably long plugin description that doesn't contain any usefull informatio """ [[preferences]] -name = 'testBool' +id = 'testBool' +name = 'Test Boolean' type = 'bool' default = true description = "test bool description" @@ -31,42 +32,49 @@ description = "test action description 2" shortcut = { key = 'B', kind = 'main'} [[entrypoint.preferences]] -name = 'testBool' +id = 'testBool' +name = 'Test Boolean' type = 'bool' default = true description = "test bool description" [[entrypoint.preferences]] -name = 'testEnum' +id = 'testEnum' +name = 'Test Enum' type = 'enum' default = 'item' enum_values = [{ label = 'Item', value = 'item'}, { label = 'Item 2', value = 'item_2'}] description = "test enum description" [[entrypoint.preferences]] -name = 'testListOfStrings' +id = 'testListOfStrings' +name = 'Test List of Strings' type = 'list_of_strings' description = "test list of strings description" [[entrypoint.preferences]] -name = 'testListOfNumbers' +id = 'testListOfNumbers' +name = 'Test List of Numbers' type = 'list_of_numbers' description = "test list of numbers description" [[entrypoint.preferences]] -name = 'testListOfEnums' +id = 'testListOfEnums' +name = 'Test List of Enums' type = 'list_of_enums' description = "test list of enums description" enum_values = [{ label = 'Item', value = 'item'}, { label = 'Item 2', value = 'item_2'}] [[entrypoint.preferences]] -name = 'testNum' +id = 'testNum' +name = 'Test Num' type = 'number' default = 2 description = "test number description" [[entrypoint.preferences]] -name = 'testStr' +id = 'testStr' +name = 'Test Str' type = 'string' default = 'test_value' description = "test string description" diff --git a/rust/common/src/model.rs b/rust/common/src/model.rs index ad3fa54..ccb89fc 100644 --- a/rust/common/src/model.rs +++ b/rust/common/src/model.rs @@ -325,31 +325,38 @@ pub enum PluginPreferenceUserData { #[derive(Debug, Clone)] pub enum PluginPreference { Number { + name: String, default: Option, description: String, }, String { + name: String, default: Option, description: String, }, Enum { + name: String, default: Option, description: String, enum_values: Vec, }, Bool { + name: String, default: Option, description: String, }, ListOfStrings { + name: String, default: Option>, description: String, }, ListOfNumbers { + name: String, default: Option>, description: String, }, ListOfEnums { + name: String, default: Option>, enum_values: Vec, description: String, diff --git a/rust/common/src/rpc/backend_api.rs b/rust/common/src/rpc/backend_api.rs index c448d82..8686cb8 100644 --- a/rust/common/src/rpc/backend_api.rs +++ b/rust/common/src/rpc/backend_api.rs @@ -365,11 +365,11 @@ impl BackendApi { }) } - pub async fn set_preference_value(&mut self, plugin_id: PluginId, entrypoint_id: Option, name: String, user_data: PluginPreferenceUserData) -> Result<(), BackendApiError> { + pub async fn set_preference_value(&mut self, plugin_id: PluginId, entrypoint_id: Option, id: String, user_data: PluginPreferenceUserData) -> Result<(), BackendApiError> { let request = RpcSetPreferenceValueRequest { plugin_id: plugin_id.to_string(), entrypoint_id: entrypoint_id.map(|id| id.to_string()).unwrap_or_default(), - preference_name: name, + preference_id: id, preference_value: Some(plugin_preference_user_data_to_rpc(user_data)), }; diff --git a/rust/common/src/rpc/backend_server.rs b/rust/common/src/rpc/backend_server.rs index 747bae5..997b573 100644 --- a/rust/common/src/rpc/backend_server.rs +++ b/rust/common/src/rpc/backend_server.rs @@ -79,7 +79,7 @@ pub trait BackendServer { &self, plugin_id: PluginId, entrypoint_id: Option, - preference_name: String, + preference_id: String, preference_value: PluginPreferenceUserData ) -> anyhow::Result<()>; @@ -203,10 +203,10 @@ impl RpcBackend for RpcBackendServerImpl { Some(EntrypointId::from_string(request.entrypoint_id)) }; - let preference_name = request.preference_name; + let preference_id = request.preference_id; let preference_value = request.preference_value.unwrap(); - self.server.set_preference_value(plugin_id, entrypoint_id, preference_name, plugin_preference_user_data_from_rpc(preference_value)) + self.server.set_preference_value(plugin_id, entrypoint_id, preference_id, plugin_preference_user_data_from_rpc(preference_value)) .await .map_err(|err| Status::internal(format!("{:#}", err)))?; diff --git a/rust/common/src/rpc/grpc_convert.rs b/rust/common/src/rpc/grpc_convert.rs index 78e6762..ca5f46a 100644 --- a/rust/common/src/rpc/grpc_convert.rs +++ b/rust/common/src/rpc/grpc_convert.rs @@ -2,9 +2,9 @@ use std::collections::HashMap; use anyhow::anyhow; -use crate::model::{EntrypointId, PluginId, PluginPreference, PluginPreferenceUserData, PreferenceEnumValue, UiPropertyValue, SearchResult, SearchResultEntrypointType, UiWidget}; -use crate::rpc::grpc::{rpc_ui_property_value, RpcEntrypointTypeSearchResult, RpcEnumValue, RpcPluginPreference, RpcPluginPreferenceUserData, RpcPluginPreferenceValueType, RpcSearchResult, RpcUiPropertyValue, RpcUiPropertyValueObject, RpcUiWidget, RpcUiWidgetId}; +use crate::model::{EntrypointId, PluginId, PluginPreference, PluginPreferenceUserData, PreferenceEnumValue, SearchResult, SearchResultEntrypointType, UiPropertyValue, UiWidget}; use crate::rpc::grpc::rpc_ui_property_value::Value; +use crate::rpc::grpc::{RpcEntrypointTypeSearchResult, RpcEnumValue, RpcPluginPreference, RpcPluginPreferenceUserData, RpcPluginPreferenceValueType, RpcSearchResult, RpcUiPropertyValue, RpcUiPropertyValueObject, RpcUiWidget, RpcUiWidgetId}; pub(crate) fn ui_widget_to_rpc(value: UiWidget) -> RpcUiWidget { let children = value.widget_children.into_iter() @@ -276,26 +276,29 @@ pub fn plugin_preference_user_data_to_rpc(value: PluginPreferenceUserData) -> Rp pub fn plugin_preference_to_rpc(value: PluginPreference) -> RpcPluginPreference { match value { - PluginPreference::Number { default, description } => { + PluginPreference::Number { name, default, description } => { RpcPluginPreference { r#type: RpcPluginPreferenceValueType::Number.into(), - default: default.map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::Number(value)) }), + default: default.map(|value| RpcUiPropertyValue { value: Some(Value::Number(value)) }), + name, description, ..RpcPluginPreference::default() } } - PluginPreference::String { default, description } => { + PluginPreference::String { name, default, description } => { RpcPluginPreference { r#type: RpcPluginPreferenceValueType::String.into(), - default: default.map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::String(value)) }), + default: default.map(|value| RpcUiPropertyValue { value: Some(Value::String(value)) }), + name, description, ..RpcPluginPreference::default() } } - PluginPreference::Enum { default, description, enum_values } => { + PluginPreference::Enum { name, default, description, enum_values } => { RpcPluginPreference { r#type: RpcPluginPreferenceValueType::Enum.into(), - default: default.map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::String(value)) }), + default: default.map(|value| RpcUiPropertyValue { value: Some(Value::String(value)) }), + name, description, enum_values: enum_values.into_iter() .map(|value| RpcEnumValue { label: value.label, value: value.value }) @@ -303,34 +306,38 @@ pub fn plugin_preference_to_rpc(value: PluginPreference) -> RpcPluginPreference ..RpcPluginPreference::default() } } - PluginPreference::Bool { default, description } => { + PluginPreference::Bool { name, default, description } => { RpcPluginPreference { r#type: RpcPluginPreferenceValueType::Bool.into(), - default: default.map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::Bool(value)) }), + default: default.map(|value| RpcUiPropertyValue { value: Some(Value::Bool(value)) }), + name, description, ..RpcPluginPreference::default() } } - PluginPreference::ListOfStrings { default, description } => { + PluginPreference::ListOfStrings { name, default, description } => { RpcPluginPreference { r#type: RpcPluginPreferenceValueType::ListOfStrings.into(), - default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::String(value)) }).collect()).unwrap_or(vec![]), + default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(Value::String(value)) }).collect()).unwrap_or(vec![]), + name, description, ..RpcPluginPreference::default() } } - PluginPreference::ListOfNumbers { default, description } => { + PluginPreference::ListOfNumbers { name, default, description } => { RpcPluginPreference { r#type: RpcPluginPreferenceValueType::ListOfNumbers.into(), - default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::Number(value)) }).collect()).unwrap_or(vec![]), + default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(Value::Number(value)) }).collect()).unwrap_or(vec![]), + name, description, ..RpcPluginPreference::default() } } - PluginPreference::ListOfEnums { default, enum_values, description } => { + PluginPreference::ListOfEnums { name, default, enum_values, description } => { RpcPluginPreference { r#type: RpcPluginPreferenceValueType::ListOfEnums.into(), - default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::String(value)) }).collect()).unwrap_or(vec![]), + default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(Value::String(value)) }).collect()).unwrap_or(vec![]), + name, description, enum_values: enum_values.into_iter() .map(|value| RpcEnumValue { label: value.label, value: value.value }) @@ -355,6 +362,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc PluginPreference::Number { default, + name: value.name, description: value.description, } } @@ -369,6 +377,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc PluginPreference::String { default, + name: value.name, description: value.description, } } @@ -383,6 +392,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc PluginPreference::Enum { default, + name: value.name, description: value.description, enum_values: value.enum_values.into_iter() .map(|value| PreferenceEnumValue { label: value.label, value: value.value }) @@ -400,6 +410,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc PluginPreference::Bool { default, + name: value.name, description: value.description, } } @@ -423,6 +434,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc PluginPreference::ListOfStrings { default: default_list, + name: value.name, description: value.description, } } @@ -446,6 +458,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc PluginPreference::ListOfNumbers { default: default_list, + name: value.name, description: value.description, } } @@ -469,6 +482,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc PluginPreference::ListOfEnums { default: default_list, + name: value.name, enum_values: value.enum_values.into_iter() .map(|value| PreferenceEnumValue { label: value.label, value: value.value }) .collect(), diff --git a/rust/management_client/src/views/plugins.rs b/rust/management_client/src/views/plugins.rs index ead70a7..8beca8d 100644 --- a/rust/management_client/src/views/plugins.rs +++ b/rust/management_client/src/views/plugins.rs @@ -152,15 +152,15 @@ impl ManagementAppPluginsState { } ManagementAppPluginMsgIn::PluginPreferenceMsg(msg) => { match msg { - PluginPreferencesMsg::UpdatePreferenceValue { plugin_id, entrypoint_id, name, user_data } => { + PluginPreferencesMsg::UpdatePreferenceValue { plugin_id, entrypoint_id, id, user_data } => { self.preference_user_data - .insert((plugin_id.clone(), entrypoint_id.clone(), name.clone()), user_data.clone()); + .insert((plugin_id.clone(), entrypoint_id.clone(), id.clone()), user_data.clone()); let mut backend_api = backend_api.clone(); Command::perform( async move { - backend_api.set_preference_value(plugin_id, entrypoint_id, name, user_data.to_user_data()) + backend_api.set_preference_value(plugin_id, entrypoint_id, id, user_data.to_user_data()) .await?; Ok(()) @@ -228,13 +228,13 @@ impl ManagementAppPluginsState { .map(|(plugin_id, plugin)| { let mut result = vec![]; - for (name, user_data) in &plugin.preferences_user_data { - result.push(((plugin_id.clone(), None, name.clone()), PluginPreferenceUserDataState::from_user_data(user_data.clone()))) + for (id, user_data) in &plugin.preferences_user_data { + result.push(((plugin_id.clone(), None, id.clone()), PluginPreferenceUserDataState::from_user_data(user_data.clone()))) } for (entrypoint_id, entrypoint) in &plugin.entrypoints { - for (name, user_data) in &entrypoint.preferences_user_data { - result.push(((plugin_id.clone(), Some(entrypoint_id.clone()), name.clone()), PluginPreferenceUserDataState::from_user_data(user_data.clone()))) + for (id, user_data) in &entrypoint.preferences_user_data { + result.push(((plugin_id.clone(), Some(entrypoint_id.clone()), id.clone()), PluginPreferenceUserDataState::from_user_data(user_data.clone()))) } } diff --git a/rust/management_client/src/views/plugins/preferences.rs b/rust/management_client/src/views/plugins/preferences.rs index c5d11ea..faa0f0c 100644 --- a/rust/management_client/src/views/plugins/preferences.rs +++ b/rust/management_client/src/views/plugins/preferences.rs @@ -15,7 +15,7 @@ pub enum PluginPreferencesMsg { UpdatePreferenceValue { plugin_id: PluginId, entrypoint_id: Option, - name: String, + id: String, user_data: PluginPreferenceUserDataState }, } @@ -46,13 +46,25 @@ pub fn preferences_ui<'a>( preferences.sort_by_key(|(&ref key, _)| key); - for (preference_name, preference) in preferences { + for (preference_id, preference) in preferences { let plugin_id = plugin_id.clone(); let entrypoint_id = entrypoint_id.clone(); - let user_data = preference_user_data.get(&(plugin_id.clone(), entrypoint_id.clone(), preference_name.clone())); + let user_data = preference_user_data.get(&(plugin_id.clone(), entrypoint_id.clone(), preference_id.clone())); + let (preference_name, description) = match preference { + PluginPreference::Number { name, description, .. } => (name, description), + PluginPreference::String { name, description, .. } => (name, description), + PluginPreference::Enum { name, description, .. } => (name, description), + PluginPreference::Bool { name, description, .. } => (name, description), + PluginPreference::ListOfStrings { name, description, .. } => (name, description), + PluginPreference::ListOfNumbers { name, description, .. } => (name, description), + PluginPreference::ListOfEnums { name, description, .. } => (name, description), + }; + + let preference_id = preference_id.to_owned(); let preference_name = preference_name.to_owned(); + let description = description.to_owned(); let preference_label: Element<_> = text(&preference_name) .size(14) @@ -65,16 +77,6 @@ pub fn preferences_ui<'a>( column_content.push(preference_label); - let description = match preference { - PluginPreference::Number { description, .. } => description, - PluginPreference::String { description, .. } => description, - PluginPreference::Enum { description, .. } => description, - PluginPreference::Bool { description, .. } => description, - PluginPreference::ListOfStrings { description, .. } => description, - PluginPreference::ListOfNumbers { description, .. } => description, - PluginPreference::ListOfEnums { description, .. } => description, - }; - if !description.trim().is_empty() { let description = container(text(description)) .padding(Padding::from([4.0, 8.0])) @@ -102,7 +104,7 @@ pub fn preferences_ui<'a>( PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::Number { value: Some(value), }, @@ -130,7 +132,7 @@ pub fn preferences_ui<'a>( PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::String { value: Some(value), }, @@ -166,7 +168,7 @@ pub fn preferences_ui<'a>( Box::new(move |item: SelectItem| PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::Enum { value: Some(item.value), }, @@ -194,7 +196,7 @@ pub fn preferences_ui<'a>( PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::Bool { value: Some(value), }, @@ -239,7 +241,7 @@ pub fn preferences_ui<'a>( .on_press(PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::ListOfStrings { value, new_value: new_value.clone(), @@ -279,7 +281,7 @@ pub fn preferences_ui<'a>( Some(PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::ListOfStrings { value: Some(save_value), new_value: "".to_owned(), @@ -305,7 +307,7 @@ pub fn preferences_ui<'a>( .on_input(move |new_value| PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::ListOfStrings { value: value.clone(), new_value, @@ -356,7 +358,7 @@ pub fn preferences_ui<'a>( .on_press(PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::ListOfNumbers { value, new_value: new_value.clone(), @@ -399,7 +401,7 @@ pub fn preferences_ui<'a>( .on_press(PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::ListOfNumbers { value: Some(save_value), new_value: 0.0, @@ -421,7 +423,7 @@ pub fn preferences_ui<'a>( PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::ListOfNumbers { value: value.clone(), new_value, @@ -471,7 +473,7 @@ pub fn preferences_ui<'a>( .on_press(PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::ListOfEnums { value, new_value: new_value.clone(), @@ -511,7 +513,7 @@ pub fn preferences_ui<'a>( Some(PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::ListOfEnums { value: Some(save_value), new_value: None, @@ -545,7 +547,7 @@ pub fn preferences_ui<'a>( Box::new(move |new_value: SelectItem| PluginPreferencesMsg::UpdatePreferenceValue { plugin_id: plugin_id.clone(), entrypoint_id: entrypoint_id.clone(), - name: preference_name.to_owned(), + id: preference_id.to_owned(), user_data: PluginPreferenceUserDataState::ListOfEnums { value: value.clone(), new_value: Some(new_value), diff --git a/rust/server/src/plugins/data_db_repository.rs b/rust/server/src/plugins/data_db_repository.rs index 646bf5c..187412f 100644 --- a/rust/server/src/plugins/data_db_repository.rs +++ b/rust/server/src/plugins/data_db_repository.rs @@ -231,37 +231,44 @@ pub enum DbPluginActionShortcutKind { pub enum DbPluginPreference { #[serde(rename = "number")] Number { + name: Option, // option for db backwards compatibility, in settings id will be shown default: Option, description: String, }, #[serde(rename = "string")] String { + name: Option, default: Option, description: String, }, #[serde(rename = "enum")] Enum { + name: Option, default: Option, description: String, enum_values: Vec, }, #[serde(rename = "bool")] Bool { + name: Option, default: Option, description: String, }, #[serde(rename = "list_of_strings")] ListOfStrings { + name: Option, default: Option>, description: String, }, #[serde(rename = "list_of_numbers")] ListOfNumbers { + name: Option, default: Option>, description: String, }, #[serde(rename = "list_of_enums")] ListOfEnums { + name: Option, default: Option>, enum_values: Vec, description: String, @@ -793,7 +800,7 @@ impl DataDbRepository { } } - pub async fn set_preference_value(&self, plugin_id: String, entrypoint_id: Option, user_data_name: String, user_data_value: DbPluginPreferenceUserData) -> anyhow::Result<()> { + pub async fn set_preference_value(&self, plugin_id: String, entrypoint_id: Option, preference_id: String, value: DbPluginPreferenceUserData) -> anyhow::Result<()> { let mut tx = self.pool.begin().await?; match entrypoint_id { @@ -802,7 +809,7 @@ impl DataDbRepository { .await? .preferences_user_data; - user_data.insert(user_data_name, user_data_value); + user_data.insert(preference_id, value); // language=SQLite sqlx::query("UPDATE plugin SET preferences_user_data = ?1 WHERE id = ?2") @@ -816,7 +823,7 @@ impl DataDbRepository { .await? .preferences_user_data; - user_data.insert(user_data_name, user_data_value); + user_data.insert(preference_id, value); // language=SQLite sqlx::query("UPDATE plugin_entrypoint SET preferences_user_data = ?1 WHERE id = ?2 AND plugin_id = ?3") diff --git a/rust/server/src/plugins/loader.rs b/rust/server/src/plugins/loader.rs index 61c7c29..81fbe7f 100644 --- a/rust/server/src/plugins/loader.rs +++ b/rust/server/src/plugins/loader.rs @@ -273,24 +273,24 @@ impl PluginLoader { preferences: entrypoint.preferences .into_iter() .map(|preference| match preference { - PluginManifestPreference::Number { name, default, description } => (name, DbPluginPreference::Number { default, description }), - PluginManifestPreference::String { name, default, description } => (name, DbPluginPreference::String { default, description }), - PluginManifestPreference::Enum { name, default, description, enum_values } => { + PluginManifestPreference::Number { id, name, default, description } => (id, DbPluginPreference::Number { name: Some(name), default, description }), + PluginManifestPreference::String { id, name, default, description } => (id, DbPluginPreference::String { name: Some(name), default, description }), + PluginManifestPreference::Enum { id, name, default, description, enum_values } => { let enum_values = enum_values.into_iter() .map(|PluginManifestPreferenceEnumValue { label, value } | DbPreferenceEnumValue { label, value }) .collect(); - (name, DbPluginPreference::Enum { default, description, enum_values }) + (id, DbPluginPreference::Enum { name: Some(name), default, description, enum_values }) }, - PluginManifestPreference::Bool { name, default, description } => (name, DbPluginPreference::Bool { default, description }), - PluginManifestPreference::ListOfStrings { name, description } => (name, DbPluginPreference::ListOfStrings { default: None, description }), - PluginManifestPreference::ListOfNumbers { name, description } => (name, DbPluginPreference::ListOfNumbers { default: None, description }), - PluginManifestPreference::ListOfEnums { name, description, enum_values } => { + PluginManifestPreference::Bool { id, name, default, description } => (id, DbPluginPreference::Bool { name: Some(name), default, description }), + PluginManifestPreference::ListOfStrings { id, name, description } => (id, DbPluginPreference::ListOfStrings { name: Some(name), default: None, description }), + PluginManifestPreference::ListOfNumbers { id, name, description } => (id, DbPluginPreference::ListOfNumbers { name: Some(name), default: None, description }), + PluginManifestPreference::ListOfEnums { id, name, description, enum_values } => { let enum_values = enum_values.into_iter() .map(|PluginManifestPreferenceEnumValue { label, value } | DbPreferenceEnumValue { label, value }) .collect(); - (name, DbPluginPreference::ListOfEnums { default: None, description, enum_values }) + (id, DbPluginPreference::ListOfEnums { name: Some(name), default: None, description, enum_values }) }, }) .collect(), @@ -311,24 +311,24 @@ impl PluginLoader { let plugin_preferences = plugin_manifest.preferences .into_iter() .map(|preference| match preference { - PluginManifestPreference::Number { name, default, description } => (name, DbPluginPreference::Number { default, description }), - PluginManifestPreference::String { name, default, description } => (name, DbPluginPreference::String { default, description }), - PluginManifestPreference::Enum { name, default, description, enum_values } => { + PluginManifestPreference::Number { id, name, default, description } => (id, DbPluginPreference::Number { name: Some(name), default, description }), + PluginManifestPreference::String { id, name, default, description } => (id, DbPluginPreference::String { name: Some(name), default, description }), + PluginManifestPreference::Enum { id, name, default, description, enum_values } => { let enum_values = enum_values.into_iter() .map(|PluginManifestPreferenceEnumValue { label, value } | DbPreferenceEnumValue { label, value }) .collect(); - (name, DbPluginPreference::Enum { default, description, enum_values }) + (id, DbPluginPreference::Enum { name: Some(name), default, description, enum_values }) }, - PluginManifestPreference::Bool { name, default, description } => (name, DbPluginPreference::Bool { default, description }), - PluginManifestPreference::ListOfStrings { name, description } => (name, DbPluginPreference::ListOfStrings { default: None, description }), - PluginManifestPreference::ListOfNumbers { name, description } => (name, DbPluginPreference::ListOfNumbers { default: None, description }), - PluginManifestPreference::ListOfEnums { name, description, enum_values } => { + PluginManifestPreference::Bool { id, name, default, description } => (id, DbPluginPreference::Bool { name: Some(name), default, description }), + PluginManifestPreference::ListOfStrings { id, name, description } => (id, DbPluginPreference::ListOfStrings { name: Some(name), default: None, description }), + PluginManifestPreference::ListOfNumbers { id, name, description } => (id, DbPluginPreference::ListOfNumbers { name: Some(name), default: None, description }), + PluginManifestPreference::ListOfEnums { id, name, description, enum_values } => { let enum_values = enum_values.into_iter() .map(|PluginManifestPreferenceEnumValue { label, value } | DbPreferenceEnumValue { label, value }) .collect(); - (name, DbPluginPreference::ListOfEnums { default: None, description, enum_values }) + (id, DbPluginPreference::ListOfEnums { name: Some(name), default: None, description, enum_values }) }, }) .collect(); @@ -429,18 +429,21 @@ struct PluginManifestEntrypoint { enum PluginManifestPreference { #[serde(rename = "number")] Number { + id: String, name: String, default: Option, description: String, }, #[serde(rename = "string")] String { + id: String, name: String, default: Option, description: String, }, #[serde(rename = "enum")] Enum { + id: String, name: String, default: Option, description: String, @@ -448,24 +451,28 @@ enum PluginManifestPreference { }, #[serde(rename = "bool")] Bool { + id: String, name: String, default: Option, description: String, }, #[serde(rename = "list_of_strings")] ListOfStrings { + id: String, name: String, // default: Option>, description: String, }, #[serde(rename = "list_of_numbers")] ListOfNumbers { + id: String, name: String, // default: Option>, description: String, }, #[serde(rename = "list_of_enums")] ListOfEnums { + id: String, name: String, // default: Option>, enum_values: Vec, diff --git a/rust/server/src/plugins/mod.rs b/rust/server/src/plugins/mod.rs index 7f4c05e..76df4e7 100644 --- a/rust/server/src/plugins/mod.rs +++ b/rust/server/src/plugins/mod.rs @@ -179,7 +179,10 @@ impl ApplicationManager { DbPluginEntrypointType::CommandGenerator => SettingsEntrypointType::CommandGenerator, }.into(), preferences: entrypoint.preferences.into_iter() - .map(|(key, value)| (key, plugin_preference_from_db(value))) + .map(|(key, value)| { + let preference = plugin_preference_from_db(&key, value); + (key, preference) + }) .collect(), preferences_user_data: entrypoint.preferences_user_data.into_iter() .map(|(key, value)| (key, plugin_preference_user_data_from_db(value))) @@ -197,7 +200,10 @@ impl ApplicationManager { enabled: plugin.enabled, entrypoints, preferences: plugin.preferences.into_iter() - .map(|(key, value)| (key, plugin_preference_from_db(value))) + .map(|(key, value)| { + let preference = plugin_preference_from_db(&key, value); + (key, preference) + }) .collect(), preferences_user_data: plugin.preferences_user_data.into_iter() .map(|(key, value)| (key, plugin_preference_user_data_from_db(value))) @@ -264,10 +270,10 @@ impl ApplicationManager { self.db_repository.get_global_shortcut().await } - pub async fn set_preference_value(&self, plugin_id: PluginId, entrypoint_id: Option, preference_name: String, preference_value: PluginPreferenceUserData) -> anyhow::Result<()> { + pub async fn set_preference_value(&self, plugin_id: PluginId, entrypoint_id: Option, preference_id: String, preference_value: PluginPreferenceUserData) -> anyhow::Result<()> { let user_data = plugin_preference_user_data_to_db(preference_value); - self.db_repository.set_preference_value(plugin_id.to_string(), entrypoint_id.map(|id| id.to_string()), preference_name, user_data) + self.db_repository.set_preference_value(plugin_id.to_string(), entrypoint_id.map(|id| id.to_string()), preference_id, user_data) .await?; Ok(()) @@ -635,26 +641,66 @@ impl ApplicationManager { } } -fn plugin_preference_from_db(value: DbPluginPreference) -> PluginPreference { +fn plugin_preference_from_db(id: &str, value: DbPluginPreference) -> PluginPreference { match value { - DbPluginPreference::Number { default, description } => PluginPreference::Number { default, description }, - DbPluginPreference::String { default, description } => PluginPreference::String { default, description }, - DbPluginPreference::Enum { default, description, enum_values } => { + DbPluginPreference::Number { name, default, description } => { + PluginPreference::Number { + name: name.unwrap_or_else(|| id.to_string()), + default, + description + } + }, + DbPluginPreference::String { name, default, description } => { + PluginPreference::String { + name: name.unwrap_or_else(|| id.to_string()), + default, + description + } + }, + DbPluginPreference::Enum { name, default, description, enum_values } => { let enum_values = enum_values.into_iter() .map(|value| PreferenceEnumValue { label: value.label, value: value.value }) .collect(); - PluginPreference::Enum { default, description, enum_values } + PluginPreference::Enum { + name: name.unwrap_or_else(|| id.to_string()), + default, + description, + enum_values + } + }, + DbPluginPreference::Bool { name, default, description } => { + PluginPreference::Bool { + name: name.unwrap_or_else(|| id.to_string()), + default, + description + } + }, + DbPluginPreference::ListOfStrings { name, default, description } => { + PluginPreference::ListOfStrings { + name: name.unwrap_or_else(|| id.to_string()), + default, + description + } }, - DbPluginPreference::Bool { default, description } => PluginPreference::Bool { default, description }, - DbPluginPreference::ListOfStrings { default, description } => PluginPreference::ListOfStrings { default, description }, - DbPluginPreference::ListOfNumbers { default, description } => PluginPreference::ListOfNumbers { default, description }, - DbPluginPreference::ListOfEnums { default, enum_values, description } => { + DbPluginPreference::ListOfNumbers { name, default, description } => { + PluginPreference::ListOfNumbers { + name: name.unwrap_or_else(|| id.to_string()), + default, + description + } + }, + DbPluginPreference::ListOfEnums { name, default, enum_values, description } => { let enum_values = enum_values.into_iter() .map(|value| PreferenceEnumValue { label: value.label, value: value.value }) .collect(); - PluginPreference::ListOfEnums { default, enum_values, description } + PluginPreference::ListOfEnums { + name: name.unwrap_or_else(|| id.to_string()), + default, + enum_values, + description + } }, } } diff --git a/rust/server/src/rpc.rs b/rust/server/src/rpc.rs index 060b51c..df3bc5b 100644 --- a/rust/server/src/rpc.rs +++ b/rust/server/src/rpc.rs @@ -85,8 +85,8 @@ impl BackendServer for BackendServerImpl { Ok(result) } - async fn set_preference_value(&self, plugin_id: PluginId, entrypoint_id: Option, preference_name: String, preference_value: PluginPreferenceUserData) -> anyhow::Result<()> { - let result = self.application_manager.set_preference_value(plugin_id, entrypoint_id, preference_name, preference_value) + async fn set_preference_value(&self, plugin_id: PluginId, entrypoint_id: Option, preference_id: String, preference_value: PluginPreferenceUserData) -> anyhow::Result<()> { + let result = self.application_manager.set_preference_value(plugin_id, entrypoint_id, preference_id, preference_value) .await; if let Err(err) = &result { diff --git a/schema/backend.proto b/schema/backend.proto index 7418b77..f9f1074 100644 --- a/schema/backend.proto +++ b/schema/backend.proto @@ -93,7 +93,7 @@ message RpcGetGlobalShortcutResponse { message RpcSetPreferenceValueRequest { string plugin_id = 1; string entrypoint_id = 2; - string preference_name = 3; + string preference_id = 3; RpcPluginPreferenceUserData preference_value = 4; } message RpcSetPreferenceValueResponse { @@ -215,6 +215,7 @@ message RpcPluginPreference { bool default_list_exists = 4; string description = 5; repeated RpcEnumValue enum_values = 6; + string name = 7; } message RpcEnumValue { diff --git a/tools b/tools index 0506c37..e441fa0 160000 --- a/tools +++ b/tools @@ -1 +1 @@ -Subproject commit 0506c376f15a220e571e5ef573e94781ad789077 +Subproject commit e441fa089a42f2bb4192a2fe7de0d8e3b7bb2f32