mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-01 11:13:40 +03:00
refactor(core): plugin initialization return value (#1575)
This commit is contained in:
parent
f708ff824e
commit
508eddc784
5
.changes/plugin-initialization-result.md
Normal file
5
.changes/plugin-initialization-result.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Change plugin trait `initialization` return type to `std::result::Result<(), Box<dyn std::error::Error>>`.
|
@ -57,6 +57,9 @@ pub enum Error {
|
||||
#[cfg(feature = "updater")]
|
||||
#[error("Updater: {0}")]
|
||||
TauriUpdater(#[from] crate::updater::Error),
|
||||
/// Error initializing plugin.
|
||||
#[error("failed to initialize plugin `{0}`: {1}")]
|
||||
PluginInitialization(String, String),
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for Error {
|
||||
|
@ -12,6 +12,9 @@ use crate::{
|
||||
use serde_json::Value as JsonValue;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// The plugin result type.
|
||||
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
/// The plugin interface.
|
||||
pub trait Plugin<M: Params>: Send {
|
||||
/// The plugin name. Used as key on the plugin config object.
|
||||
@ -19,7 +22,7 @@ pub trait Plugin<M: Params>: Send {
|
||||
|
||||
/// Initialize the plugin.
|
||||
#[allow(unused_variables)]
|
||||
fn initialize(&mut self, config: JsonValue) -> crate::Result<()> {
|
||||
fn initialize(&mut self, config: JsonValue) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -69,7 +72,9 @@ impl<M: Params> PluginStore<M> {
|
||||
/// Initializes all plugins in the store.
|
||||
pub(crate) fn initialize(&mut self, config: &PluginConfig) -> crate::Result<()> {
|
||||
self.store.values_mut().try_for_each(|plugin| {
|
||||
plugin.initialize(config.0.get(plugin.name()).cloned().unwrap_or_default())
|
||||
plugin
|
||||
.initialize(config.0.get(plugin.name()).cloned().unwrap_or_default())
|
||||
.map_err(|e| crate::Error::PluginInitialization(plugin.name().to_string(), e.to_string()))
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user