Reformat project

This commit is contained in:
Gregory Schier
2025-12-13 08:10:12 -08:00
parent c20c0eff32
commit cfbfd66eef
68 changed files with 290 additions and 759 deletions

View File

@@ -58,10 +58,7 @@ pub async fn check_plugin_updates<R: Runtime>(
.list_plugins()?
.into_iter()
.filter_map(|p| match get_plugin_meta(&Path::new(&p.directory)) {
Ok(m) => Some(PluginNameVersion {
name: m.name,
version: m.version,
}),
Ok(m) => Some(PluginNameVersion { name: m.name, version: m.version }),
Err(e) => {
warn!("Failed to get plugin metadata: {}", e);
None
@@ -70,9 +67,7 @@ pub async fn check_plugin_updates<R: Runtime>(
.collect();
let url = build_url("/updates");
let body = serde_json::to_vec(&PluginUpdatesResponse {
plugins: name_versions,
})?;
let body = serde_json::to_vec(&PluginUpdatesResponse { plugins: name_versions })?;
let resp = yaak_api_client(app_handle)?.post(url.clone()).body(body).send().await?;
if !resp.status().is_success() {
return Err(ApiErr(format!("{} response to {}", resp.status(), url.to_string())));

View File

@@ -1,9 +1,9 @@
use crate::api::{
check_plugin_updates, search_plugins, PluginSearchResponse, PluginUpdatesResponse,
PluginSearchResponse, PluginUpdatesResponse, check_plugin_updates, search_plugins,
};
use crate::error::Result;
use crate::install::{delete_and_uninstall, download_and_install};
use tauri::{command, AppHandle, Runtime, WebviewWindow};
use tauri::{AppHandle, Runtime, WebviewWindow, command};
use yaak_models::models::Plugin;
#[command]

View File

@@ -45,11 +45,7 @@ pub struct PluginContext {
impl PluginContext {
pub fn new_empty() -> Self {
Self {
id: "default".to_string(),
label: None,
workspace_id: None,
}
Self { id: "default".to_string(), label: None, workspace_id: None }
}
pub fn new<R: Runtime>(window: &WebviewWindow<R>) -> Self {
Self {
@@ -1049,9 +1045,7 @@ pub enum Content {
impl Default for Content {
fn default() -> Self {
Self::Text {
content: String::default(),
}
Self::Text { content: String::default() }
}
}

View File

@@ -1,24 +1,24 @@
use std::sync::atomic::{AtomicBool, Ordering};
use crate::commands::{install, search, uninstall, updates};
use crate::manager::PluginManager;
use log::info;
use std::sync::atomic::{AtomicBool, Ordering};
use tauri::plugin::{Builder, TauriPlugin};
use tauri::{generate_handler, Manager, RunEvent, Runtime, State};
use tauri::{Manager, RunEvent, Runtime, State, generate_handler};
pub mod api;
mod checksum;
mod commands;
pub mod error;
pub mod events;
pub mod install;
pub mod manager;
pub mod native_template_functions;
mod nodejs;
pub mod plugin_handle;
pub mod plugin_meta;
mod server_ws;
pub mod template_callback;
mod util;
mod checksum;
pub mod api;
pub mod install;
pub mod plugin_meta;
static EXITING: AtomicBool = AtomicBool::new(false);

View File

@@ -185,12 +185,8 @@ impl PluginManager {
.collect();
let plugins = app_handle.db().list_plugins().unwrap_or_default();
let installed_plugin_dirs: Vec<PluginCandidate> = plugins
.iter()
.map(|p| PluginCandidate {
dir: p.directory.to_owned(),
})
.collect();
let installed_plugin_dirs: Vec<PluginCandidate> =
plugins.iter().map(|p| PluginCandidate { dir: p.directory.to_owned() }).collect();
[bundled_plugin_dirs, installed_plugin_dirs].concat()
}
@@ -524,9 +520,7 @@ impl PluginManager {
RenderPurpose::Preview,
);
// We don't want to fail for this op because the UI will not be able to list any auth types then
let render_opt = RenderOptions {
error_behavior: RenderErrorBehavior::ReturnEmpty,
};
let render_opt = RenderOptions { error_behavior: RenderErrorBehavior::ReturnEmpty };
let rendered_values = render_json_value_raw(json!(values), vars, &cb, &render_opt).await?;
let context_id = format!("{:x}", md5::compute(model_id.to_string()));
@@ -643,9 +637,7 @@ impl PluginManager {
RenderPurpose::Preview,
);
// We don't want to fail for this op because the UI will not be able to list any auth types then
let render_opt = RenderOptions {
error_behavior: RenderErrorBehavior::ReturnEmpty,
};
let render_opt = RenderOptions { error_behavior: RenderErrorBehavior::ReturnEmpty };
let rendered_values = render_json_value_raw(json!(values), vars, &cb, &render_opt).await?;
let context_id = format!("{:x}", md5::compute(model_id.to_string()));
let event = self
@@ -688,9 +680,7 @@ impl PluginManager {
&PluginContext::new(&window),
RenderPurpose::Preview,
),
&RenderOptions {
error_behavior: RenderErrorBehavior::Throw,
},
&RenderOptions { error_behavior: RenderErrorBehavior::Throw },
)
.await?;
let results = self.get_http_authentication_summaries(window).await?;
@@ -807,21 +797,20 @@ impl PluginManager {
.await
.map_err(|e| RenderError(format!("Failed to call template function {e:}")))?;
let value = events.into_iter().find_map(|e| match e.payload {
// Error returned
InternalEventPayload::CallTemplateFunctionResponse(CallTemplateFunctionResponse {
error: Some(error),
..
}) => Some(Err(error)),
// Value or null returned
InternalEventPayload::CallTemplateFunctionResponse(CallTemplateFunctionResponse {
value,
..
}) => Some(Ok(value.unwrap_or_default())),
// Generic error returned
InternalEventPayload::ErrorResponse(ErrorResponse { error }) => Some(Err(error)),
_ => None,
});
let value =
events.into_iter().find_map(|e| match e.payload {
// Error returned
InternalEventPayload::CallTemplateFunctionResponse(
CallTemplateFunctionResponse { error: Some(error), .. },
) => Some(Err(error)),
// Value or null returned
InternalEventPayload::CallTemplateFunctionResponse(
CallTemplateFunctionResponse { value, .. },
) => Some(Ok(value.unwrap_or_default())),
// Generic error returned
InternalEventPayload::ErrorResponse(ErrorResponse { error }) => Some(Err(error)),
_ => None,
});
match value {
None => Err(RenderError(format!("Template function {fn_name}(…) not found "))),

View File

@@ -4,17 +4,17 @@ use crate::events::{
TemplateFunctionPreviewType,
};
use crate::template_callback::PluginTemplateCallback;
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use base64::prelude::BASE64_STANDARD;
use keyring::Error::NoEntry;
use log::{debug, info};
use std::collections::HashMap;
use tauri::{AppHandle, Runtime};
use yaak_common::platform::{get_os, OperatingSystem};
use yaak_common::platform::{OperatingSystem, get_os};
use yaak_crypto::manager::EncryptionManagerExt;
use yaak_templates::error::Error::RenderError;
use yaak_templates::error::Result;
use yaak_templates::{transform_args, FnArg, Parser, Token, Tokens, Val};
use yaak_templates::{FnArg, Parser, Token, Tokens, Val, transform_args};
pub(crate) fn template_function_secure() -> TemplateFunction {
TemplateFunction {
@@ -179,9 +179,7 @@ pub fn decrypt_secure_template_function<R: Runtime>(
for token in parsed.tokens.iter() {
match token {
Token::Tag {
val: Val::Fn { name, args },
} if name == "secure" => {
Token::Tag { val: Val::Fn { name, args } } if name == "secure" => {
let mut args_map = HashMap::new();
for a in args {
match a.clone().value {
@@ -228,7 +226,7 @@ pub fn encrypt_secure_template_function<R: Runtime>(
tokens,
&PluginTemplateCallback::new(app_handle, plugin_context, RenderPurpose::Preview),
)?
.to_string())
.to_string())
}
pub fn template_function_keychain_run(args: HashMap<String, serde_json::Value>) -> Result<String> {

View File

@@ -3,8 +3,8 @@ use log::{info, warn};
use std::net::SocketAddr;
use tauri::path::BaseDirectory;
use tauri::{AppHandle, Manager, Runtime};
use tauri_plugin_shell::process::CommandEvent;
use tauri_plugin_shell::ShellExt;
use tauri_plugin_shell::process::CommandEvent;
use tokio::sync::watch::Receiver;
pub async fn start_nodejs_plugin_runtime<R: Runtime>(

View File

@@ -3,10 +3,10 @@ use futures_util::{SinkExt, StreamExt};
use log::{error, info, warn};
use std::sync::Arc;
use tokio::net::{TcpListener, TcpStream};
use tokio::sync::{mpsc, Mutex};
use tokio::sync::{Mutex, mpsc};
use tokio_tungstenite::accept_async_with_config;
use tokio_tungstenite::tungstenite::protocol::WebSocketConfig;
use tokio_tungstenite::tungstenite::Message;
use tokio_tungstenite::tungstenite::protocol::WebSocketConfig;
#[derive(Clone)]
pub(crate) struct PluginRuntimeServerWebsocket {

View File

@@ -1,5 +1,5 @@
use rand::distr::Alphanumeric;
use rand::Rng;
use rand::distr::Alphanumeric;
pub fn gen_id() -> String {
rand::rng().sample_iter(&Alphanumeric).take(5).map(char::from).collect()