Implement propertyInspectorDidAppear and propertyInspectorDidDisappear events

This commit is contained in:
ninjadev64 committed 2024-01-04 18:45:06 +00:00
1 parent ea697de483
commit 0da4b3f673
5 files changed
+56 -10

No files matched your search

+10
View File
@@ -200,6 +200,16 @@ pub async fn make_info(app: tauri::AppHandle, plugin: String) -> String {
serde_json::to_string(&crate::plugins::info_param::make_info(plugin, manifest.version).await).unwrap()
}
#[tauri::command]
pub async fn switch_property_inspector(old: Option<ActionContext>, new: Option<ActionContext>) {
if let Some(context) = old {
let _ = crate::events::outbound::property_inspector::property_inspector_did_appear(context, "propertyInspectorDidDisappear").await;
}
if let Some(context) = new {
let _ = crate::events::outbound::property_inspector::property_inspector_did_appear(context, "propertyInspectorDidAppear").await;
}
}
pub async fn update_state(app: &tauri::AppHandle, instance: &ActionInstance) -> Result<(), anyhow::Error> {
let window = app.get_window("main").unwrap();
window.emit("update_state", serde_json::to_string(instance).unwrap())?;
@@ -3,20 +3,28 @@ use crate::shared::ActionContext;
use serde::Serialize;
#[derive(Serialize)]
pub struct SendTo {
struct SendToEvent {
event: String,
action: String,
context: ActionContext,
payload: serde_json::Value
}
#[derive(Serialize)]
struct PropertyInspectorDidAppearEvent {
event: &'static str,
action: String,
context: ActionContext,
device: String
}
pub async fn send_to_property_inspector(context: ActionContext, message: serde_json::Value) -> Result<(), anyhow::Error> {
if let Some(instance) = crate::store::profiles::get_instance(
&context.device,
context.position,
&context.controller
).await? {
super::send_to_property_inspector(&context, &SendTo {
super::send_to_property_inspector(&context, &SendToEvent {
event: "sendToPropertyInspector".to_owned(),
action: instance.action.uuid.clone(),
context: context.clone(),
@@ -33,7 +41,7 @@ pub async fn send_to_plugin(context: ActionContext, message: serde_json::Value)
context.position,
&context.controller
).await? {
super::send_to_plugin(&instance.action.plugin, &SendTo {
super::send_to_plugin(&instance.action.plugin, &SendToEvent {
event: "sendToPlugin".to_owned(),
action: instance.action.uuid.clone(),
context,
@@ -43,3 +51,23 @@ pub async fn send_to_plugin(context: ActionContext, message: serde_json::Value)
Ok(())
}
pub async fn property_inspector_did_appear(context: ActionContext, event: &'static str) -> Result<(), anyhow::Error> {
if let Some(instance) = crate::store::profiles::get_instance(
&context.device,
context.position,
&context.controller
).await? {
if instance.action.property_inspector.is_empty() {
return Ok(())
}
super::send_to_plugin(&instance.action.plugin, &PropertyInspectorDidAppearEvent {
event: event,
action: instance.action.uuid.clone(),
device: context.device.clone(),
context
}).await?;
}
Ok(())
}
+6 -6
View File
@@ -5,13 +5,13 @@ use crate::shared::ActionContext;
use serde::Serialize;
#[derive(Serialize)]
pub struct DidReceiveSettingsPayload {
struct DidReceiveSettingsPayload {
settings: serde_json::Value,
coordinates: Coordinates
}
#[derive(Serialize)]
pub struct DidReceiveSettings {
struct DidReceiveSettingsEvent {
event: String,
action: String,
context: ActionContext,
@@ -20,18 +20,18 @@ pub struct DidReceiveSettings {
}
#[derive(Serialize)]
pub struct DidReceiveGlobalSettingsPayload {
struct DidReceiveGlobalSettingsPayload {
settings: serde_json::Value
}
#[derive(Serialize)]
pub struct DidReceiveGlobalSettings {
struct DidReceiveGlobalSettingsEvent {
event: String,
payload: DidReceiveGlobalSettingsPayload
}
pub async fn did_receive_settings(instance: &crate::shared::ActionInstance, to_property_inspector: bool) -> Result<(), anyhow::Error> {
let data = DidReceiveSettings {
let data = DidReceiveSettingsEvent {
event: "didReceiveSettings".to_owned(),
action: instance.action.uuid.clone(),
context: instance.context.clone(),
@@ -59,7 +59,7 @@ pub async fn did_receive_global_settings(context: &str) -> Result<(), anyhow::Er
let path = settings_dir.join(format!("{}.json", context));
let settings: serde_json::Value = serde_json::from_slice(&std::fs::read(path)?)?;
let data = DidReceiveGlobalSettings {
let data = DidReceiveGlobalSettingsEvent {
event: "didReceiveGlobalSettings".to_owned(),
payload: DidReceiveGlobalSettingsPayload {
settings
+2 -1
View File
@@ -29,7 +29,8 @@ async fn main() {
frontend::get_selected_profile,
frontend::set_selected_profile,
frontend::delete_profile,
frontend::make_info
frontend::make_info,
frontend::switch_property_inspector
])
.plugin(tauri_plugin_log::Builder::default()
.targets([
+7
View File
@@ -1,3 +1,10 @@
import { writable, type Writable } from "svelte/store";
export const inspectedInstance: Writable<string | null> = writable(null);
import { invoke } from "@tauri-apps/api";
let old: string | null = null;
inspectedInstance.subscribe(async (value) => {
await invoke("switch_property_inspector", { old, new: value });
old = value;
});