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

@ -0,0 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
[package]
name = "appflowy_tauri"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
rust-version = "1.57"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.2", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2", features = ["shell-open"] }
bytes = { version = "1.0" }
tracing = { version = "0.1", features = ["log"] }
lib-dispatch = { path = "../../rust-lib/lib-dispatch", features = ["use_serde"] }
flowy-core = { path = "../../rust-lib/flowy-core", features = ["rev-sqlite","ts"] }
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = ["custom-protocol"]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = ["tauri/custom-protocol"]

View File

@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View File

@ -0,0 +1,15 @@
use serde::Serialize;
use tauri::{AppHandle, Event, Manager, Wry};
#[allow(dead_code)]
pub const AF_EVENT: &str = "af-event";
#[allow(dead_code)]
pub const AF_NOTIFICATION: &str = "af-notification";
#[tracing::instrument(level = "trace")]
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();
}

View File

@ -0,0 +1,10 @@
use flowy_core::{get_client_server_configuration, FlowySDK, FlowySDKConfig};
pub fn init_flowy_core() -> FlowySDK {
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 = FlowySDKConfig::new(&path, "AppFlowy".to_string(), server_config)
.log_filter("trace", vec!["appflowy_tauri".to_string()]);
FlowySDK::new(config)
}

View File

@ -0,0 +1,38 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
mod event;
mod init;
mod request;
use event::*;
use flowy_core::FlowySDK;
use init::*;
use request::*;
use tauri::{Manager, State};
fn main() {
let sdk = init_flowy_core();
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![invoke_request])
.manage(sdk)
.on_window_event(|_window_event| {})
.on_menu_event(|_menu| {})
.on_page_load(|window, _payload| {
let app_handler = window.app_handle();
// tauri::async_runtime::spawn(async move {});
window.listen_global(AF_EVENT, move |event| {
on_event(app_handler.clone(), event);
});
})
.setup(|app| {
let window = app.get_window("main").unwrap();
#[cfg(debug_assertions)]
window.open_devtools();
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -0,0 +1,46 @@
use flowy_core::FlowySDK;
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
#[tracing::instrument(level = "trace", skip(app_handler))]
#[tauri::command]
pub async fn invoke_request(
request: AFTauriRequest,
app_handler: AppHandle<Wry>,
) -> AFTauriResponse {
let request: AFPluginRequest = request.into();
let state: State<FlowySDK> = app_handler.state();
let dispatcher = state.inner().dispatcher();
let response = AFPluginDispatcher::async_send(dispatcher, request).await;
response.into()
}

View File

@ -0,0 +1,70 @@
{
"build": {
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": false
},
"package": {
"productName": "AppFlowy",
"version": "0.0.0"
},
"tauri": {
"allowlist": {
"all": false,
"shell": {
"all": false,
"open": true
}
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.appflowy.tauri",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "AppFlowy",
"width": 800
}
]
}
}