feat: add icon field (#4824)

* feat: add icon field

* fix: add sqlx migration files

* chore: fix tst

* chore: fix duplicate event name

* chore: update to lastest stable rust toolchain

* chore: use 1.75 channel

* chore: fix duplicate event name

* chore: fix duplicate event name

* chore: use more reliable assertion

---------

Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
Zack
2024-03-13 15:07:52 +08:00
committed by GitHub
parent af16299c83
commit bf70be1841
19 changed files with 42 additions and 25 deletions

View File

@ -11,7 +11,7 @@ use crate::module::AFPluginStateMap;
use crate::runtime::AFPluginRuntime;
use crate::{
errors::{DispatchError, Error, InternalError},
module::{as_plugin_map, AFPlugin, AFPluginMap, AFPluginRequest},
module::{plugin_map_or_crash, AFPlugin, AFPluginMap, AFPluginRequest},
response::AFPluginEventResponse,
service::{AFPluginServiceFactory, Service},
};
@ -87,7 +87,7 @@ impl AFPluginDispatcher {
pub fn new(runtime: Arc<AFPluginRuntime>, plugins: Vec<AFPlugin>) -> AFPluginDispatcher {
tracing::trace!("{}", plugin_info(&plugins));
AFPluginDispatcher {
plugins: as_plugin_map(plugins),
plugins: plugin_map_or_crash(plugins),
runtime,
}
}

View File

@ -27,12 +27,16 @@ use crate::{
};
pub type AFPluginMap = Arc<HashMap<AFPluginEvent, Arc<AFPlugin>>>;
pub(crate) fn as_plugin_map(plugins: Vec<AFPlugin>) -> AFPluginMap {
let mut plugin_map = HashMap::new();
pub(crate) fn plugin_map_or_crash(plugins: Vec<AFPlugin>) -> AFPluginMap {
let mut plugin_map: HashMap<AFPluginEvent, Arc<AFPlugin>> = HashMap::new();
plugins.into_iter().for_each(|m| {
let events = m.events();
let plugins = Arc::new(m);
events.into_iter().for_each(|e| {
if plugin_map.contains_key(&e) {
let plugin_name = plugin_map.get(&e).and_then(|p| Some(&p.name));
panic!("Error: {:?} is already defined in {:?}", &e, plugin_name,);
}
plugin_map.insert(e, plugins.clone());
});
});
@ -40,7 +44,7 @@ pub(crate) fn as_plugin_map(plugins: Vec<AFPlugin>) -> AFPluginMap {
}
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
pub struct AFPluginEvent(pub String);
pub struct AFPluginEvent(String);
impl<T: Display + Eq + Hash + Debug + Clone> std::convert::From<T> for AFPluginEvent {
fn from(t: T) -> Self {