mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-25 01:58:39 +02:00
Cargo format
This commit is contained in:
@@ -5,7 +5,10 @@ use serde::{Deserialize, Serialize};
|
|||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use tauri::{Manager, Runtime, WebviewWindow};
|
use tauri::{Manager, Runtime, WebviewWindow};
|
||||||
use ts_rs::TS;
|
use ts_rs::TS;
|
||||||
use yaak_models::queries::{generate_id, get_key_value_int, get_key_value_string, get_or_create_settings, set_key_value_int, set_key_value_string, UpdateSource};
|
use yaak_models::queries::{
|
||||||
|
generate_id, get_key_value_int, get_key_value_string, get_or_create_settings,
|
||||||
|
set_key_value_int, set_key_value_string, UpdateSource,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::is_dev;
|
use crate::is_dev;
|
||||||
|
|
||||||
|
|||||||
@@ -74,10 +74,7 @@ impl YaakNotifier {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let notification = resp
|
let notification = resp.json::<YaakNotification>().await.map_err(|e| e.to_string())?;
|
||||||
.json::<YaakNotification>()
|
|
||||||
.await
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
|
|
||||||
let age = notification.timestamp.signed_duration_since(Utc::now());
|
let age = notification.timestamp.signed_duration_since(Utc::now());
|
||||||
let seen = get_kv(window).await?;
|
let seen = get_kv(window).await?;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::MAIN_WINDOW_PREFIX;
|
||||||
use hex_color::HexColor;
|
use hex_color::HexColor;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use objc::{msg_send, sel, sel_impl};
|
use objc::{msg_send, sel, sel_impl};
|
||||||
@@ -6,7 +7,6 @@ use tauri::{
|
|||||||
plugin::{Builder, TauriPlugin},
|
plugin::{Builder, TauriPlugin},
|
||||||
Emitter, Listener, Manager, Runtime, Window, WindowEvent,
|
Emitter, Listener, Manager, Runtime, Window, WindowEvent,
|
||||||
};
|
};
|
||||||
use crate::MAIN_WINDOW_PREFIX;
|
|
||||||
|
|
||||||
const WINDOW_CONTROL_PAD_X: f64 = 13.0;
|
const WINDOW_CONTROL_PAD_X: f64 = 13.0;
|
||||||
const WINDOW_CONTROL_PAD_Y: f64 = 18.0;
|
const WINDOW_CONTROL_PAD_Y: f64 = 18.0;
|
||||||
@@ -202,10 +202,9 @@ pub fn setup_traffic_light_positioner<R: Runtime>(window: &Window<R>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let ns_win = window
|
let ns_win =
|
||||||
.ns_window()
|
window.ns_window().expect("NS Window should exist to mount traffic light delegate.")
|
||||||
.expect("NS Window should exist to mount traffic light delegate.")
|
as id;
|
||||||
as id;
|
|
||||||
|
|
||||||
let current_delegate: id = ns_win.delegate();
|
let current_delegate: id = ns_win.delegate();
|
||||||
|
|
||||||
@@ -322,10 +321,7 @@ pub fn setup_traffic_light_positioner<R: Runtime>(window: &Window<R>) {
|
|||||||
) {
|
) {
|
||||||
unsafe {
|
unsafe {
|
||||||
with_window_state(&*this, |state: &mut WindowState<R>| {
|
with_window_state(&*this, |state: &mut WindowState<R>| {
|
||||||
state
|
state.window.emit("did-enter-fullscreen", ()).expect("Failed to emit event");
|
||||||
.window
|
|
||||||
.emit("did-enter-fullscreen", ())
|
|
||||||
.expect("Failed to emit event");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let super_del: id = *this.get_ivar("super_delegate");
|
let super_del: id = *this.get_ivar("super_delegate");
|
||||||
@@ -339,10 +335,7 @@ pub fn setup_traffic_light_positioner<R: Runtime>(window: &Window<R>) {
|
|||||||
) {
|
) {
|
||||||
unsafe {
|
unsafe {
|
||||||
with_window_state(&*this, |state: &mut WindowState<R>| {
|
with_window_state(&*this, |state: &mut WindowState<R>| {
|
||||||
state
|
state.window.emit("will-enter-fullscreen", ()).expect("Failed to emit event");
|
||||||
.window
|
|
||||||
.emit("will-enter-fullscreen", ())
|
|
||||||
.expect("Failed to emit event");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let super_del: id = *this.get_ivar("super_delegate");
|
let super_del: id = *this.get_ivar("super_delegate");
|
||||||
@@ -356,10 +349,7 @@ pub fn setup_traffic_light_positioner<R: Runtime>(window: &Window<R>) {
|
|||||||
) {
|
) {
|
||||||
unsafe {
|
unsafe {
|
||||||
with_window_state(&*this, |state: &mut WindowState<R>| {
|
with_window_state(&*this, |state: &mut WindowState<R>| {
|
||||||
state
|
state.window.emit("did-exit-fullscreen", ()).expect("Failed to emit event");
|
||||||
.window
|
|
||||||
.emit("did-exit-fullscreen", ())
|
|
||||||
.expect("Failed to emit event");
|
|
||||||
|
|
||||||
let id = state.window.ns_window().expect("Failed to emit event") as id;
|
let id = state.window.ns_window().expect("Failed to emit event") as id;
|
||||||
position_traffic_lights(
|
position_traffic_lights(
|
||||||
@@ -381,10 +371,7 @@ pub fn setup_traffic_light_positioner<R: Runtime>(window: &Window<R>) {
|
|||||||
) {
|
) {
|
||||||
unsafe {
|
unsafe {
|
||||||
with_window_state(&*this, |state: &mut WindowState<R>| {
|
with_window_state(&*this, |state: &mut WindowState<R>| {
|
||||||
state
|
state.window.emit("will-exit-fullscreen", ()).expect("Failed to emit event");
|
||||||
.window
|
|
||||||
.emit("will-exit-fullscreen", ())
|
|
||||||
.expect("Failed to emit event");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let super_del: id = *this.get_ivar("super_delegate");
|
let super_del: id = *this.get_ivar("super_delegate");
|
||||||
@@ -432,11 +419,8 @@ pub fn setup_traffic_light_positioner<R: Runtime>(window: &Window<R>) {
|
|||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
};
|
};
|
||||||
let app_box = Box::into_raw(Box::new(app_state)) as *mut c_void;
|
let app_box = Box::into_raw(Box::new(app_state)) as *mut c_void;
|
||||||
let random_str: String = rand::thread_rng()
|
let random_str: String =
|
||||||
.sample_iter(&Alphanumeric)
|
rand::thread_rng().sample_iter(&Alphanumeric).take(20).map(char::from).collect();
|
||||||
.take(20)
|
|
||||||
.map(char::from)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// We need to ensure we have a unique delegate name, otherwise we will panic while trying to create a duplicate
|
// We need to ensure we have a unique delegate name, otherwise we will panic while trying to create a duplicate
|
||||||
// delegate with the same name.
|
// delegate with the same name.
|
||||||
|
|||||||
@@ -31,11 +31,7 @@ impl TemplateCallback for PluginTemplateCallback {
|
|||||||
let window_context = self.window_context.to_owned();
|
let window_context = self.window_context.to_owned();
|
||||||
// The beta named the function `Response` but was changed in stable.
|
// The beta named the function `Response` but was changed in stable.
|
||||||
// Keep this here for a while because there's no easy way to migrate
|
// Keep this here for a while because there's no easy way to migrate
|
||||||
let fn_name = if fn_name == "Response" {
|
let fn_name = if fn_name == "Response" { "response" } else { fn_name };
|
||||||
"response"
|
|
||||||
} else {
|
|
||||||
fn_name
|
|
||||||
};
|
|
||||||
|
|
||||||
let function = self
|
let function = self
|
||||||
.plugin_manager
|
.plugin_manager
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ impl Encoder for DynamicCodec {
|
|||||||
type Error = Status;
|
type Error = Status;
|
||||||
|
|
||||||
fn encode(&mut self, item: Self::Item, dst: &mut EncodeBuf<'_>) -> Result<(), Self::Error> {
|
fn encode(&mut self, item: Self::Item, dst: &mut EncodeBuf<'_>) -> Result<(), Self::Error> {
|
||||||
item.encode(dst)
|
item.encode(dst).expect("buffer is too small to decode this message");
|
||||||
.expect("buffer is too small to decode this message");
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,8 +44,7 @@ impl Decoder for DynamicCodec {
|
|||||||
|
|
||||||
fn decode(&mut self, src: &mut DecodeBuf<'_>) -> Result<Option<Self::Item>, Self::Error> {
|
fn decode(&mut self, src: &mut DecodeBuf<'_>) -> Result<Option<Self::Item>, Self::Error> {
|
||||||
let mut msg = DynamicMessage::new(self.0.output());
|
let mut msg = DynamicMessage::new(self.0.output());
|
||||||
msg.merge(src)
|
msg.merge(src).map_err(|err| Status::internal(err.to_string()))?;
|
||||||
.map_err(|err| Status::internal(err.to_string()))?;
|
|
||||||
Ok(Some(msg))
|
Ok(Some(msg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,15 +30,13 @@ pub struct MethodDefinition {
|
|||||||
pub server_streaming: bool,
|
pub server_streaming: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
static SERIALIZE_OPTIONS: &'static SerializeOptions = &SerializeOptions::new()
|
static SERIALIZE_OPTIONS: &'static SerializeOptions =
|
||||||
.skip_default_fields(false)
|
&SerializeOptions::new().skip_default_fields(false).stringify_64_bit_integers(false);
|
||||||
.stringify_64_bit_integers(false);
|
|
||||||
|
|
||||||
pub fn serialize_message(msg: &DynamicMessage) -> Result<String, String> {
|
pub fn serialize_message(msg: &DynamicMessage) -> Result<String, String> {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let mut se = serde_json::Serializer::pretty(&mut buf);
|
let mut se = serde_json::Serializer::pretty(&mut buf);
|
||||||
msg.serialize_with_options(&mut se, SERIALIZE_OPTIONS)
|
msg.serialize_with_options(&mut se, SERIALIZE_OPTIONS).map_err(|e| e.to_string())?;
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
let s = String::from_utf8(buf).expect("serde_json to emit valid utf8");
|
let s = String::from_utf8(buf).expect("serde_json to emit valid utf8");
|
||||||
Ok(s)
|
Ok(s)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,19 +54,14 @@ impl From<Status> for StreamError {
|
|||||||
|
|
||||||
impl GrpcConnection {
|
impl GrpcConnection {
|
||||||
pub fn service(&self, service: &str) -> Result<ServiceDescriptor, String> {
|
pub fn service(&self, service: &str) -> Result<ServiceDescriptor, String> {
|
||||||
let service = self
|
let service = self.pool.get_service_by_name(service).ok_or("Failed to find service")?;
|
||||||
.pool
|
|
||||||
.get_service_by_name(service)
|
|
||||||
.ok_or("Failed to find service")?;
|
|
||||||
Ok(service)
|
Ok(service)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn method(&self, service: &str, method: &str) -> Result<MethodDescriptor, String> {
|
pub fn method(&self, service: &str, method: &str) -> Result<MethodDescriptor, String> {
|
||||||
let service = self.service(service)?;
|
let service = self.service(service)?;
|
||||||
let method = service
|
let method =
|
||||||
.methods()
|
service.methods().find(|m| m.name() == method).ok_or("Failed to find method")?;
|
||||||
.find(|m| m.name() == method)
|
|
||||||
.ok_or("Failed to find method")?;
|
|
||||||
Ok(method)
|
Ok(method)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,13 +127,10 @@ impl GrpcConnection {
|
|||||||
let path = method_desc_to_path(method);
|
let path = method_desc_to_path(method);
|
||||||
let codec = DynamicCodec::new(method.clone());
|
let codec = DynamicCodec::new(method.clone());
|
||||||
client.ready().await.unwrap();
|
client.ready().await.unwrap();
|
||||||
client
|
client.client_streaming(req, path, codec).await.map_err(|e| StreamError {
|
||||||
.client_streaming(req, path, codec)
|
message: e.message().to_string(),
|
||||||
.await
|
status: Some(e),
|
||||||
.map_err(|e| StreamError {
|
})
|
||||||
message: e.message().to_string(),
|
|
||||||
status: Some(e),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn server_streaming(
|
pub async fn server_streaming(
|
||||||
@@ -197,8 +189,7 @@ impl GrpcHandle {
|
|||||||
fill_pool_from_files(&self.app_handle, proto_files).await
|
fill_pool_from_files(&self.app_handle, proto_files).await
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
self.pools
|
self.pools.insert(make_pool_key(id, uri, proto_files), pool.clone());
|
||||||
.insert(make_pool_key(id, uri, proto_files), pool.clone());
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,9 +202,7 @@ impl GrpcHandle {
|
|||||||
// Ensure reflection is up-to-date
|
// Ensure reflection is up-to-date
|
||||||
self.reflect(id, uri, proto_files).await?;
|
self.reflect(id, uri, proto_files).await?;
|
||||||
|
|
||||||
let pool = self
|
let pool = self.get_pool(id, uri, proto_files).ok_or("Failed to get pool".to_string())?;
|
||||||
.get_pool(id, uri, proto_files)
|
|
||||||
.ok_or("Failed to get pool".to_string())?;
|
|
||||||
Ok(self.services_from_pool(&pool))
|
Ok(self.services_from_pool(&pool))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +223,7 @@ impl GrpcHandle {
|
|||||||
&pool,
|
&pool,
|
||||||
input_message,
|
input_message,
|
||||||
))
|
))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
def
|
def
|
||||||
@@ -249,9 +238,7 @@ impl GrpcHandle {
|
|||||||
proto_files: &Vec<PathBuf>,
|
proto_files: &Vec<PathBuf>,
|
||||||
) -> Result<GrpcConnection, String> {
|
) -> Result<GrpcConnection, String> {
|
||||||
self.reflect(id, uri, proto_files).await?;
|
self.reflect(id, uri, proto_files).await?;
|
||||||
let pool = self
|
let pool = self.get_pool(id, uri, proto_files).ok_or("Failed to get pool")?;
|
||||||
.get_pool(id, uri, proto_files)
|
|
||||||
.ok_or("Failed to get pool")?;
|
|
||||||
|
|
||||||
let uri = uri_from_str(uri)?;
|
let uri = uri_from_str(uri)?;
|
||||||
let conn = get_transport();
|
let conn = get_transport();
|
||||||
@@ -301,4 +288,4 @@ fn make_pool_key(id: &str, uri: &str, proto_files: &Vec<PathBuf>) -> String {
|
|||||||
);
|
);
|
||||||
|
|
||||||
format!("{:x}", md5::compute(pool_key))
|
format!("{:x}", md5::compute(pool_key))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ pub async fn fill_pool_from_reflection(uri: &Uri) -> Result<DescriptorPool, Stri
|
|||||||
if service == "grpc.reflection.v1alpha.ServerReflection" {
|
if service == "grpc.reflection.v1alpha.ServerReflection" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if service == "grpc.reflection.v1.ServerReflection"{
|
if service == "grpc.reflection.v1.ServerReflection" {
|
||||||
// TODO: update reflection client to use v1
|
// TODO: update reflection client to use v1
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -316,8 +316,8 @@ mod topology {
|
|||||||
zero_indegree.push(node.clone());
|
zero_indegree.push(node.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (node, deps) in data.out_graph.iter(){
|
for (node, deps) in data.out_graph.iter() {
|
||||||
if deps.is_empty(){
|
if deps.is_empty() {
|
||||||
zero_indegree.push(node.clone());
|
zero_indegree.push(node.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,8 +344,8 @@ mod topology {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let node = self.zero_indegree.pop().unwrap();
|
let node = self.zero_indegree.pop().unwrap();
|
||||||
if let Some(parents) = self.data.in_graph.get(&node){
|
if let Some(parents) = self.data.in_graph.get(&node) {
|
||||||
for parent in parents.iter(){
|
for parent in parents.iter() {
|
||||||
let deps = self.data.out_graph.get_mut(parent).unwrap();
|
let deps = self.data.out_graph.get_mut(parent).unwrap();
|
||||||
deps.remove(&node);
|
deps.remove(&node);
|
||||||
if deps.is_empty() {
|
if deps.is_empty() {
|
||||||
@@ -360,7 +360,7 @@ mod topology {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sort(){
|
fn test_sort() {
|
||||||
{
|
{
|
||||||
let mut topo_sort = SimpleTopoSort::new();
|
let mut topo_sort = SimpleTopoSort::new();
|
||||||
topo_sort.insert("a", []);
|
topo_sort.insert("a", []);
|
||||||
@@ -390,5 +390,4 @@ mod topology {
|
|||||||
assert_eq!(iter.next(), None);
|
assert_eq!(iter.next(), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,9 @@ pub async fn check_license<R: Runtime>(app_handle: &AppHandle<R>) -> Result<Lice
|
|||||||
|
|
||||||
match (has_activation_id, trial_period_active) {
|
match (has_activation_id, trial_period_active) {
|
||||||
(false, true) => Ok(LicenseCheckStatus::Trialing { end: trial_end }),
|
(false, true) => Ok(LicenseCheckStatus::Trialing { end: trial_end }),
|
||||||
(false, false) => Ok(LicenseCheckStatus::PersonalUse { trial_ended: trial_end }),
|
(false, false) => Ok(LicenseCheckStatus::PersonalUse {
|
||||||
|
trial_ended: trial_end,
|
||||||
|
}),
|
||||||
(true, _) => {
|
(true, _) => {
|
||||||
info!("Checking license activation");
|
info!("Checking license activation");
|
||||||
// A license has been activated, so let's check the license server
|
// A license has been activated, so let's check the license server
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
pub mod error;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod queries;
|
pub mod queries;
|
||||||
pub mod error;
|
|
||||||
|
|
||||||
pub mod plugin;
|
pub mod plugin;
|
||||||
|
|||||||
@@ -1,37 +1,37 @@
|
|||||||
|
use crate::server::plugin_runtime::EventStreamEvent;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tokio::io;
|
use tokio::io;
|
||||||
use tokio::sync::mpsc::error::SendError;
|
use tokio::sync::mpsc::error::SendError;
|
||||||
use crate::server::plugin_runtime::EventStreamEvent;
|
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("IO error: {0}")]
|
#[error("IO error: {0}")]
|
||||||
IoErr(#[from] io::Error),
|
IoErr(#[from] io::Error),
|
||||||
|
|
||||||
#[error("Tauri error: {0}")]
|
#[error("Tauri error: {0}")]
|
||||||
TauriErr(#[from] tauri::Error),
|
TauriErr(#[from] tauri::Error),
|
||||||
|
|
||||||
#[error("Tauri shell error: {0}")]
|
#[error("Tauri shell error: {0}")]
|
||||||
TauriShellErr(#[from] tauri_plugin_shell::Error),
|
TauriShellErr(#[from] tauri_plugin_shell::Error),
|
||||||
|
|
||||||
#[error("Grpc transport error: {0}")]
|
#[error("Grpc transport error: {0}")]
|
||||||
GrpcTransportErr(#[from] tonic::transport::Error),
|
GrpcTransportErr(#[from] tonic::transport::Error),
|
||||||
|
|
||||||
#[error("Grpc send error: {0}")]
|
#[error("Grpc send error: {0}")]
|
||||||
GrpcSendErr(#[from] SendError<tonic::Result<EventStreamEvent>>),
|
GrpcSendErr(#[from] SendError<tonic::Result<EventStreamEvent>>),
|
||||||
|
|
||||||
#[error("JSON error: {0}")]
|
#[error("JSON error: {0}")]
|
||||||
JsonErr(#[from] serde_json::Error),
|
JsonErr(#[from] serde_json::Error),
|
||||||
|
|
||||||
#[error("Plugin not found: {0}")]
|
#[error("Plugin not found: {0}")]
|
||||||
PluginNotFoundErr(String),
|
PluginNotFoundErr(String),
|
||||||
|
|
||||||
#[error("Plugin error: {0}")]
|
#[error("Plugin error: {0}")]
|
||||||
PluginErr(String),
|
PluginErr(String),
|
||||||
|
|
||||||
#[error("Client not initialized error")]
|
#[error("Client not initialized error")]
|
||||||
ClientNotInitializedErr,
|
ClientNotInitializedErr,
|
||||||
|
|
||||||
#[error("Unknown event received")]
|
#[error("Unknown event received")]
|
||||||
UnknownEventErr,
|
UnknownEventErr,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
use std::process::exit;
|
use crate::manager::PluginManager;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
use std::process::exit;
|
||||||
use tauri::plugin::{Builder, TauriPlugin};
|
use tauri::plugin::{Builder, TauriPlugin};
|
||||||
use tauri::{Manager, RunEvent, Runtime, State};
|
use tauri::{Manager, RunEvent, Runtime, State};
|
||||||
use crate::manager::PluginManager;
|
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod manager;
|
pub mod manager;
|
||||||
mod nodejs;
|
mod nodejs;
|
||||||
mod server;
|
|
||||||
pub mod plugin_handle;
|
pub mod plugin_handle;
|
||||||
|
mod server;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::net::SocketAddr;
|
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
use log::info;
|
use log::info;
|
||||||
use serde;
|
use serde;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::net::SocketAddr;
|
||||||
use tauri::path::BaseDirectory;
|
use tauri::path::BaseDirectory;
|
||||||
use tauri::{AppHandle, Manager, Runtime};
|
use tauri::{AppHandle, Manager, Runtime};
|
||||||
use tauri_plugin_shell::process::CommandEvent;
|
use tauri_plugin_shell::process::CommandEvent;
|
||||||
@@ -20,15 +20,12 @@ pub async fn start_nodejs_plugin_runtime<R: Runtime>(
|
|||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
kill_rx: &Receiver<bool>,
|
kill_rx: &Receiver<bool>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let plugin_runtime_main = app
|
let plugin_runtime_main =
|
||||||
.path()
|
app.path().resolve("vendored/plugin-runtime", BaseDirectory::Resource)?.join("index.cjs");
|
||||||
.resolve("vendored/plugin-runtime", BaseDirectory::Resource)?
|
|
||||||
.join("index.cjs");
|
|
||||||
|
|
||||||
// HACK: Remove UNC prefix for Windows paths to pass to sidecar
|
// HACK: Remove UNC prefix for Windows paths to pass to sidecar
|
||||||
let plugin_runtime_main = dunce::simplified(plugin_runtime_main.as_path())
|
let plugin_runtime_main =
|
||||||
.to_string_lossy()
|
dunce::simplified(plugin_runtime_main.as_path()).to_string_lossy().to_string();
|
||||||
.to_string();
|
|
||||||
|
|
||||||
info!("Starting plugin runtime main={}", plugin_runtime_main);
|
info!("Starting plugin runtime main={}", plugin_runtime_main);
|
||||||
|
|
||||||
@@ -59,10 +56,7 @@ pub async fn start_nodejs_plugin_runtime<R: Runtime>(
|
|||||||
|
|
||||||
// Check on child
|
// Check on child
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
kill_rx
|
kill_rx.wait_for(|b| *b == true).await.expect("Kill channel errored");
|
||||||
.wait_for(|b| *b == true)
|
|
||||||
.await
|
|
||||||
.expect("Kill channel errored");
|
|
||||||
info!("Killing plugin runtime");
|
info!("Killing plugin runtime");
|
||||||
child.kill().expect("Failed to kill plugin runtime");
|
child.kill().expect("Failed to kill plugin runtime");
|
||||||
info!("Killed plugin runtime");
|
info!("Killed plugin runtime");
|
||||||
|
|||||||
@@ -57,11 +57,8 @@ impl PluginHandle {
|
|||||||
|
|
||||||
pub async fn terminate(&self, window_context: WindowContext) -> Result<()> {
|
pub async fn terminate(&self, window_context: WindowContext) -> Result<()> {
|
||||||
info!("Terminating plugin {}", self.dir);
|
info!("Terminating plugin {}", self.dir);
|
||||||
let event = self.build_event_to_send(
|
let event =
|
||||||
window_context,
|
self.build_event_to_send(window_context, &InternalEventPayload::TerminateRequest, None);
|
||||||
&InternalEventPayload::TerminateRequest,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
self.send(&event).await
|
self.send(&event).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
pub mod format;
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
pub mod renderer;
|
pub mod renderer;
|
||||||
pub mod format;
|
|
||||||
|
|
||||||
pub use parser::*;
|
pub use parser::*;
|
||||||
pub use renderer::*;
|
pub use renderer::*;
|
||||||
|
|||||||
@@ -3,25 +3,20 @@ use std::fmt::Display;
|
|||||||
use ts_rs::TS;
|
use ts_rs::TS;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
||||||
#[ts(export, export_to="parser.ts")]
|
#[ts(export, export_to = "parser.ts")]
|
||||||
pub struct Tokens {
|
pub struct Tokens {
|
||||||
pub tokens: Vec<Token>,
|
pub tokens: Vec<Token>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Tokens {
|
impl Display for Tokens {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let str = self
|
let str = self.tokens.iter().map(|t| t.to_string()).collect::<Vec<String>>().join("");
|
||||||
.tokens
|
|
||||||
.iter()
|
|
||||||
.map(|t| t.to_string())
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join("");
|
|
||||||
write!(f, "{}", str)
|
write!(f, "{}", str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
||||||
#[ts(export, export_to="parser.ts")]
|
#[ts(export, export_to = "parser.ts")]
|
||||||
pub struct FnArg {
|
pub struct FnArg {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub value: Val,
|
pub value: Val,
|
||||||
@@ -36,7 +31,7 @@ impl Display for FnArg {
|
|||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
||||||
#[serde(rename_all = "snake_case", tag = "type")]
|
#[serde(rename_all = "snake_case", tag = "type")]
|
||||||
#[ts(export, export_to="parser.ts")]
|
#[ts(export, export_to = "parser.ts")]
|
||||||
pub enum Val {
|
pub enum Val {
|
||||||
Str { text: String },
|
Str { text: String },
|
||||||
Var { name: String },
|
Var { name: String },
|
||||||
@@ -71,7 +66,7 @@ impl Display for Val {
|
|||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
||||||
#[serde(rename_all = "snake_case", tag = "type")]
|
#[serde(rename_all = "snake_case", tag = "type")]
|
||||||
#[ts(export, export_to="parser.ts")]
|
#[ts(export, export_to = "parser.ts")]
|
||||||
pub enum Token {
|
pub enum Token {
|
||||||
Raw { text: String },
|
Raw { text: String },
|
||||||
Tag { val: Val },
|
Tag { val: Val },
|
||||||
@@ -396,9 +391,7 @@ impl Parser {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cmp = self.chars[self.pos..self.pos + value.len()]
|
let cmp = self.chars[self.pos..self.pos + value.len()].iter().collect::<String>();
|
||||||
.iter()
|
|
||||||
.collect::<String>();
|
|
||||||
|
|
||||||
if cmp == value {
|
if cmp == value {
|
||||||
// We have a match, so advance the current index
|
// We have a match, so advance the current index
|
||||||
|
|||||||
@@ -80,10 +80,7 @@ async fn render_tag<T: TemplateCallback>(
|
|||||||
match cb.run(name.as_str(), resolved_args.clone()).await {
|
match cb.run(name.as_str(), resolved_args.clone()).await {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!(
|
warn!("Failed to run template callback {}({:?}): {}", name, resolved_args, e);
|
||||||
"Failed to run template callback {}({:?}): {}",
|
|
||||||
name, resolved_args, e
|
|
||||||
);
|
|
||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,10 +113,7 @@ mod tests {
|
|||||||
let template = "";
|
let template = "";
|
||||||
let vars = HashMap::new();
|
let vars = HashMap::new();
|
||||||
let result = "";
|
let result = "";
|
||||||
assert_eq!(
|
assert_eq!(parse_and_render(template, &vars, &empty_cb).await, result.to_string());
|
||||||
parse_and_render(template, &vars, &empty_cb).await,
|
|
||||||
result.to_string()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -128,10 +122,7 @@ mod tests {
|
|||||||
let template = "Hello World!";
|
let template = "Hello World!";
|
||||||
let vars = HashMap::new();
|
let vars = HashMap::new();
|
||||||
let result = "Hello World!";
|
let result = "Hello World!";
|
||||||
assert_eq!(
|
assert_eq!(parse_and_render(template, &vars, &empty_cb).await, result.to_string());
|
||||||
parse_and_render(template, &vars, &empty_cb).await,
|
|
||||||
result.to_string()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -140,10 +131,7 @@ mod tests {
|
|||||||
let template = "${[ foo ]}";
|
let template = "${[ foo ]}";
|
||||||
let vars = HashMap::from([("foo".to_string(), "bar".to_string())]);
|
let vars = HashMap::from([("foo".to_string(), "bar".to_string())]);
|
||||||
let result = "bar";
|
let result = "bar";
|
||||||
assert_eq!(
|
assert_eq!(parse_and_render(template, &vars, &empty_cb).await, result.to_string());
|
||||||
parse_and_render(template, &vars, &empty_cb).await,
|
|
||||||
result.to_string()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -156,10 +144,7 @@ mod tests {
|
|||||||
vars.insert("baz".to_string(), "baz".to_string());
|
vars.insert("baz".to_string(), "baz".to_string());
|
||||||
|
|
||||||
let result = "foo: bar: baz";
|
let result = "foo: bar: baz";
|
||||||
assert_eq!(
|
assert_eq!(parse_and_render(template, &vars, &empty_cb).await, result.to_string());
|
||||||
parse_and_render(template, &vars, &empty_cb).await,
|
|
||||||
result.to_string()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -168,10 +153,7 @@ mod tests {
|
|||||||
let template = "hello ${[ word ]} world!";
|
let template = "hello ${[ word ]} world!";
|
||||||
let vars = HashMap::from([("word".to_string(), "cruel".to_string())]);
|
let vars = HashMap::from([("word".to_string(), "cruel".to_string())]);
|
||||||
let result = "hello cruel world!";
|
let result = "hello cruel world!";
|
||||||
assert_eq!(
|
assert_eq!(parse_and_render(template, &vars, &empty_cb).await, result.to_string());
|
||||||
parse_and_render(template, &vars, &empty_cb).await,
|
|
||||||
result.to_string()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -187,12 +169,7 @@ mod tests {
|
|||||||
fn_name: &str,
|
fn_name: &str,
|
||||||
args: HashMap<String, String>,
|
args: HashMap<String, String>,
|
||||||
) -> Result<String, String> {
|
) -> Result<String, String> {
|
||||||
Ok(format!(
|
Ok(format!("{fn_name}: {}, {:?} {:?}", args.len(), args.get("a"), args.get("b")))
|
||||||
"{fn_name}: {}, {:?} {:?}",
|
|
||||||
args.len(),
|
|
||||||
args.get("a"),
|
|
||||||
args.get("b")
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_eq!(parse_and_render(template, &vars, &CB {}).await, result);
|
assert_eq!(parse_and_render(template, &vars, &CB {}).await, result);
|
||||||
@@ -218,10 +195,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(parse_and_render(template, &vars, &CB {}).await, result.to_string());
|
||||||
parse_and_render(template, &vars, &CB {}).await,
|
|
||||||
result.to_string()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -241,9 +215,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(parse_and_render(template, &vars, &CB {}).await, result.to_string());
|
||||||
parse_and_render(template, &vars, &CB {}).await,
|
|
||||||
result.to_string()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user