Feat/tauri (#1716)

* feat: support tauri desktop

* chore: support call flowy sdk command

* chore: switch to svelte

* chore: gen js protobuf

* chore: import js protobuf

* chore: call flowy sdk handler

* chore: update scipts

* chore: create index.ts

* chore: track files

* chore: gen ts event

* chore: replace application icon

* chore: migrate to react

* chore: fix wanrings

Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
Nathan.fooo
2023-01-17 16:27:17 +08:00
committed by GitHub
parent ba653ff463
commit f64346c955
94 changed files with 6749 additions and 99 deletions

View File

@ -24,6 +24,7 @@ dyn-clone = "1.0"
derivative = "2.2.0"
serde_json = {version = "1.0", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde_repr = { version = "0.1", optional = true }
dashmap = "5"
#optional crate
@ -37,5 +38,5 @@ futures-util = "0.3.15"
[features]
default = ["use_protobuf"]
use_serde = ["bincode", "serde_json", "serde"]
use_serde = ["bincode", "serde_json", "serde", "serde_repr"]
use_protobuf= ["protobuf"]

View File

@ -24,18 +24,18 @@ where
}
}
#[cfg(feature = "use_serde")]
impl<T> ToBytes for T
where
T: serde::Serialize,
{
fn into_bytes(self) -> Result<Bytes, DispatchError> {
match serde_json::to_string(&self.0) {
Ok(s) => Ok(Bytes::from(s)),
Err(e) => Err(InternalError::SerializeToBytes(format!("{:?}", e)).into()),
}
}
}
// #[cfg(feature = "use_serde")]
// impl<T> ToBytes for T
// where
// T: serde::Serialize,
// {
// fn into_bytes(self) -> Result<Bytes, DispatchError> {
// match serde_json::to_string(&self.0) {
// Ok(s) => Ok(Bytes::from(s)),
// Err(e) => Err(InternalError::SerializeToBytes(format!("{:?}", e)).into()),
// }
// }
// }
// From bytes
@ -65,18 +65,18 @@ where
}
}
}
#[cfg(feature = "use_serde")]
impl<T> AFPluginFromBytes for T
where
T: serde::de::DeserializeOwned + 'static,
{
fn parse_from_bytes(bytes: Bytes) -> Result<Self, String> {
let s = String::from_utf8_lossy(&bytes);
match serde_json::from_str::<T>(s.as_ref()) {
Ok(data) => Ok(data),
Err(e) => Err(format!("{:?}", e)),
}
}
}
//
// #[cfg(feature = "use_serde")]
// impl<T> AFPluginFromBytes for T
// where
// T: serde::de::DeserializeOwned + 'static,
// {
// fn parse_from_bytes(bytes: Bytes) -> Result<Self, String> {
// let s = String::from_utf8_lossy(&bytes);
//
// match serde_json::from_str::<T>(s.as_ref()) {
// Ok(data) => Ok(data),
// Err(e) => Err(format!("{:?}", e)),
// }
// }
// }

View File

@ -122,8 +122,7 @@ impl fmt::Display for InternalError {
impl Error for InternalError {
fn as_response(&self) -> AFPluginEventResponse {
let error = format!("{}", self).into_bytes();
ResponseBuilder::Internal().data(error).build()
ResponseBuilder::Err().data(self.to_string()).build()
}
}

View File

@ -37,7 +37,7 @@ pub(crate) fn as_plugin_map(plugins: Vec<AFPlugin>) -> AFPluginMap {
}
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
pub struct AFPluginEvent(String);
pub struct AFPluginEvent(pub String);
impl<T: Display + Eq + Hash + Debug + Clone> std::convert::From<T> for AFPluginEvent {
fn from(t: T) -> Self {

View File

@ -11,6 +11,15 @@ pub enum Payload {
Bytes(Bytes),
}
impl Payload {
pub fn to_vec(self) -> Vec<u8> {
match self {
Payload::None => vec![],
Payload::Bytes(bytes) => bytes.to_vec(),
}
}
}
impl std::fmt::Debug for Payload {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
format_payload_print(self, f)

View File

@ -39,5 +39,4 @@ impl ResponseBuilder {
static_response!(Ok, StatusCode::Ok);
static_response!(Err, StatusCode::Err);
static_response!(Internal, StatusCode::Internal);
}

View File

@ -9,11 +9,11 @@ use derivative::*;
use std::{convert::TryFrom, fmt, fmt::Formatter};
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "use_serde", derive(serde::Serialize))]
#[cfg_attr(feature = "use_serde", derive(serde_repr::Serialize_repr))]
#[repr(u8)]
pub enum StatusCode {
Ok = 0,
Err = 1,
Internal = 2,
}
// serde user guide: https://serde.rs/field-attrs.html
@ -43,7 +43,7 @@ impl AFPluginEventResponse {
let data = <AFPluginData<T>>::try_from(self.payload)?;
Ok(Ok(data.into_inner()))
}
StatusCode::Err | StatusCode::Internal => {
StatusCode::Err => {
let err = <AFPluginData<E>>::try_from(self.payload)?;
Ok(Err(err.into_inner()))
}