mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: appflowy_web build (#4302)
* chore: create web folder * fix: support lib-dispatch and notification compiling to wasm * refactor: wasm * refactor: call async evnet * chore: add web ci * ci: fix * ci: fix * ci: fix --------- Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
parent
89370b4a55
commit
79c912219d
14
.github/workflows/flutter_ci.yaml
vendored
14
.github/workflows/flutter_ci.yaml
vendored
@ -4,22 +4,20 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
- "develop"
|
||||
- "release/*"
|
||||
paths:
|
||||
- ".github/workflows/flutter_ci.yaml"
|
||||
- "frontend/**"
|
||||
- "!frontend/appflowy_tauri/**"
|
||||
- "frontend/rust-lib/**"
|
||||
- "frontend/appflowy_flutter/**"
|
||||
|
||||
pull_request:
|
||||
branches:
|
||||
- "main"
|
||||
- "develop"
|
||||
- "release/*"
|
||||
paths:
|
||||
- ".github/workflows/flutter_ci.yaml"
|
||||
- "frontend/**"
|
||||
- "!frontend/appflowy_tauri/**"
|
||||
- "frontend/rust-lib/**"
|
||||
- "frontend/appflowy_flutter/**"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@ -253,8 +251,10 @@ jobs:
|
||||
- name: Run Docker-Compose
|
||||
working-directory: AppFlowy-Cloud
|
||||
run: |
|
||||
#docker compose down -v --remove-orphans
|
||||
docker compose down -v --remove-orphans
|
||||
docker pull appflowyinc/appflowy_cloud:latest
|
||||
docker compose up -d
|
||||
docker ps -a
|
||||
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v2
|
||||
|
82
.github/workflows/web_ci.yaml
vendored
Normal file
82
.github/workflows/web_ci.yaml
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
name: WEB-CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "main"
|
||||
paths:
|
||||
- ".github/workflows/web_ci.yaml"
|
||||
- "frontend/rust-lib/**"
|
||||
- "frontend/appflowy_web/**"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
NODE_VERSION: "18.16.0"
|
||||
PNPM_VERSION: "8.5.0"
|
||||
RUST_TOOLCHAIN: "1.75"
|
||||
CARGO_MAKE_VERSION: "0.36.6"
|
||||
|
||||
jobs:
|
||||
web-build:
|
||||
if: github.event.pull_request.draft != true
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
platform: [ubuntu-latest]
|
||||
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: setup node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
|
||||
- name: Cache Rust Dependencies
|
||||
uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
key: rust-dependencies-${{ runner.os }}
|
||||
workspaces: |
|
||||
frontend/rust-lib
|
||||
frontend/appflowy_web/appflowy_wasm
|
||||
|
||||
- name: Cache Node.js dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: npm-${{ runner.os }}
|
||||
|
||||
- name: Cache node_modules
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: frontend/appflowy_web/node_modules
|
||||
key: node-modules-${{ runner.os }}
|
||||
|
||||
- name: Install Rust toolchain
|
||||
id: rust_toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ env.RUST_TOOLCHAIN }}
|
||||
override: true
|
||||
profile: minimal
|
||||
|
||||
- name: Install wasm-pack
|
||||
run: cargo install wasm-pack
|
||||
|
||||
- uses: taiki-e/install-action@v2
|
||||
with:
|
||||
tool: cargo-make@${{ env.CARGO_MAKE_VERSION }}
|
||||
|
||||
- name: install dependencies
|
||||
if: matrix.platform == 'ubuntu-latest'
|
||||
working-directory: frontend
|
||||
run: |
|
||||
sudo apt-get update
|
||||
npm install -g pnpm@${{ env.PNPM_VERSION }}
|
||||
cargo make install_web_protobuf
|
||||
|
||||
- name: Build
|
||||
working-directory: frontend/appflowy_web
|
||||
run: |
|
||||
pnpm install
|
||||
pnpm run wasm
|
13
frontend/appflowy_tauri/src-tauri/Cargo.lock
generated
13
frontend/appflowy_tauri/src-tauri/Cargo.lock
generated
@ -1781,6 +1781,7 @@ dependencies = [
|
||||
"flowy-notification",
|
||||
"flowy-storage",
|
||||
"futures",
|
||||
"getrandom 0.2.10",
|
||||
"indexmap 2.1.0",
|
||||
"lib-dispatch",
|
||||
"lib-infra",
|
||||
@ -2361,8 +2362,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3114,6 +3117,7 @@ dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"getrandom 0.2.10",
|
||||
"nanoid",
|
||||
"parking_lot",
|
||||
"pin-project",
|
||||
@ -3125,6 +3129,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"tracing",
|
||||
"validator",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -5079,18 +5084,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.188"
|
||||
version = "1.0.194"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
|
||||
checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.188"
|
||||
version = "1.0.194"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
|
||||
checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
18
frontend/appflowy_web/.eslintrc.cjs
Normal file
18
frontend/appflowy_web/.eslintrc.cjs
Normal file
@ -0,0 +1,18 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: { browser: true, es2020: true },
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:react-hooks/recommended',
|
||||
],
|
||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['react-refresh'],
|
||||
rules: {
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
}
|
26
frontend/appflowy_web/.gitignore
vendored
Normal file
26
frontend/appflowy_web/.gitignore
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
appflowy-wasm/target
|
23
frontend/appflowy_web/README.md
Normal file
23
frontend/appflowy_web/README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# AppFlowy Web Project
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
cd appflowy-web
|
||||
|
||||
# Install dependencies
|
||||
rm -rf node_modules && pnpm install
|
||||
```
|
||||
|
||||
## Running the app
|
||||
|
||||
```bash
|
||||
# development
|
||||
pnpm run dev
|
||||
|
||||
# production mode
|
||||
pnpm run build
|
||||
|
||||
# generate wasm
|
||||
pnpm run wasm
|
||||
```
|
2042
frontend/appflowy_web/appflowy-wasm/Cargo.lock
generated
Normal file
2042
frontend/appflowy_web/appflowy-wasm/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
26
frontend/appflowy_web/appflowy-wasm/Cargo.toml
Normal file
26
frontend/appflowy_web/appflowy-wasm/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "appflowy-wasm"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = { version = "0.2.89" }
|
||||
lazy_static = "1.4.0"
|
||||
lib-dispatch = { workspace = true, features = ["single_thread"] }
|
||||
parking_lot.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-core = { version = "0.1.32" }
|
||||
tracing-wasm = "0.2.1"
|
||||
flowy-notification = { workspace = true, features = ["ts"] }
|
||||
serde.workspace = true
|
||||
|
||||
[workspace.dependencies]
|
||||
lib-dispatch = { path = "../../rust-lib/lib-dispatch" }
|
||||
parking_lot = { version = "0.12.1" }
|
||||
tracing = { version = "0.1.22" }
|
||||
flowy-notification = { path = "../../rust-lib/flowy-notification" }
|
||||
serde = { version = "1.0.194", features = ["derive"] }
|
2
frontend/appflowy_web/appflowy-wasm/rust-toolchain.toml
Normal file
2
frontend/appflowy_web/appflowy-wasm/rust-toolchain.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[toolchain]
|
||||
channel = "1.75"
|
12
frontend/appflowy_web/appflowy-wasm/rustfmt.toml
Normal file
12
frontend/appflowy_web/appflowy-wasm/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"
|
60
frontend/appflowy_web/appflowy-wasm/src/lib.rs
Normal file
60
frontend/appflowy_web/appflowy-wasm/src/lib.rs
Normal file
@ -0,0 +1,60 @@
|
||||
use crate::notification::TSNotificationSender;
|
||||
use flowy_notification::{register_notification_sender, unregister_all_notification_sender};
|
||||
|
||||
pub mod notification;
|
||||
pub mod request;
|
||||
|
||||
use crate::request::{MutexDispatcher, WasmRequest};
|
||||
use lazy_static::lazy_static;
|
||||
use lib_dispatch::prelude::AFPluginDispatcher;
|
||||
use lib_dispatch::runtime::AFPluginRuntime;
|
||||
use std::sync::Arc;
|
||||
use tracing::trace;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
use wasm_bindgen::JsValue;
|
||||
|
||||
lazy_static! {
|
||||
pub(crate) static ref DISPATCHER: MutexDispatcher = MutexDispatcher::new();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn init_sdk(_data: String) -> i64 {
|
||||
let runtime = Arc::new(AFPluginRuntime::new().unwrap());
|
||||
*DISPATCHER.0.lock() = Some(Arc::new(AFPluginDispatcher::new(runtime, vec![])));
|
||||
0
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn init_tracing() {
|
||||
tracing_wasm::set_as_global_default();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn async_event(name: String, payload: Vec<u8>) {
|
||||
trace!("[WASM]: receives event: {}", name);
|
||||
|
||||
let dispatcher = DISPATCHER.0.lock().as_ref().unwrap().clone();
|
||||
AFPluginDispatcher::boxed_async_send_with_callback(
|
||||
dispatcher,
|
||||
WasmRequest::new(name, payload),
|
||||
|_| Box::pin(async {}),
|
||||
);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = console)]
|
||||
pub fn log(s: &str);
|
||||
#[wasm_bindgen(js_namespace = window)]
|
||||
fn onFlowyNotify(event_name: &str, payload: JsValue);
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn register_listener() {
|
||||
unregister_all_notification_sender();
|
||||
register_notification_sender(TSNotificationSender::new());
|
||||
}
|
||||
|
||||
pub fn on_event(event_name: &str, args: JsValue) {
|
||||
onFlowyNotify(event_name, args);
|
||||
}
|
19
frontend/appflowy_web/appflowy-wasm/src/notification.rs
Normal file
19
frontend/appflowy_web/appflowy-wasm/src/notification.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use flowy_notification::entities::SubscribeObject;
|
||||
use flowy_notification::NotificationSender;
|
||||
|
||||
pub const AF_NOTIFICATION: &str = "af-notification";
|
||||
|
||||
pub struct TSNotificationSender {}
|
||||
|
||||
impl TSNotificationSender {
|
||||
pub(crate) fn new() -> Self {
|
||||
TSNotificationSender {}
|
||||
}
|
||||
}
|
||||
|
||||
impl NotificationSender for TSNotificationSender {
|
||||
fn send_subject(&self, _subject: SubscribeObject) -> Result<(), String> {
|
||||
// on_event(AF_NOTIFICATION, serde_wasm_bindgen::to_value(&subject).unwrap_or(JsValue::UNDEFINED));
|
||||
Ok(())
|
||||
}
|
||||
}
|
64
frontend/appflowy_web/appflowy-wasm/src/request.rs
Normal file
64
frontend/appflowy_web/appflowy-wasm/src/request.rs
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
use lib_dispatch::prelude::{AFPluginDispatcher, AFPluginRequest};
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
pub(crate) struct MutexDispatcher(pub Arc<Mutex<Option<Arc<AFPluginDispatcher>>>>);
|
||||
|
||||
impl MutexDispatcher {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self(Arc::new(Mutex::new(None)))
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sync for MutexDispatcher {}
|
||||
unsafe impl Send for MutexDispatcher {}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct WasmRequest {
|
||||
name: String,
|
||||
payload: Vec<u8>,
|
||||
}
|
||||
|
||||
impl WasmRequest {
|
||||
pub fn new(name: String, payload: Vec<u8>) -> Self {
|
||||
Self { name, payload }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WasmRequest> for AFPluginRequest {
|
||||
fn from(request: WasmRequest) -> Self {
|
||||
AFPluginRequest::new(request.name).payload(request.payload)
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl WasmRequest {
|
||||
pub fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
// Setter for the name
|
||||
#[wasm_bindgen(setter)]
|
||||
pub fn set_name(&mut self, name: String) {
|
||||
self.name = name;
|
||||
}
|
||||
|
||||
// Getter for payload that returns a pointer to the data
|
||||
pub fn get_payload_ptr(&self) -> *const u8 {
|
||||
self.payload.as_ptr()
|
||||
}
|
||||
|
||||
// Getter for the length of the payload
|
||||
pub fn get_payload_len(&self) -> usize {
|
||||
self.payload.len()
|
||||
}
|
||||
|
||||
// Setter or method to update payload
|
||||
pub fn set_payload(&mut self, payload: &[u8]) {
|
||||
self.payload = payload.to_vec();
|
||||
}
|
||||
}
|
13
frontend/appflowy_web/index.html
Normal file
13
frontend/appflowy_web/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
34
frontend/appflowy_web/package.json
Normal file
34
frontend/appflowy_web/package.json
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "appflowy_web",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"wasm": "cd appflowy-wasm && wasm-pack build",
|
||||
"dev": "pnpm run wasm && vite",
|
||||
"build": "tsc && vite build",
|
||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"events": "^3.3.0",
|
||||
"google-protobuf": "^3.21.2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/events": "^3.0.3",
|
||||
"@types/node": "^20.10.6",
|
||||
"@types/react": "^18.2.43",
|
||||
"@types/react-dom": "^18.2.17",
|
||||
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
||||
"@typescript-eslint/parser": "^6.14.0",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"eslint": "^8.55.0",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.5",
|
||||
"typescript": "^5.2.2",
|
||||
"vite": "^5.0.8",
|
||||
"vite-plugin-wasm": "^3.3.0"
|
||||
}
|
||||
}
|
1945
frontend/appflowy_web/pnpm-lock.yaml
Normal file
1945
frontend/appflowy_web/pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load Diff
1
frontend/appflowy_web/public/vite.svg
Normal file
1
frontend/appflowy_web/public/vite.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
15
frontend/appflowy_web/src/@types/global.d.ts
vendored
Normal file
15
frontend/appflowy_web/src/@types/global.d.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
export interface NotifyArgs {
|
||||
source: string;
|
||||
ty: number;
|
||||
id: string;
|
||||
payload?: Unit8Array;
|
||||
error?: Unit8Array;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
onFlowyNotify: (eventName: string, args: NotifyArgs) => void;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
42
frontend/appflowy_web/src/App.css
Normal file
42
frontend/appflowy_web/src/App.css
Normal file
@ -0,0 +1,42 @@
|
||||
#root {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.react:hover {
|
||||
filter: drop-shadow(0 0 2em #61dafbaa);
|
||||
}
|
||||
|
||||
@keyframes logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
a:nth-of-type(2) .logo {
|
||||
animation: logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
56
frontend/appflowy_web/src/App.tsx
Normal file
56
frontend/appflowy_web/src/App.tsx
Normal file
@ -0,0 +1,56 @@
|
||||
import reactLogo from "./assets/react.svg";
|
||||
import viteLogo from "/vite.svg";
|
||||
import "./App.css";
|
||||
import {async_event, init_sdk, init_tracing} from "../appflowy-wasm/pkg/appflowy_wasm";
|
||||
import { useEffect } from "react";
|
||||
import { initApp } from "./application/init_app.ts";
|
||||
import { subscribeNotification } from "./application/notification.ts";
|
||||
import { NotifyArgs } from "./@types/global";
|
||||
|
||||
|
||||
async function runWasm() {
|
||||
init_tracing();
|
||||
init_sdk("sdk config"); // Call your exported Wasm function.
|
||||
}
|
||||
runWasm();
|
||||
|
||||
|
||||
function App() {
|
||||
useEffect(() => {
|
||||
initApp();
|
||||
return subscribeNotification((event: NotifyArgs) => {
|
||||
console.log(event);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleClick = async () => {
|
||||
const payload = new TextEncoder().encode("someString");
|
||||
const res = await async_event("add", payload);
|
||||
console.log(res);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<a href="https://vitejs.dev" target="_blank">
|
||||
<img src={viteLogo} className="logo" alt="Vite logo" />
|
||||
</a>
|
||||
<a href="https://react.dev" target="_blank">
|
||||
<img src={reactLogo} className="logo react" alt="React logo" />
|
||||
</a>
|
||||
</div>
|
||||
<h1>Vite + React</h1>
|
||||
<div className="card">
|
||||
<button onClick={handleClick}>Click me!</button>
|
||||
<p>
|
||||
Edit <code>src/App.tsx</code> and save to test HMR
|
||||
</p>
|
||||
</div>
|
||||
<p className="read-the-docs">
|
||||
Click on the Vite and React logos to learn more
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
34
frontend/appflowy_web/src/application/event_bus.ts
Normal file
34
frontend/appflowy_web/src/application/event_bus.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { EventEmitter } from "events";
|
||||
import { NotifyArgs } from "../@types/global";
|
||||
|
||||
const AF_NOTIFICATION = "af-notification";
|
||||
|
||||
let eventEmitter: EventEmitter;
|
||||
export function getEventEmitterInstance() {
|
||||
if (!eventEmitter) {
|
||||
eventEmitter = new EventEmitter();
|
||||
}
|
||||
return eventEmitter;
|
||||
}
|
||||
|
||||
export function initEventBus() {
|
||||
window.onFlowyNotify = (eventName: string, args: NotifyArgs) => {
|
||||
notify(eventName, args);
|
||||
};
|
||||
}
|
||||
|
||||
export function notify(_eventName: string, args: NotifyArgs) {
|
||||
const eventEmitter = getEventEmitterInstance();
|
||||
eventEmitter.emit(AF_NOTIFICATION, args);
|
||||
}
|
||||
|
||||
export function onNotify(callback: (args: NotifyArgs) => void) {
|
||||
const eventEmitter = getEventEmitterInstance();
|
||||
eventEmitter.on(AF_NOTIFICATION, callback);
|
||||
return offNotify;
|
||||
}
|
||||
|
||||
export function offNotify() {
|
||||
const eventEmitter = getEventEmitterInstance();
|
||||
eventEmitter.removeAllListeners(AF_NOTIFICATION);
|
||||
}
|
7
frontend/appflowy_web/src/application/init_app.ts
Normal file
7
frontend/appflowy_web/src/application/init_app.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { initEventBus } from "./event_bus.ts";
|
||||
import { register_listener } from "../../appflowy-wasm/pkg";
|
||||
|
||||
export function initApp() {
|
||||
initEventBus();
|
||||
register_listener();
|
||||
}
|
17
frontend/appflowy_web/src/application/notification.ts
Normal file
17
frontend/appflowy_web/src/application/notification.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { NotifyArgs } from "../@types/global";
|
||||
import { onNotify } from "./event_bus.ts";
|
||||
|
||||
export function subscribeNotification(
|
||||
callback: (args: NotifyArgs) => void,
|
||||
options?: { id?: string }
|
||||
) {
|
||||
return onNotify((payload) => {
|
||||
const { id } = payload;
|
||||
|
||||
if (options?.id !== undefined && id !== options.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(payload);
|
||||
});
|
||||
}
|
1
frontend/appflowy_web/src/assets/react.svg
Normal file
1
frontend/appflowy_web/src/assets/react.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
After Width: | Height: | Size: 4.0 KiB |
68
frontend/appflowy_web/src/index.css
Normal file
68
frontend/appflowy_web/src/index.css
Normal file
@ -0,0 +1,68 @@
|
||||
:root {
|
||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
10
frontend/appflowy_web/src/main.tsx
Normal file
10
frontend/appflowy_web/src/main.tsx
Normal file
@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.tsx'
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
1
frontend/appflowy_web/src/vite-env.d.ts
vendored
Normal file
1
frontend/appflowy_web/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
27
frontend/appflowy_web/tsconfig.json
Normal file
27
frontend/appflowy_web/tsconfig.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
|
||||
"typeRoots": ["./node_modules/@types", "./src/@types"],
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
10
frontend/appflowy_web/tsconfig.node.json
Normal file
10
frontend/appflowy_web/tsconfig.node.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
8
frontend/appflowy_web/vite.config.ts
Normal file
8
frontend/appflowy_web/vite.config.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import wasm from "vite-plugin-wasm";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react(), wasm()],
|
||||
})
|
27
frontend/rust-lib/Cargo.lock
generated
27
frontend/rust-lib/Cargo.lock
generated
@ -1025,7 +1025,7 @@ dependencies = [
|
||||
"cssparser-macros",
|
||||
"dtoa-short",
|
||||
"itoa",
|
||||
"phf 0.8.0",
|
||||
"phf 0.11.2",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
@ -1737,6 +1737,7 @@ dependencies = [
|
||||
"flowy-notification",
|
||||
"flowy-storage",
|
||||
"futures",
|
||||
"getrandom 0.2.10",
|
||||
"indexmap 2.1.0",
|
||||
"lib-dispatch",
|
||||
"lib-infra",
|
||||
@ -3378,7 +3379,7 @@ version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12"
|
||||
dependencies = [
|
||||
"phf_macros",
|
||||
"phf_macros 0.8.0",
|
||||
"phf_shared 0.8.0",
|
||||
"proc-macro-hack",
|
||||
]
|
||||
@ -3398,6 +3399,7 @@ version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
|
||||
dependencies = [
|
||||
"phf_macros 0.11.2",
|
||||
"phf_shared 0.11.2",
|
||||
]
|
||||
|
||||
@ -3465,6 +3467,19 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_macros"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b"
|
||||
dependencies = [
|
||||
"phf_generator 0.11.2",
|
||||
"phf_shared 0.11.2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.47",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.8.0"
|
||||
@ -4495,18 +4510,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.193"
|
||||
version = "1.0.194"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
|
||||
checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.193"
|
||||
version = "1.0.194"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
|
||||
checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -65,7 +65,7 @@ anyhow = "1.0.75"
|
||||
tracing = "0.1.40"
|
||||
bytes = "1.5.0"
|
||||
serde_json = "1.0.108"
|
||||
serde = "1.0.108"
|
||||
serde = "1.0.194"
|
||||
protobuf = { version = "2.28.0" }
|
||||
diesel = { version = "2.1.0", features = ["sqlite", "chrono", "r2d2"] }
|
||||
uuid = { version = "1.5.0", features = ["serde", "v4"] }
|
||||
|
@ -19,8 +19,5 @@ tokio = { workspace = true, features = ["sync"]}
|
||||
lib-infra = { workspace = true }
|
||||
|
||||
[features]
|
||||
default = ["rocksdb_plugin"]
|
||||
supabase_integrate = ["rocksdb_plugin"]
|
||||
appflowy_cloud_integrate = ["rocksdb_plugin"]
|
||||
snapshot_plugin = ["rocksdb_plugin"]
|
||||
rocksdb_plugin = []
|
||||
default = []
|
||||
wasm_build = []
|
@ -245,47 +245,41 @@ impl AppFlowyCollabBuilder {
|
||||
let _enter = span.enter();
|
||||
match provider_type {
|
||||
CollabPluginProviderType::AppFlowyCloud => {
|
||||
#[cfg(feature = "appflowy_cloud_integrate")]
|
||||
{
|
||||
trace!("init appflowy cloud collab plugins");
|
||||
let local_collab = Arc::downgrade(&collab);
|
||||
let plugins = self
|
||||
.plugin_provider
|
||||
.read()
|
||||
.await
|
||||
.get_plugins(CollabPluginProviderContext::AppFlowyCloud {
|
||||
uid,
|
||||
collab_object: collab_object.clone(),
|
||||
local_collab,
|
||||
})
|
||||
.await;
|
||||
trace!("init appflowy cloud collab plugins");
|
||||
let local_collab = Arc::downgrade(&collab);
|
||||
let plugins = self
|
||||
.plugin_provider
|
||||
.read()
|
||||
.await
|
||||
.get_plugins(CollabPluginProviderContext::AppFlowyCloud {
|
||||
uid,
|
||||
collab_object: collab_object.clone(),
|
||||
local_collab,
|
||||
})
|
||||
.await;
|
||||
|
||||
trace!("add appflowy cloud collab plugins: {}", plugins.len());
|
||||
for plugin in plugins {
|
||||
collab.lock().add_plugin(plugin);
|
||||
}
|
||||
trace!("add appflowy cloud collab plugins: {}", plugins.len());
|
||||
for plugin in plugins {
|
||||
collab.lock().add_plugin(plugin);
|
||||
}
|
||||
},
|
||||
CollabPluginProviderType::Supabase => {
|
||||
#[cfg(feature = "supabase_integrate")]
|
||||
{
|
||||
trace!("init supabase collab plugins");
|
||||
let local_collab = Arc::downgrade(&collab);
|
||||
let local_collab_db = collab_db.clone();
|
||||
let plugins = self
|
||||
.plugin_provider
|
||||
.read()
|
||||
.await
|
||||
.get_plugins(CollabPluginProviderContext::Supabase {
|
||||
uid,
|
||||
collab_object: collab_object.clone(),
|
||||
local_collab,
|
||||
local_collab_db,
|
||||
})
|
||||
.await;
|
||||
for plugin in plugins {
|
||||
collab.lock().add_plugin(plugin);
|
||||
}
|
||||
trace!("init supabase collab plugins");
|
||||
let local_collab = Arc::downgrade(&collab);
|
||||
let local_collab_db = collab_db.clone();
|
||||
let plugins = self
|
||||
.plugin_provider
|
||||
.read()
|
||||
.await
|
||||
.get_plugins(CollabPluginProviderContext::Supabase {
|
||||
uid,
|
||||
collab_object: collab_object.clone(),
|
||||
local_collab,
|
||||
local_collab_db,
|
||||
})
|
||||
.await;
|
||||
for plugin in plugins {
|
||||
collab.lock().add_plugin(plugin);
|
||||
}
|
||||
},
|
||||
CollabPluginProviderType::Local => {},
|
||||
|
@ -1,17 +1,6 @@
|
||||
pub use collab::core::collab::MutexCollab;
|
||||
pub use collab::preclude::Snapshot;
|
||||
#[cfg(feature = "supabase_integrate")]
|
||||
#[cfg(any(
|
||||
feature = "appflowy_cloud_integrate",
|
||||
feature = "supabase_integrate",
|
||||
feature = "rocksdb_plugin"
|
||||
))]
|
||||
pub use collab_plugins::local_storage::CollabPersistenceConfig;
|
||||
#[cfg(any(
|
||||
feature = "appflowy_cloud_integrate",
|
||||
feature = "supabase_integrate",
|
||||
feature = "rocksdb_plugin"
|
||||
))]
|
||||
pub use collab_plugins::CollabKVDB;
|
||||
pub mod collab_builder;
|
||||
pub mod config;
|
||||
|
@ -55,4 +55,4 @@ zip = "0.6.6"
|
||||
default = ["supabase_cloud_test"]
|
||||
dart = ["flowy-core/dart"]
|
||||
supabase_cloud_test = []
|
||||
single_thread = ["flowy-core/wasm_build"]
|
||||
single_thread = ["flowy-core/single_thread"]
|
@ -23,7 +23,7 @@ flowy-server = { workspace = true }
|
||||
flowy-server-config = { workspace = true }
|
||||
flowy-config = { workspace = true }
|
||||
flowy-date = { workspace = true }
|
||||
collab-integrate = { workspace = true, features = ["supabase_integrate", "appflowy_cloud_integrate", "snapshot_plugin"] }
|
||||
collab-integrate = { workspace = true }
|
||||
collab-entity = { version = "0.1.0" }
|
||||
collab-plugins = { version = "0.1.0" }
|
||||
collab = { version = "0.1.0" }
|
||||
@ -73,4 +73,4 @@ ts = [
|
||||
]
|
||||
rev-sqlite = ["flowy-user/rev-sqlite"]
|
||||
openssl_vendored = ["flowy-sqlite/openssl_vendored"]
|
||||
wasm_build = ["lib-dispatch/wasm_build"]
|
||||
single_thread = ["collab-integrate/wasm_build"]
|
||||
|
@ -54,13 +54,13 @@ pub struct AppFlowyCore {
|
||||
}
|
||||
|
||||
impl AppFlowyCore {
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub async fn new(config: AppFlowyCoreConfig) -> Self {
|
||||
let runtime = Arc::new(AFPluginRuntime::new().unwrap());
|
||||
Self::init(config, runtime).await
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub fn new(config: AppFlowyCoreConfig) -> Self {
|
||||
let runtime = Arc::new(AFPluginRuntime::new().unwrap());
|
||||
let cloned_runtime = runtime.clone();
|
||||
|
@ -4,15 +4,16 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
collab = { version = "0.1.0" }
|
||||
collab-document = { version = "0.1.0" }
|
||||
collab-entity = { version = "0.1.0" }
|
||||
collab-integrate = { workspace = true, features = ["rocksdb_plugin", "snapshot_plugin"] }
|
||||
collab-integrate = { workspace = true }
|
||||
flowy-document-deps = { workspace = true }
|
||||
flowy-storage = { workspace = true }
|
||||
|
||||
flowy-derive.workspace = true
|
||||
flowy-notification = { workspace = true }
|
||||
flowy-error = { path = "../flowy-error", features = ["impl_from_serde", "impl_from_sqlite", "impl_from_dispatch_error", "impl_from_collab"] }
|
||||
@ -27,7 +28,7 @@ strum_macros = "0.21"
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
tracing.workspace = true
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
tokio = { workspace = true, features = ["rt"] }
|
||||
anyhow.workspace = true
|
||||
indexmap = {version = "2.1.0", features = ["serde"]}
|
||||
uuid.workspace = true
|
||||
@ -36,6 +37,9 @@ tokio-stream = { workspace = true, features = ["sync"] }
|
||||
scraper = "0.18.0"
|
||||
lru.workspace = true
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
getrandom = { version = "0.2", features = ["js"]}
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.4.0"
|
||||
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
|
||||
|
@ -1,7 +1,8 @@
|
||||
use flowy_derive::ProtoBuf;
|
||||
use serde::Serialize;
|
||||
use std::{fmt, fmt::Formatter};
|
||||
|
||||
#[derive(Debug, Clone, ProtoBuf, serde::Serialize)]
|
||||
#[derive(Debug, Clone, ProtoBuf, Serialize)]
|
||||
pub struct SubscribeObject {
|
||||
#[pb(index = 1)]
|
||||
pub source: String,
|
||||
|
@ -4,10 +4,12 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
lib-infra = { workspace = true }
|
||||
tokio = { workspace = true, features = ["sync", "macros", ]}
|
||||
tokio = { workspace = true, features = ["sync", "macros"]}
|
||||
atomic_refcell = "0.1.9"
|
||||
anyhow.workspace = true
|
||||
tracing.workspace = true
|
||||
|
@ -25,12 +25,14 @@ tracing.workspace = true
|
||||
parking_lot = "0.12"
|
||||
bincode = { version = "1.3", optional = true}
|
||||
protobuf = { workspace = true, optional = true }
|
||||
getrandom = { version = "0.2", optional = true }
|
||||
wasm-bindgen = { version = "0.2.89", optional = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
thread-id = "3.3.0"
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
getrandom = { version = "0.2", features = ["js"]}
|
||||
wasm-bindgen = { version = "0.2.89" }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { workspace = true, features = ["rt"] }
|
||||
futures-util = "0.3.26"
|
||||
@ -39,7 +41,7 @@ futures-util = "0.3.26"
|
||||
default = ["use_protobuf"]
|
||||
use_serde = ["bincode", "serde_json", "serde", "serde_repr"]
|
||||
use_protobuf= ["protobuf"]
|
||||
wasm_build = ["getrandom/js", "wasm-bindgen"]
|
||||
single_thread = []
|
||||
|
||||
|
||||
[lib]
|
||||
|
@ -16,51 +16,51 @@ use crate::{
|
||||
service::{AFPluginServiceFactory, Service},
|
||||
};
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub trait AFConcurrent {}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
impl<T> AFConcurrent for T where T: ?Sized {}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub trait AFConcurrent: Send + Sync {}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
impl<T> AFConcurrent for T where T: Send + Sync {}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub type AFBoxFuture<'a, T> = futures_core::future::LocalBoxFuture<'a, T>;
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub type AFBoxFuture<'a, T> = futures_core::future::BoxFuture<'a, T>;
|
||||
|
||||
pub type AFStateMap = std::sync::Arc<AFPluginStateMap>;
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub(crate) fn downcast_owned<T: 'static>(boxed: AFBox) -> Option<T> {
|
||||
boxed.downcast().ok().map(|boxed| *boxed)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub(crate) fn downcast_owned<T: 'static + Send + Sync>(boxed: AFBox) -> Option<T> {
|
||||
boxed.downcast().ok().map(|boxed| *boxed)
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub(crate) type AFBox = Box<dyn Any>;
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub(crate) type AFBox = Box<dyn Any + Send + Sync>;
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub type BoxFutureCallback =
|
||||
Box<dyn FnOnce(AFPluginEventResponse) -> AFBoxFuture<'static, ()> + 'static>;
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub type BoxFutureCallback =
|
||||
Box<dyn FnOnce(AFPluginEventResponse) -> AFBoxFuture<'static, ()> + Send + Sync + 'static>;
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub fn af_spawn<T>(future: T) -> tokio::task::JoinHandle<T::Output>
|
||||
where
|
||||
T: Future + Send + 'static,
|
||||
@ -69,7 +69,7 @@ where
|
||||
tokio::spawn(future)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub fn af_spawn<T>(future: T) -> tokio::task::JoinHandle<T::Output>
|
||||
where
|
||||
T: Future + Send + 'static,
|
||||
@ -202,7 +202,7 @@ impl AFPluginDispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub fn sync_send(
|
||||
dispatch: Arc<AFPluginDispatcher>,
|
||||
request: AFPluginRequest,
|
||||
@ -214,7 +214,7 @@ impl AFPluginDispatcher {
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
#[track_caller]
|
||||
pub fn spawn<F>(&self, future: F) -> tokio::task::JoinHandle<F::Output>
|
||||
where
|
||||
@ -223,7 +223,7 @@ impl AFPluginDispatcher {
|
||||
self.runtime.spawn(future)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
#[track_caller]
|
||||
pub fn spawn<F>(&self, future: F) -> tokio::task::JoinHandle<F::Output>
|
||||
where
|
||||
@ -233,7 +233,7 @@ impl AFPluginDispatcher {
|
||||
self.runtime.spawn(future)
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub async fn run_until<F>(&self, future: F) -> F::Output
|
||||
where
|
||||
F: Future + 'static,
|
||||
@ -242,7 +242,7 @@ impl AFPluginDispatcher {
|
||||
self.runtime.run_until(handle).await.unwrap()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub async fn run_until<'a, F>(&self, future: F) -> F::Output
|
||||
where
|
||||
F: Future + Send + 'a,
|
||||
|
@ -8,7 +8,7 @@ use tokio::task::JoinHandle;
|
||||
|
||||
pub struct AFPluginRuntime {
|
||||
inner: Runtime,
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
local: tokio::task::LocalSet,
|
||||
}
|
||||
|
||||
@ -27,12 +27,12 @@ impl AFPluginRuntime {
|
||||
let inner = default_tokio_runtime()?;
|
||||
Ok(Self {
|
||||
inner,
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
local: tokio::task::LocalSet::new(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
#[track_caller]
|
||||
pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
|
||||
where
|
||||
@ -41,7 +41,7 @@ impl AFPluginRuntime {
|
||||
self.local.spawn_local(future)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
#[track_caller]
|
||||
pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
|
||||
where
|
||||
@ -51,7 +51,7 @@ impl AFPluginRuntime {
|
||||
self.inner.spawn(future)
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub async fn run_until<F>(&self, future: F) -> F::Output
|
||||
where
|
||||
F: Future,
|
||||
@ -59,7 +59,7 @@ impl AFPluginRuntime {
|
||||
self.local.run_until(future).await
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub async fn run_until<F>(&self, future: F) -> F::Output
|
||||
where
|
||||
F: Future,
|
||||
@ -67,7 +67,7 @@ impl AFPluginRuntime {
|
||||
future.await
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
#[track_caller]
|
||||
pub fn block_on<F>(&self, f: F) -> F::Output
|
||||
where
|
||||
@ -76,7 +76,7 @@ impl AFPluginRuntime {
|
||||
self.local.block_on(&self.inner, f)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
#[track_caller]
|
||||
pub fn block_on<F>(&self, f: F) -> F::Output
|
||||
where
|
||||
@ -86,14 +86,14 @@ impl AFPluginRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub fn default_tokio_runtime() -> io::Result<Runtime> {
|
||||
runtime::Builder::new_current_thread()
|
||||
.thread_name("dispatch-rt-st")
|
||||
.build()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub fn default_tokio_runtime() -> io::Result<Runtime> {
|
||||
runtime::Builder::new_multi_thread()
|
||||
.thread_name("dispatch-rt-mt")
|
||||
|
@ -16,7 +16,7 @@ where
|
||||
BoxServiceFactory(Box::new(FactoryWrapper(factory)))
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
type Inner<Cfg, Req, Res, Err> = Box<
|
||||
dyn AFPluginServiceFactory<
|
||||
Req,
|
||||
@ -27,7 +27,7 @@ type Inner<Cfg, Req, Res, Err> = Box<
|
||||
Future = AFBoxFuture<'static, Result<BoxService<Req, Res, Err>, Err>>,
|
||||
>,
|
||||
>;
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
type Inner<Cfg, Req, Res, Err> = Box<
|
||||
dyn AFPluginServiceFactory<
|
||||
Req,
|
||||
@ -58,12 +58,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasm_build")]
|
||||
#[cfg(feature = "single_thread")]
|
||||
pub type BoxService<Req, Res, Err> = Box<
|
||||
dyn Service<Req, Response = Res, Error = Err, Future = AFBoxFuture<'static, Result<Res, Err>>>,
|
||||
>;
|
||||
|
||||
#[cfg(not(feature = "wasm_build"))]
|
||||
#[cfg(not(feature = "single_thread"))]
|
||||
pub type BoxService<Req, Res, Err> = Box<
|
||||
dyn Service<Req, Response = Res, Error = Err, Future = AFBoxFuture<'static, Result<Res, Err>>>
|
||||
+ Sync
|
||||
|
@ -4,6 +4,8 @@ version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
chrono = { workspace = true, default-features = false, features = ["clock"] }
|
||||
@ -15,6 +17,8 @@ async-trait.workspace = true
|
||||
md5 = "0.7.0"
|
||||
anyhow.workspace = true
|
||||
walkdir = "2.4.0"
|
||||
zip = "0.6.6"
|
||||
tempfile = "3.8.1"
|
||||
validator = "0.16.0"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
zip = "0.6.6"
|
||||
|
@ -1,7 +1,9 @@
|
||||
pub use async_trait;
|
||||
|
||||
pub mod box_any;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod file_util;
|
||||
|
||||
pub mod future;
|
||||
pub mod ref_map;
|
||||
pub mod util;
|
||||
|
@ -101,7 +101,7 @@ rustup target add x86_64-unknown-linux-gnu
|
||||
"""
|
||||
|
||||
[tasks.install_tauri_prerequests]
|
||||
dependencies=["install_targets", "install_tauri_protobuf"]
|
||||
dependencies=["install_targets", "install_web_protobuf"]
|
||||
|
||||
[tasks.install_flutter_prerequests]
|
||||
dependencies=["install_targets", "install_flutter_protobuf"]
|
||||
|
@ -1,17 +1,17 @@
|
||||
|
||||
[tasks.install_tauri_protobuf.windows]
|
||||
[tasks.install_web_protobuf.windows]
|
||||
script = """
|
||||
npm install -g protoc-gen-ts typescript@4.9.5
|
||||
"""
|
||||
script_runner = "@shell"
|
||||
|
||||
[tasks.install_tauri_protobuf.mac]
|
||||
[tasks.install_web_protobuf.mac]
|
||||
script = """
|
||||
sudo npm install -g protoc-gen-ts typescript@4.9.5
|
||||
"""
|
||||
script_runner = "@shell"
|
||||
|
||||
[tasks.install_tauri_protobuf.linux]
|
||||
[tasks.install_web_protobuf.linux]
|
||||
script = """
|
||||
sudo npm install -g protoc-gen-ts typescript@4.9.5
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user