Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: build tauri from vscode launch (#1720)

Nathan.foood77c41013f1e
diff --git a/frontend/.vscode/launch.json b/frontend/.vscode/launch.json
index e089da32ae..39c80de2cf 100644
--- a/frontend/.vscode/launch.json
+++ b/frontend/.vscode/launch.json
@@ -94,7 +94,7 @@
{
"type": "lldb",
"request": "launch",
- "name": "AF: Tauri dev",
+ "name": "AF-tauri: Dev",
"cargo": {
"args": [
"build",
@@ -102,7 +102,7 @@
"--no-default-features"
]
},
- "preLaunchTask": "tauri:dev",
+ "preLaunchTask": "AF: Tauri Dev",
"cwd": "${workspaceRoot}/appflowy_tauri/"
},
{
diff --git a/frontend/.vscode/tasks.json b/frontend/.vscode/tasks.json
index 9b3236bcd7..10bc312c23 100644
--- a/frontend/.vscode/tasks.json
+++ b/frontend/.vscode/tasks.json
@@ -14,7 +14,7 @@
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
- "AF: Rust Clean",
+ "AF: Dart Clean",
"AF: Flutter Clean",
"AF: build_flowy_sdk",
"AF: Flutter Pub Get",
@@ -32,7 +32,7 @@
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
- "AF: Rust Clean",
+ "AF: Dart Clean",
"AF: Flutter Clean",
"AF: build_flowy_sdk_for_android",
"AF: Flutter Pub Get",
@@ -166,7 +166,7 @@
}
},
{
- "label": "AF: Rust Clean",
+ "label": "AF: Dart Clean",
"type": "shell",
"command": "cargo make dart_clean",
"group": "build",
@@ -187,7 +187,7 @@
"detail": "app_flowy"
},
{
- "label": "tauri:dev",
+ "label": "AF: Tauri Dev",
"type": "shell",
"isBackground": true,
"command": "npm run dev",
@@ -196,5 +196,13 @@
"cwd": "${workspaceFolder}/appflowy_tauri"
}
},
+ {
+ "label": "AF: Tauri Clean",
+ "type": "shell",
+ "command": "cargo make tauri_clean",
+ "options": {
+ "cwd": "${workspaceFolder}"
+ }
+ },
]
}
\ No newline at end of file
diff --git a/frontend/appflowy_tauri/src-tauri/build.rs b/frontend/appflowy_tauri/src-tauri/build.rs
index d860e1e6a7..4b4e6edf99 100644
--- a/frontend/appflowy_tauri/src-tauri/build.rs
+++ b/frontend/appflowy_tauri/src-tauri/build.rs
@@ -1,3 +1,7 @@
+use std::env;
fn main() {
+ env::set_var("TAURI_PROTOBUF_PATH", "appflowy_tauri/src/protobuf");
+ env::set_var("CARGO_MAKE_WORKING_DIRECTORY", "../../../");
+
tauri_build::build()
}
diff --git a/frontend/rust-lib/dart-ffi/Cargo.toml b/frontend/rust-lib/dart-ffi/Cargo.toml
index a43c7ea5a8..a9f5d73bc1 100644
--- a/frontend/rust-lib/dart-ffi/Cargo.toml
+++ b/frontend/rust-lib/dart-ffi/Cargo.toml
@@ -38,7 +38,4 @@ http_sync = ["flowy-core/http_sync", "flowy-core/use_bunyan"]
openssl_vendored = ["flowy-core/openssl_vendored"]
[build-dependencies]
-flowy-codegen = { path = "../flowy-codegen", features = [
- "dart",
-]}
-
+flowy-codegen = { path = "../flowy-codegen", features = ["dart"] }
diff --git a/frontend/rust-lib/dart-notify/Cargo.toml b/frontend/rust-lib/dart-notify/Cargo.toml
index 7c65ca7065..2ca4bcabe4 100644
--- a/frontend/rust-lib/dart-notify/Cargo.toml
+++ b/frontend/rust-lib/dart-notify/Cargo.toml
@@ -6,17 +6,17 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-lazy_static = {version = "1.4.0"}
-protobuf = {version = "2.20.0"}
-allo-isolate = {version = "^0.1", features = ["catch-unwind",]}
+lazy_static = { version = "1.4.0" }
+protobuf = { version = "2.20.0" }
+allo-isolate = { version = "^0.1", features = ["catch-unwind"] }
log = "0.4.14"
bytes = { version = "1.0" }
-flowy-derive = {path = "../flowy-derive" }
-lib-dispatch = {path = "../lib-dispatch" }
+flowy-derive = { path = "../flowy-derive" }
+lib-dispatch = { path = "../lib-dispatch" }
[build-dependencies]
-flowy-codegen = { path = "../flowy-codegen", features = ["dart"]}
+flowy-codegen = { path = "../flowy-codegen" }
[features]
-dart = []
\ No newline at end of file
+dart = ["flowy-codegen/dart"]
diff --git a/frontend/rust-lib/flowy-codegen/Cargo.toml b/frontend/rust-lib/flowy-codegen/Cargo.toml
index 78c4ce2611..d65ca032cf 100644
--- a/frontend/rust-lib/flowy-codegen/Cargo.toml
+++ b/frontend/rust-lib/flowy-codegen/Cargo.toml
@@ -16,7 +16,7 @@ cmd_lib = { version = "1", optional = true }
protoc-rust = { version = "2", optional = true }
walkdir = { version = "2", optional = true }
similar = { version = "1.2.2", optional = true }
-syn = { version = "1.0.60", features = ["extra-traits", "parsing", "derive", "full"], optional = true }
+syn = { version = "1.0.60", features = ["extra-traits", "parsing", "derive", "full"] }
fancy-regex = { version = "0.10.0", optional = true }
lazy_static = { version = "1.4.0", optional = true }
tera = { version = "1.5.0", optional = true}
@@ -31,7 +31,6 @@ toml = {version = "0.5.8", optional = true}
[features]
proto_gen = [
"similar",
- "syn",
"fancy-regex",
"lazy_static",
"tera",
@@ -45,7 +44,7 @@ proto_gen = [
"walkdir",
"protoc-bin-vendored",
]
-dart_event = ["walkdir", "tera", "syn"]
+dart_event = ["walkdir", "tera", ]
dart = ["proto_gen", "dart_event"]
-ts_event = ["walkdir", "tera", "syn"]
+ts_event = ["walkdir", "tera", ]
ts = ["proto_gen", "ts_event"]
\ No newline at end of file
diff --git a/frontend/rust-lib/flowy-codegen/src/dart_event/ast.rs b/frontend/rust-lib/flowy-codegen/src/ast.rs
similarity index 100%
rename from frontend/rust-lib/flowy-codegen/src/dart_event/ast.rs
rename to frontend/rust-lib/flowy-codegen/src/ast.rs
diff --git a/frontend/rust-lib/flowy-codegen/src/dart_event/dart_event.rs b/frontend/rust-lib/flowy-codegen/src/dart_event/dart_event.rs
index 1dc3a2f13f..3149773246 100644
--- a/frontend/rust-lib/flowy-codegen/src/dart_event/dart_event.rs
+++ b/frontend/rust-lib/flowy-codegen/src/dart_event/dart_event.rs
@@ -1,5 +1,5 @@
use super::event_template::*;
-use crate::dart_event::ast::EventASTContext;
+use crate::ast::EventASTContext;
use crate::flowy_toml::{parse_crate_config_from, CrateConfig};
use crate::util::{is_crate_dir, is_hidden, path_string_with_component, read_file};
use flowy_ast::ASTResult;
diff --git a/frontend/rust-lib/flowy-codegen/src/dart_event/mod.rs b/frontend/rust-lib/flowy-codegen/src/dart_event/mod.rs
index 7cae08ccd3..f885527b47 100644
--- a/frontend/rust-lib/flowy-codegen/src/dart_event/mod.rs
+++ b/frontend/rust-lib/flowy-codegen/src/dart_event/mod.rs
@@ -1,5 +1,5 @@
#![allow(clippy::module_inception)]
-pub(crate) mod ast;
+
mod dart_event;
mod event_template;
diff --git a/frontend/rust-lib/flowy-codegen/src/lib.rs b/frontend/rust-lib/flowy-codegen/src/lib.rs
index 78dee8fcdf..770ed27b21 100644
--- a/frontend/rust-lib/flowy-codegen/src/lib.rs
+++ b/frontend/rust-lib/flowy-codegen/src/lib.rs
@@ -10,6 +10,7 @@ pub mod ts_event;
#[cfg(any(feature = "proto_gen", feature = "dart_event", feature = "ts_event"))]
mod flowy_toml;
+pub(crate) mod ast;
#[cfg(any(feature = "proto_gen", feature = "dart_event", feature = "ts_event"))]
pub mod util;
diff --git a/frontend/rust-lib/flowy-codegen/src/protobuf_file/mod.rs b/frontend/rust-lib/flowy-codegen/src/protobuf_file/mod.rs
index 52bde9fb93..ca3a4f4014 100644
--- a/frontend/rust-lib/flowy-codegen/src/protobuf_file/mod.rs
+++ b/frontend/rust-lib/flowy-codegen/src/protobuf_file/mod.rs
@@ -100,14 +100,13 @@ fn generate_ts_protobuf_files(
file_names: &Vec<String>,
protoc_bin_path: &Path,
) {
- if std::env::var("TAURI_PROTOBUF_PATH").is_err() {
- eprintln!("TAURI_PROTOBUF_PATH was not set, skip generate ts pb");
- return;
- }
+ let root = std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("../../".to_string());
+ let tauri_protobuf_path =
+ std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("appflowy_tauri/src/protobuf".to_string());
let mut output = PathBuf::new();
- output.push(std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap());
- output.push(std::env::var("TAURI_PROTOBUF_PATH").unwrap());
+ output.push(root);
+ output.push(tauri_protobuf_path);
output.push("classes");
output.push(name);
@@ -159,12 +158,12 @@ fn generate_dart_protobuf_files(
protoc_bin_path: &Path,
) {
if std::env::var("CARGO_MAKE_WORKING_DIRECTORY").is_err() {
- log::warn!("CARGO_MAKE_WORKING_DIRECTORY was not set, skip generate dart pb");
+ log::error!("CARGO_MAKE_WORKING_DIRECTORY was not set, skip generate dart pb");
return;
}
if std::env::var("FLUTTER_FLOWY_SDK_PATH").is_err() {
- log::warn!("FLUTTER_FLOWY_SDK_PATH was not set, skip generate dart pb");
+ log::error!("FLUTTER_FLOWY_SDK_PATH was not set, skip generate dart pb");
return;
}
diff --git a/frontend/rust-lib/flowy-codegen/src/ts_event/mod.rs b/frontend/rust-lib/flowy-codegen/src/ts_event/mod.rs
index 2179209287..6d060f4229 100644
--- a/frontend/rust-lib/flowy-codegen/src/ts_event/mod.rs
+++ b/frontend/rust-lib/flowy-codegen/src/ts_event/mod.rs
@@ -1,6 +1,6 @@
mod event_template;
-use crate::dart_event::ast::EventASTContext;
+use crate::ast::EventASTContext;
use crate::flowy_toml::{parse_crate_config_from, CrateConfig};
use crate::ts_event::event_template::{EventRenderContext, EventTemplate};
use crate::util::{is_crate_dir, is_hidden, path_string_with_component, read_file};
@@ -13,10 +13,9 @@ use syn::Item;
use walkdir::WalkDir;
pub fn gen(crate_name: &str) {
- if std::env::var("TAURI_PROTOBUF_PATH").is_err() {
- log::warn!("TAURI_PROTOBUF_PATH was not set, skip generate ts event");
- return;
- }
+ let root = std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("../../".to_string());
+ let tauri_protobuf_path =
+ std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("appflowy_tauri/src/protobuf".to_string());
let crate_path = std::fs::canonicalize(".").unwrap().as_path().display().to_string();
let event_crates = parse_ts_event_files(vec![crate_path]);
@@ -33,15 +32,7 @@ pub fn gen(crate_name: &str) {
}
render_result.push_str(TS_FOOTER);
- let ts_event_folder: PathBuf = [
- &std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap(),
- &std::env::var("TAURI_PROTOBUF_PATH").unwrap(),
- "events",
- crate_name,
- ]
- .iter()
- .collect();
-
+ let ts_event_folder: PathBuf = [&root, &tauri_protobuf_path, "events", crate_name].iter().collect();
if !ts_event_folder.as_path().exists() {
std::fs::create_dir_all(ts_event_folder.as_path()).unwrap();
}
diff --git a/frontend/rust-lib/flowy-sync/src/synchronizer.rs b/frontend/rust-lib/flowy-sync/src/synchronizer.rs
index bba75db264..0b88115050 100644
--- a/frontend/rust-lib/flowy-sync/src/synchronizer.rs
+++ b/frontend/rust-lib/flowy-sync/src/synchronizer.rs
@@ -149,7 +149,7 @@ where
pub async fn pong(&self, user: Arc<dyn RevisionUser>, client_rev_id: i64) -> Result<(), CollaborateError> {
let object_id = self.object_id.clone();
let server_rev_id = self.rev_id();
- tracing::Span::current().record("server_rev_id", &server_rev_id);
+ tracing::Span::current().record("server_rev_id", server_rev_id);
match server_rev_id.cmp(&client_rev_id) {
Ordering::Less => {
tracing::trace!("Client should not send ping and the server should pull the revisions from the client")
@@ -171,7 +171,7 @@ where
#[tracing::instrument(level = "debug", skip(self, revisions), fields(object_id), err)]
pub async fn reset(&self, revisions: Vec<Revision>) -> Result<(), CollaborateError> {
let object_id = self.object_id.clone();
- tracing::Span::current().record("object_id", &object_id.as_str());
+ tracing::Span::current().record("object_id", object_id.as_str());
let (_, rev_id) = pair_rev_id_from_revision_pbs(&revisions);
let operations = make_operations_from_revisions(revisions.clone())?;
self.persistence.reset_object(&object_id, revisions).await?;
diff --git a/frontend/scripts/makefile/tauri.toml b/frontend/scripts/makefile/tauri.toml
index 30a1983d08..3d7058ac3d 100644
--- a/frontend/scripts/makefile/tauri.toml
+++ b/frontend/scripts/makefile/tauri.toml
@@ -1,37 +1,45 @@
+
+
+
+[tasks.tauri_env]
+script_runner = "@rust"
+script = '''
+//! ```cargo
+use std::env;
+fn main() {
+ env.set_var("TAURI_PROTOBUF_PATH", "appflowy_tauri/src/protobuf");
+}
+'''
+
+
[tasks.tauri_build]
-script = [
- """
+script = ["""
cd appflowy_tauri/src-tauri
npm run tauri build
- """,
-]
+ """]
script_runner = "@shell"
[tasks.tauri_pb]
-script = [
- """
+script = ["""
cd appflowy_tauri/src-tauri
cargo build
- """,
-]
+ """]
script_runner = "@shell"
[tasks.tauri_dev]
-script = [
- """
+script = ["""
cd appflowy_tauri
npm run tauri dev
- """,
-]
+ """]
script_runner = "@shell"
[tasks.tauri_clean]
run_task = { name = [
- "rust_lib_clean",
- "rm_macro_build_cache",
- "rm_rust_generated_files",
- "rm_tauri_generated_protobuf_files",
- "rm_tauri_generated_event_files",
+ "rust_lib_clean",
+ "rm_macro_build_cache",
+ "rm_rust_generated_files",
+ "rm_tauri_generated_protobuf_files",
+ "rm_tauri_generated_event_files",
] }
[tasks.rm_tauri_generated_protobuf_files]