AppFlowy/frontend/appflowy_tauri/src-tauri/src/request.rs
Nathan.fooo 55c97b56a3
feat: calling user event from web (#4535)
* refactor: user manager

* refactor: user manager

* refactor: session location

* refactor: user manager

* chore: gen ts files

* feat: implement indexeddb persistence

* chore: integrate user manager

* chore: update

* chore: run on web thread

* chore: run on web thread

* chore: fix test

* chore: add test

* chore: add test

* chore: add user & sign in with password

* chore: fix test

* chore: update docs

* chore: fix warnings

* chore: gen files

* chore: add user

* chore: add files

* chore: update config

* chore: update scirpt

* chore: update scirpt

* fix: build

* chore: update command

* fix: ci

* ci: fix

* fix: compile

* fix: compile

* fix: ci

* fix: compile

* fix: tauri build

* chore: fix test

* chore: fix test
2024-01-30 05:36:27 +08:00

46 lines
1.2 KiB
Rust

use flowy_core::AppFlowyCore;
use lib_dispatch::prelude::{
AFPluginDispatcher, AFPluginEventResponse, AFPluginRequest, StatusCode,
};
use tauri::{AppHandle, Manager, State, Wry};
#[derive(Clone, Debug, serde::Deserialize)]
pub struct AFTauriRequest {
ty: String,
payload: Vec<u8>,
}
impl std::convert::From<AFTauriRequest> for AFPluginRequest {
fn from(event: AFTauriRequest) -> Self {
AFPluginRequest::new(event.ty).payload(event.payload)
}
}
#[derive(Clone, serde::Serialize)]
pub struct AFTauriResponse {
code: StatusCode,
payload: Vec<u8>,
}
impl std::convert::From<AFPluginEventResponse> for AFTauriResponse {
fn from(response: AFPluginEventResponse) -> Self {
Self {
code: response.status_code,
payload: response.payload.to_vec(),
}
}
}
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
pub async fn invoke_request(
request: AFTauriRequest,
app_handler: AppHandle<Wry>,
) -> AFTauriResponse {
let request: AFPluginRequest = request.into();
let state: State<AppFlowyCore> = app_handler.state();
let dispatcher = state.inner().dispatcher();
let response = AFPluginDispatcher::async_send(dispatcher.as_ref(), request).await;
response.into()
}