refactor: use builder style (#50)

* refactor(upload): use plugin builder style

* refactor(sql): use builder style

* refactor(fs-watch): use builder style

* refactor(fs-extra): use builder style

* refactor(auth): use builder style

* fmt

* fmt

Co-authored-by: FabianLars <fabianlars@fabianlars.de>
This commit is contained in:
Jonas Kruckenberg
2023-01-07 15:53:56 +01:00
committed by GitHub
parent 66dc508f34
commit 2d670f70d9
6 changed files with 99 additions and 172 deletions
+9 -22
View File
@@ -3,7 +3,11 @@
// SPDX-License-Identifier: MIT
use serde::{ser::Serializer, Serialize};
use tauri::{command, plugin::Plugin, Invoke, Runtime};
use tauri::{
command,
plugin::{Builder as PluginBuilder, TauriPlugin},
Runtime,
};
use std::{
path::PathBuf,
@@ -121,25 +125,8 @@ async fn exists(path: PathBuf) -> bool {
path.exists()
}
/// Tauri plugin.
pub struct FsExtra<R: Runtime> {
invoke_handler: Box<dyn Fn(Invoke<R>) + Send + Sync>,
}
impl<R: Runtime> Default for FsExtra<R> {
fn default() -> Self {
Self {
invoke_handler: Box::new(tauri::generate_handler![exists, metadata]),
}
}
}
impl<R: Runtime> Plugin<R> for FsExtra<R> {
fn name(&self) -> &'static str {
"fs-extra"
}
fn extend_api(&mut self, message: Invoke<R>) {
(self.invoke_handler)(message)
}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
PluginBuilder::new("fs-extra")
.invoke_handler(tauri::generate_handler![exists, metadata])
.build()
}