From b5cc0644d67d6dadba9506c02c204f7517502e82 Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Thu, 1 Aug 2024 11:16:49 +0800 Subject: [PATCH] Remove `PluginName` --- src/builder.rs | 2 +- src/event.rs | 9 +++++---- src/lib.rs | 46 +--------------------------------------------- 3 files changed, 7 insertions(+), 50 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 4e25ade..487c4b9 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -12,7 +12,7 @@ use tauri::{ipc::Invoke, App, Runtime}; use crate::{ internal::{Commands, Events}, - EventRegistry, PluginName, + EventRegistry, }; pub struct Builder { diff --git a/src/event.rs b/src/event.rs index b48bfcb..2c396d8 100644 --- a/src/event.rs +++ b/src/event.rs @@ -7,17 +7,18 @@ use serde::{de::DeserializeOwned, Serialize}; use specta::{DataType, NamedType, SpectaID}; use tauri::{Emitter, EventId, EventTarget, Listener, Manager, Runtime}; -use crate::PluginName; +use crate::apply_as_prefix; #[derive(Clone, Copy)] pub struct EventRegistryMeta { - plugin_name: Option, + plugin_name: Option<&'static str>, } impl EventRegistryMeta { fn wrap_with_plugin(&self, input: &str) -> String { self.plugin_name - .map(|n| n.apply_as_prefix(input, crate::ItemType::Event)) + .as_ref() + .map(|n| apply_as_prefix(n, input, crate::ItemType::Event)) .unwrap_or_else(|| input.to_string()) } } @@ -45,7 +46,7 @@ impl EventRegistry { pub fn register_collection( &self, collection: EventCollection, - plugin_name: Option, + plugin_name: Option<&'static str>, ) { let mut registry = self.0.write().expect("Failed to write EventRegistry"); diff --git a/src/lib.rs b/src/lib.rs index bb25a4f..cb7bca3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,33 +174,12 @@ pub trait LanguageExt: Language { ) -> Result; } -// TODO: Remove -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -pub(crate) struct PluginName(&'static str); - +// TODO: Remove this pub(crate) enum ItemType { Event, Command, } -impl PluginName { - pub fn new(plugin_name: &'static str) -> Self { - Self(plugin_name) - } - - pub fn apply_as_prefix(&self, s: &str, item_type: ItemType) -> String { - format!( - "plugin:{}{}{}", - self.0, - match item_type { - ItemType::Event => ":", - ItemType::Command => "|", - }, - s, - ) - } -} - pub(crate) fn apply_as_prefix(plugin_name: &str, s: &str, item_type: ItemType) -> String { format!( "plugin:{}{}{}", @@ -212,26 +191,3 @@ pub(crate) fn apply_as_prefix(plugin_name: &str, s: &str, item_type: ItemType) - s, ) } - -// // TODO: Remove -// #[derive(Default, Clone)] -// pub struct ExportConfig { -// /// The name of the plugin to invoke. -// /// -// /// If there is no plugin name (i.e. this is an app), this should be `None`. -// pub(crate) plugin_name: Option, -// /// The specta export configuration -// pub(crate) inner: TConfig, -// pub(crate) path: Option, -// pub(crate) header: Cow<'static, str>, -// } - -// impl ExportConfig { -// /// Creates a new [`ExportConfiguration`] from a [`specta::ts::ExportConfiguration`] -// pub fn new(config: TConfig) -> Self { -// Self { -// inner: config, -// ..Default::default() -// } -// } -// }