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>
4
frontend/appflowy_tauri/src-tauri/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
5630
frontend/appflowy_tauri/src-tauri/Cargo.lock
generated
Normal file
31
frontend/appflowy_tauri/src-tauri/Cargo.toml
Normal 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"]
|
3
frontend/appflowy_tauri/src-tauri/build.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
BIN
frontend/appflowy_tauri/src-tauri/icons/128x128.png
Normal file
After Width: | Height: | Size: 9.0 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/128x128@2x.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/32x32.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/Square107x107Logo.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/Square142x142Logo.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/Square150x150Logo.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/Square284x284Logo.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/Square30x30Logo.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/Square310x310Logo.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/Square44x44Logo.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/Square71x71Logo.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/Square89x89Logo.png
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/StoreLogo.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/icon.icns
Normal file
BIN
frontend/appflowy_tauri/src-tauri/icons/icon.ico
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
frontend/appflowy_tauri/src-tauri/icons/icon.png
Normal file
After Width: | Height: | Size: 41 KiB |
15
frontend/appflowy_tauri/src-tauri/src/event.rs
Normal 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();
|
||||
}
|
10
frontend/appflowy_tauri/src-tauri/src/init.rs
Normal 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)
|
||||
}
|
38
frontend/appflowy_tauri/src-tauri/src/main.rs
Normal 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");
|
||||
}
|
46
frontend/appflowy_tauri/src-tauri/src/request.rs
Normal 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()
|
||||
}
|
70
frontend/appflowy_tauri/src-tauri/tauri.conf.json
Normal 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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|