Cargo format

This commit is contained in:
Gregory Schier
2025-01-11 13:53:30 -08:00
parent 295aea4f2e
commit ba330047ca
17 changed files with 82 additions and 163 deletions

View File

@@ -1,37 +1,37 @@
use crate::server::plugin_runtime::EventStreamEvent;
use thiserror::Error;
use tokio::io;
use tokio::sync::mpsc::error::SendError;
use crate::server::plugin_runtime::EventStreamEvent;
#[derive(Error, Debug)]
pub enum Error {
#[error("IO error: {0}")]
IoErr(#[from] io::Error),
#[error("Tauri error: {0}")]
TauriErr(#[from] tauri::Error),
#[error("Tauri shell error: {0}")]
TauriShellErr(#[from] tauri_plugin_shell::Error),
#[error("Grpc transport error: {0}")]
GrpcTransportErr(#[from] tonic::transport::Error),
#[error("Grpc send error: {0}")]
GrpcSendErr(#[from] SendError<tonic::Result<EventStreamEvent>>),
#[error("JSON error: {0}")]
JsonErr(#[from] serde_json::Error),
#[error("Plugin not found: {0}")]
PluginNotFoundErr(String),
#[error("Plugin error: {0}")]
PluginErr(String),
#[error("Client not initialized error")]
ClientNotInitializedErr,
#[error("Unknown event received")]
UnknownEventErr,
}

View File

@@ -1,15 +1,15 @@
use std::process::exit;
use crate::manager::PluginManager;
use log::info;
use std::process::exit;
use tauri::plugin::{Builder, TauriPlugin};
use tauri::{Manager, RunEvent, Runtime, State};
use crate::manager::PluginManager;
pub mod error;
pub mod events;
pub mod manager;
mod nodejs;
mod server;
pub mod plugin_handle;
mod server;
mod util;
pub fn init<R: Runtime>() -> TauriPlugin<R> {

View File

@@ -1,8 +1,8 @@
use std::net::SocketAddr;
use crate::error::Result;
use log::info;
use serde;
use serde::Deserialize;
use std::net::SocketAddr;
use tauri::path::BaseDirectory;
use tauri::{AppHandle, Manager, Runtime};
use tauri_plugin_shell::process::CommandEvent;
@@ -20,15 +20,12 @@ pub async fn start_nodejs_plugin_runtime<R: Runtime>(
addr: SocketAddr,
kill_rx: &Receiver<bool>,
) -> Result<()> {
let plugin_runtime_main = app
.path()
.resolve("vendored/plugin-runtime", BaseDirectory::Resource)?
.join("index.cjs");
let plugin_runtime_main =
app.path().resolve("vendored/plugin-runtime", BaseDirectory::Resource)?.join("index.cjs");
// HACK: Remove UNC prefix for Windows paths to pass to sidecar
let plugin_runtime_main = dunce::simplified(plugin_runtime_main.as_path())
.to_string_lossy()
.to_string();
let plugin_runtime_main =
dunce::simplified(plugin_runtime_main.as_path()).to_string_lossy().to_string();
info!("Starting plugin runtime main={}", plugin_runtime_main);
@@ -59,10 +56,7 @@ pub async fn start_nodejs_plugin_runtime<R: Runtime>(
// Check on child
tokio::spawn(async move {
kill_rx
.wait_for(|b| *b == true)
.await
.expect("Kill channel errored");
kill_rx.wait_for(|b| *b == true).await.expect("Kill channel errored");
info!("Killing plugin runtime");
child.kill().expect("Failed to kill plugin runtime");
info!("Killed plugin runtime");

View File

@@ -57,11 +57,8 @@ impl PluginHandle {
pub async fn terminate(&self, window_context: WindowContext) -> Result<()> {
info!("Terminating plugin {}", self.dir);
let event = self.build_event_to_send(
window_context,
&InternalEventPayload::TerminateRequest,
None,
);
let event =
self.build_event_to_send(window_context, &InternalEventPayload::TerminateRequest, None);
self.send(&event).await
}