mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: run rustfmt with custom defined fmt configuration (#1848)
* chore: update rustfmt * chore: apply rustfmt format
This commit is contained in:
@ -1,3 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
tauri_build::build()
|
||||
}
|
||||
|
12
frontend/appflowy_tauri/src-tauri/rustfmt.toml
Normal file
12
frontend/appflowy_tauri/src-tauri/rustfmt.toml
Normal file
@ -0,0 +1,12 @@
|
||||
# https://rust-lang.github.io/rustfmt/?version=master&search=
|
||||
max_width = 100
|
||||
tab_spaces = 2
|
||||
newline_style = "Auto"
|
||||
match_block_trailing_comma = true
|
||||
use_field_init_shorthand = true
|
||||
use_try_shorthand = true
|
||||
reorder_imports = true
|
||||
reorder_modules = true
|
||||
remove_nested_parens = true
|
||||
merge_derives = true
|
||||
edition = "2021"
|
@ -1,10 +1,10 @@
|
||||
use flowy_core::{get_client_server_configuration, AppFlowyCore, AppFlowyCoreConfig};
|
||||
|
||||
pub fn init_flowy_core() -> AppFlowyCore {
|
||||
let data_path = tauri::api::path::data_dir().unwrap();
|
||||
let path = format!("{}/AppFlowy", data_path.to_str().unwrap());
|
||||
let server_config = get_client_server_configuration().unwrap();
|
||||
let config = AppFlowyCoreConfig::new(&path, "AppFlowy".to_string(), server_config)
|
||||
.log_filter("trace", vec!["appflowy_tauri".to_string()]);
|
||||
AppFlowyCore::new(config)
|
||||
let data_path = tauri::api::path::data_dir().unwrap();
|
||||
let path = format!("{}/AppFlowy", data_path.to_str().unwrap());
|
||||
let server_config = get_client_server_configuration().unwrap();
|
||||
let config = AppFlowyCoreConfig::new(&path, "AppFlowy".to_string(), server_config)
|
||||
.log_filter("trace", vec!["appflowy_tauri".to_string()]);
|
||||
AppFlowyCore::new(config)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![cfg_attr(
|
||||
all(not(debug_assertions), target_os = "windows"),
|
||||
windows_subsystem = "windows"
|
||||
all(not(debug_assertions), target_os = "windows"),
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
mod init;
|
||||
@ -14,28 +14,28 @@ use request::*;
|
||||
use tauri::Manager;
|
||||
|
||||
fn main() {
|
||||
let flowy_core = init_flowy_core();
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![invoke_request])
|
||||
.manage(flowy_core)
|
||||
.on_window_event(|_window_event| {})
|
||||
.on_menu_event(|_menu| {})
|
||||
.on_page_load(|window, _payload| {
|
||||
let app_handler = window.app_handle();
|
||||
register_notification_sender(TSNotificationSender::new(app_handler.clone()));
|
||||
// tauri::async_runtime::spawn(async move {});
|
||||
window.listen_global(AF_EVENT, move |event| {
|
||||
on_event(app_handler.clone(), event);
|
||||
});
|
||||
})
|
||||
.setup(|app| {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let window = app.get_window("main").unwrap();
|
||||
window.open_devtools();
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
let flowy_core = init_flowy_core();
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![invoke_request])
|
||||
.manage(flowy_core)
|
||||
.on_window_event(|_window_event| {})
|
||||
.on_menu_event(|_menu| {})
|
||||
.on_page_load(|window, _payload| {
|
||||
let app_handler = window.app_handle();
|
||||
register_notification_sender(TSNotificationSender::new(app_handler.clone()));
|
||||
// tauri::async_runtime::spawn(async move {});
|
||||
window.listen_global(AF_EVENT, move |event| {
|
||||
on_event(app_handler.clone(), event);
|
||||
});
|
||||
})
|
||||
.setup(|app| {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let window = app.get_window("main").unwrap();
|
||||
window.open_devtools();
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -12,23 +12,24 @@ pub fn on_event(app_handler: AppHandle<Wry>, event: Event) {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn send_notification<P: Serialize + Clone>(app_handler: AppHandle<Wry>, payload: P) {
|
||||
app_handler.emit_all(AF_NOTIFICATION, payload).unwrap();
|
||||
app_handler.emit_all(AF_NOTIFICATION, payload).unwrap();
|
||||
}
|
||||
|
||||
pub struct TSNotificationSender {
|
||||
handler: AppHandle<Wry>,
|
||||
handler: AppHandle<Wry>,
|
||||
}
|
||||
|
||||
impl TSNotificationSender {
|
||||
pub fn new(handler: AppHandle<Wry>) -> Self {
|
||||
Self { handler }
|
||||
}
|
||||
pub fn new(handler: AppHandle<Wry>) -> Self {
|
||||
Self { handler }
|
||||
}
|
||||
}
|
||||
|
||||
impl NotificationSender for TSNotificationSender {
|
||||
fn send_subject(&self, subject: SubscribeObject) -> Result<(), String> {
|
||||
self.handler
|
||||
.emit_all(AF_NOTIFICATION, subject)
|
||||
.map_err(|e| format!("{:?}", e))
|
||||
}
|
||||
fn send_subject(&self, subject: SubscribeObject) -> Result<(), String> {
|
||||
self
|
||||
.handler
|
||||
.emit_all(AF_NOTIFICATION, subject)
|
||||
.map_err(|e| format!("{:?}", e))
|
||||
}
|
||||
}
|
||||
|
@ -1,46 +1,46 @@
|
||||
use flowy_core::AppFlowyCore;
|
||||
use lib_dispatch::prelude::{
|
||||
AFPluginDispatcher, AFPluginEventResponse, AFPluginRequest, StatusCode,
|
||||
AFPluginDispatcher, AFPluginEventResponse, AFPluginRequest, StatusCode,
|
||||
};
|
||||
use tauri::{AppHandle, Manager, State, Wry};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
pub struct AFTauriRequest {
|
||||
ty: String,
|
||||
payload: Vec<u8>,
|
||||
ty: String,
|
||||
payload: Vec<u8>,
|
||||
}
|
||||
|
||||
impl std::convert::From<AFTauriRequest> for AFPluginRequest {
|
||||
fn from(event: AFTauriRequest) -> Self {
|
||||
AFPluginRequest::new(event.ty).payload(event.payload)
|
||||
}
|
||||
fn from(event: AFTauriRequest) -> Self {
|
||||
AFPluginRequest::new(event.ty).payload(event.payload)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, serde::Serialize)]
|
||||
pub struct AFTauriResponse {
|
||||
code: StatusCode,
|
||||
payload: Vec<u8>,
|
||||
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(),
|
||||
}
|
||||
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
|
||||
#[tracing::instrument(level = "trace", skip(app_handler))]
|
||||
#[tauri::command]
|
||||
pub async fn invoke_request(
|
||||
request: AFTauriRequest,
|
||||
app_handler: AppHandle<Wry>,
|
||||
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, request).await;
|
||||
response.into()
|
||||
let request: AFPluginRequest = request.into();
|
||||
let state: State<AppFlowyCore> = app_handler.state();
|
||||
let dispatcher = state.inner().dispatcher();
|
||||
let response = AFPluginDispatcher::async_send(dispatcher, request).await;
|
||||
response.into()
|
||||
}
|
||||
|
Reference in New Issue
Block a user