Skip to content

Commit

Permalink
Remove PluginName
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Aug 1, 2024
1 parent 3087ba3 commit b5cc064
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tauri::{ipc::Invoke, App, Runtime};

use crate::{
internal::{Commands, Events},
EventRegistry, PluginName,
EventRegistry,
};

pub struct Builder<R: Runtime> {
Expand Down
9 changes: 5 additions & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginName>,
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())
}
}
Expand Down Expand Up @@ -45,7 +46,7 @@ impl EventRegistry {
pub fn register_collection(
&self,
collection: EventCollection,
plugin_name: Option<PluginName>,
plugin_name: Option<&'static str>,
) {
let mut registry = self.0.write().expect("Failed to write EventRegistry");

Expand Down
46 changes: 1 addition & 45 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,33 +174,12 @@ pub trait LanguageExt: Language {
) -> Result<String, Self::Error>;
}

// 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:{}{}{}",
Expand All @@ -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<TConfig> {
// /// 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<PluginName>,
// /// The specta export configuration
// pub(crate) inner: TConfig,
// pub(crate) path: Option<PathBuf>,
// pub(crate) header: Cow<'static, str>,
// }

// impl<TConfig: Default> ExportConfig<TConfig> {
// /// Creates a new [`ExportConfiguration`] from a [`specta::ts::ExportConfiguration`]
// pub fn new(config: TConfig) -> Self {
// Self {
// inner: config,
// ..Default::default()
// }
// }
// }

0 comments on commit b5cc064

Please sign in to comment.