Resolve linter violations and make event ID fields static string slices

This commit is contained in:
ninjadev64 committed 2024-02-08 18:16:52 +00:00
1 parent 0da4b3f673
commit 922feff242
8 files changed
+30 -35

No files matched your search

+5 -8
View File
@@ -59,6 +59,7 @@ pub async fn get_selected_profile(app: tauri::AppHandle, device: String) -> Stri
}
}
#[allow(clippy::flat_map_identity)]
#[tauri::command]
pub async fn set_selected_profile(app: tauri::AppHandle, device: String, id: String) -> String {
let mut device_stores = DEVICE_STORES.lock().await;
@@ -71,10 +72,8 @@ pub async fn set_selected_profile(app: tauri::AppHandle, device: String, id: Str
Ok(store) => &store.value,
Err(error) => return serde_json::to_string(&Error { description: error.to_string() }).unwrap()
};
for instance in (&old_profile.keys).into_iter().chain(&old_profile.sliders) {
if let Some(instance) = instance {
let _ = crate::events::outbound::will_appear::will_disappear(instance).await;
}
for instance in old_profile.keys.iter().chain(&old_profile.sliders).flat_map(|x| x) {
let _ = crate::events::outbound::will_appear::will_disappear(instance).await;
}
}
@@ -82,10 +81,8 @@ pub async fn set_selected_profile(app: tauri::AppHandle, device: String, id: Str
Ok(store) => &store.value,
Err(error) => return serde_json::to_string(&Error { description: error.to_string() }).unwrap()
};
for instance in (&new_profile.keys).into_iter().chain(&new_profile.sliders) {
if let Some(instance) = instance {
let _ = crate::events::outbound::will_appear::will_appear(instance).await;
}
for instance in new_profile.keys.iter().chain(&new_profile.sliders).flat_map(|x| x) {
let _ = crate::events::outbound::will_appear::will_appear(instance).await;
}
store.value.selected_profile = id.to_owned();
+2 -2
View File
@@ -46,7 +46,7 @@ pub async fn set_title(event: ContextAndPayloadEvent<SetTitlePayload>) -> Result
);
} else {
for (index, state) in instance.states.iter_mut().enumerate() {
(*state).text = event.payload.title.clone().unwrap_or(instance.action.states[index].text.clone());
state.text = event.payload.title.clone().unwrap_or(instance.action.states[index].text.clone());
}
}
update_state(app.as_ref().unwrap(), instance).await?;
@@ -80,7 +80,7 @@ pub async fn set_image(event: ContextAndPayloadEvent<SetImagePayload>) -> Result
);
} else {
for (index, state) in instance.states.iter_mut().enumerate() {
(*state).image = event.payload.image.clone().unwrap_or(instance.action.states[index].image.clone());
state.image = event.payload.image.clone().unwrap_or(instance.action.states[index].image.clone());
}
}
update_state(app.as_ref().unwrap(), instance).await?;
+2 -2
View File
@@ -15,8 +15,8 @@ struct DialRotatePayload {
#[derive(Serialize)]
struct DialRotateEvent {
event: &'static str,
action: String,
event: String,
context: ActionContext,
device: String,
payload: DialRotatePayload
@@ -29,8 +29,8 @@ pub async fn dial_rotate(device: &str, index: u8, ticks: i16) -> Result<(), anyh
};
send_to_plugin(&instance.action.plugin, &DialRotateEvent {
event: "dialRotate",
action: instance.action.uuid.clone(),
event: "dialRotate".to_owned(),
context: instance.context.clone(),
device: instance.context.device.clone(),
payload: DialRotatePayload {
+5 -5
View File
@@ -7,8 +7,8 @@ use serde::Serialize;
#[derive(Serialize)]
struct KeyEvent {
event: &'static str,
action: String,
event: String,
context: ActionContext,
device: String,
payload: GenericInstancePayload
@@ -21,8 +21,8 @@ pub async fn key_down(device: &str, key: u8) -> Result<(), anyhow::Error> {
};
send_to_plugin(&instance.action.plugin, &KeyEvent {
event: "keyDown",
action: instance.action.uuid.clone(),
event: "keyDown".to_owned(),
context: instance.context.clone(),
device: instance.context.device.clone(),
payload: GenericInstancePayload::new(&instance)
@@ -37,7 +37,7 @@ pub async fn key_up(device: &str, key: u8) -> Result<(), anyhow::Error> {
mut profile_stores
) = crate::store::profiles::lock_mutexes().await;
let selected_profile = &device_stores.get_device_store(&device, app.as_ref().unwrap())?.value.selected_profile;
let selected_profile = &device_stores.get_device_store(device, app.as_ref().unwrap())?.value.selected_profile;
let device = devices.get(device).unwrap();
let store = profile_stores.get_profile_store(device, selected_profile, app.as_ref().unwrap())?;
let profile = &mut store.value;
@@ -50,10 +50,10 @@ pub async fn key_up(device: &str, key: u8) -> Result<(), anyhow::Error> {
instance.current_state = (instance.current_state + 1) % (instance.states.len() as u16);
send_to_plugin(&instance.action.plugin, &KeyEvent {
event: "keyUp",
action: instance.action.uuid.clone(),
event: "keyUp".to_owned(),
context: instance.context.clone(),
device: instance.context.device.clone(),
payload: GenericInstancePayload::new(&instance)
payload: GenericInstancePayload::new(instance)
}).await
}
@@ -4,7 +4,7 @@ use serde::Serialize;
#[derive(Serialize)]
struct SendToEvent {
event: String,
event: &'static str,
action: String,
context: ActionContext,
payload: serde_json::Value
@@ -25,7 +25,7 @@ pub async fn send_to_property_inspector(context: ActionContext, message: serde_j
&context.controller
).await? {
super::send_to_property_inspector(&context, &SendToEvent {
event: "sendToPropertyInspector".to_owned(),
event: "sendToPropertyInspector",
action: instance.action.uuid.clone(),
context: context.clone(),
payload: message
@@ -42,7 +42,7 @@ pub async fn send_to_plugin(context: ActionContext, message: serde_json::Value)
&context.controller
).await? {
super::send_to_plugin(&instance.action.plugin, &SendToEvent {
event: "sendToPlugin".to_owned(),
event: "sendToPlugin",
action: instance.action.uuid.clone(),
context,
payload: message
@@ -62,7 +62,7 @@ pub async fn property_inspector_did_appear(context: ActionContext, event: &'stat
return Ok(())
}
super::send_to_plugin(&instance.action.plugin, &PropertyInspectorDidAppearEvent {
event: event,
event,
action: instance.action.uuid.clone(),
device: context.device.clone(),
context
+4 -4
View File
@@ -12,7 +12,7 @@ struct DidReceiveSettingsPayload {
#[derive(Serialize)]
struct DidReceiveSettingsEvent {
event: String,
event: &'static str,
action: String,
context: ActionContext,
device: String,
@@ -26,13 +26,13 @@ struct DidReceiveGlobalSettingsPayload {
#[derive(Serialize)]
struct DidReceiveGlobalSettingsEvent {
event: String,
event: &'static str,
payload: DidReceiveGlobalSettingsPayload
}
pub async fn did_receive_settings(instance: &crate::shared::ActionInstance, to_property_inspector: bool) -> Result<(), anyhow::Error> {
let data = DidReceiveSettingsEvent {
event: "didReceiveSettings".to_owned(),
event: "didReceiveSettings",
action: instance.action.uuid.clone(),
context: instance.context.clone(),
device: instance.context.device.clone(),
@@ -60,7 +60,7 @@ pub async fn did_receive_global_settings(context: &str) -> Result<(), anyhow::Er
let settings: serde_json::Value = serde_json::from_slice(&std::fs::read(path)?)?;
let data = DidReceiveGlobalSettingsEvent {
event: "didReceiveGlobalSettings".to_owned(),
event: "didReceiveGlobalSettings",
payload: DidReceiveGlobalSettingsPayload {
settings
}
+5 -5
View File
@@ -4,8 +4,8 @@ use crate::shared::{ActionContext, ActionInstance};
#[derive(serde::Serialize)]
struct AppearEvent {
event: &'static str,
action: String,
event: String,
context: ActionContext,
device: String,
payload: GenericInstancePayload
@@ -13,11 +13,11 @@ struct AppearEvent {
pub async fn will_appear(instance: &ActionInstance) -> Result<(), anyhow::Error> {
send_to_plugin(&instance.action.plugin, &AppearEvent {
event: "willAppear",
action: instance.action.uuid.clone(),
event: "willAppear".to_owned(),
context: instance.context.clone(),
device: instance.context.device.clone(),
payload: GenericInstancePayload::new(&instance)
payload: GenericInstancePayload::new(instance)
}).await?;
Ok(())
@@ -25,11 +25,11 @@ pub async fn will_appear(instance: &ActionInstance) -> Result<(), anyhow::Error>
pub async fn will_disappear(instance: &ActionInstance) -> Result<(), anyhow::Error> {
send_to_plugin(&instance.action.plugin, &AppearEvent {
event: "willDisappear",
action: instance.action.uuid.clone(),
event: "willDisappear".to_owned(),
context: instance.context.clone(),
device: instance.context.device.clone(),
payload: GenericInstancePayload::new(&instance)
payload: GenericInstancePayload::new(instance)
}).await?;
Ok(())
+3 -5
View File
@@ -50,11 +50,9 @@ impl ProfileStores {
pub fn all_from_plugin(&self, plugin: &str) -> Vec<crate::shared::ActionContext> {
let mut all = vec![];
for store in self.stores.values() {
for instance in (&store.value.keys).into_iter().chain(&store.value.sliders) {
if let Some(instance) = instance {
if instance.action.plugin == plugin {
all.push(instance.context.clone());
}
for instance in store.value.keys.iter().chain(&store.value.sliders).flatten() {
if instance.action.plugin == plugin {
all.push(instance.context.clone());
}
}
}